Skip to content

Commit

Permalink
Rename Salesexport to SalesExport
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepdeJong committed Dec 12, 2023
1 parent e5c6087 commit 2c0978e
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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.core.admin.SalesExportSubmission;
import ch.wisv.events.utils.LdapGroup;


Expand Down Expand Up @@ -36,23 +36,23 @@


/**
* DashboardSalesexportController class.
* DashboardSalesExportController class.
*/
@Controller
@RequestMapping("/administrator/salesexport")
@PreAuthorize("hasRole('ADMIN')")
public class DashboardSalesexportController extends DashboardController {
public class DashboardSalesExportController extends DashboardController {

/** TreasurerRepository */
private final OrderRepository orderRepository;

/**
* DashboardSalesexportController constructor.
* DashboardSalesExportController constructor.
*
* @param orderRepository of type OrderRepository
*/
@Autowired
public DashboardSalesexportController(OrderRepository orderRepository) {
public DashboardSalesExportController(OrderRepository orderRepository) {
this.orderRepository = orderRepository;
}

Expand All @@ -66,7 +66,7 @@ public DashboardSalesexportController(OrderRepository orderRepository) {
@GetMapping
public String index(Model model) {
// model.addAttribute("productMap", this.generateProductMap());
model.addAttribute("SalesexportSubmission", new SalesexportSubmission());
model.addAttribute("SalesExportSubmission", new SalesExportSubmission());

return "admin/salesexport/index";
}
Expand All @@ -78,14 +78,14 @@ public String index(Model model) {
*
*/
@GetMapping(value="/csv", produces="text/csv")
public HttpEntity<? extends Object> csvExport(@ModelAttribute SalesexportSubmission SalesexportSubmission, Model model) {
model.addAttribute("SalesexportSubmission", SalesexportSubmission);
public HttpEntity<? extends Object> csvExport(@ModelAttribute SalesExportSubmission SalesExportSubmission, Model model) {
model.addAttribute("SalesExportSubmission", SalesExportSubmission);

// Convert payment methods to integers
List<Integer> paymentMethods = new ArrayList<>();
SalesexportSubmission.getIncludedPaymentMethods().forEach( (m) -> paymentMethods.add(m.toInt()) );
SalesExportSubmission.getIncludedPaymentMethods().forEach( (m) -> paymentMethods.add(m.toInt()) );

List<TreasurerData> treasurerData = orderRepository.findallPaymentsByMonth(SalesexportSubmission.getMonth(), SalesexportSubmission.getYear(), paymentMethods, SalesexportSubmission.isFreeProductsIncluded());
List<TreasurerData> treasurerData = orderRepository.findallPaymentsByMonth(SalesExportSubmission.getMonth(), SalesExportSubmission.getYear(), paymentMethods, SalesExportSubmission.isFreeProductsIncluded());

ListIterator<TreasurerData> listIterator = treasurerData.listIterator(treasurerData.size());

Expand Down Expand Up @@ -124,7 +124,7 @@ public HttpEntity<? extends Object> csvExport(@ModelAttribute SalesexportSubmiss
}
}

// String csvContent = "Options:\n" + SalesexportSubmission.toString() + "\n\n";
// 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<Integer, Septet<String, Integer, String, Double, Integer, String, Double>> entry : map.entrySet()) {
Expand All @@ -140,7 +140,7 @@ public HttpEntity<? extends Object> csvExport(@ModelAttribute SalesexportSubmiss
InputStream bufferedInputStream = new ByteArrayInputStream(csvContent.getBytes(StandardCharsets.UTF_8));
InputStreamResource fileInputStream = new InputStreamResource(bufferedInputStream);

String filename = "Sales_overview_"+SalesexportSubmission.getYear()+"-"+SalesexportSubmission.getMonth()+"_export.csv";
String filename = "Sales_overview_"+SalesExportSubmission.getYear()+"-"+SalesExportSubmission.getMonth()+"_export.csv";

// setting HTTP headers
HttpHeaders headers = new HttpHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
@Getter
@Setter
public class SalesexportSubmission {
public class SalesExportSubmission {

/**
* Year of query
Expand All @@ -38,7 +38,7 @@ public class SalesexportSubmission {
/**
* Default constructor.
*/
public SalesexportSubmission() {
public SalesExportSubmission() {

// default: previous month
if (LocalDate.now().getMonthValue() == 1) {
Expand Down Expand Up @@ -67,4 +67,3 @@ public String toString() {
return settings;
}
}

252 changes: 165 additions & 87 deletions src/main/resources/templates/admin/salesexport/index.html
Original file line number Diff line number Diff line change
@@ -1,110 +1,188 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<meta name="description" content="" />
<meta name="author" content="" />
<!-- Icons -->
<link rel="apple-touch-icon" sizes="180x180" th:href="@{/icons/apple-touch-icon.png}">
<link rel="icon" type="image/png" sizes="32x32" th:href="@{/icons/favicon-32x32.png}">
<link rel="icon" type="image/png" sizes="16x16" th:href="@{/icons/favicon-16x16.png}">
<link rel="manifest" th:href="@{/icons/site.webmanifest}">
<link rel="mask-icon" th:href="@{/icons/safari-pinned-tab.svg}" color="#1e274a">
<link rel="shortcut icon" th:href="@{/icons/favicon.ico}">
<meta name="msapplication-TileColor" content="#2b5797">
<meta name="msapplication-config" th:content="@{/icons/browserconfig.xml}">
<meta name="theme-color" content="#ffffff">
<link
rel="apple-touch-icon"
sizes="180x180"
th:href="@{/icons/apple-touch-icon.png}"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
th:href="@{/icons/favicon-32x32.png}"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
th:href="@{/icons/favicon-16x16.png}"
/>
<link rel="manifest" th:href="@{/icons/site.webmanifest}" />
<link
rel="mask-icon"
th:href="@{/icons/safari-pinned-tab.svg}"
color="#1e274a"
/>
<link rel="shortcut icon" th:href="@{/icons/favicon.ico}" />
<meta name="msapplication-TileColor" content="#2b5797" />
<meta
name="msapplication-config"
th:content="@{/icons/browserconfig.xml}"
/>
<meta name="theme-color" content="#ffffff" />

<title>CH Events - Dashboard > Example</title>

<!--Bootstrap core CSS -->
<link th:href="@{/webjars/wisvch-bootstrap-theme/dist/css/bootstrap.min.css}" rel="stylesheet">
<link rel="stylesheet" href="https://use.typekit.net/uet5duo.css" integrity="sha384-Bg9blBrAm2v7bP2AhXtjHdM8p8EeT4YJLHwfJ/1O257DAiLyqhVtYdCB3dzdZsmb" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">
<link th:href="@{/css/dashboard.css}" rel="stylesheet">
<link th:href="@{/css/wisvch-dashboard.css}" rel="stylesheet">
<link
th:href="@{/webjars/wisvch-bootstrap-theme/dist/css/bootstrap.min.css}"
rel="stylesheet"
/>
<link
rel="stylesheet"
href="https://use.typekit.net/uet5duo.css"
integrity="sha384-Bg9blBrAm2v7bP2AhXtjHdM8p8EeT4YJLHwfJ/1O257DAiLyqhVtYdCB3dzdZsmb"
crossorigin="anonymous"
/>
<link
href="https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap"
rel="stylesheet"
/>
<link th:href="@{/css/dashboard.css}" rel="stylesheet" />
<link th:href="@{/css/wisvch-dashboard.css}" rel="stylesheet" />

<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap4.min.css" integrity="sha384-bsGkvB1NLsaPUZL6GG0N5H9GOW9DK6KiHrrDvO57EJXoD9H3gzlohtuPENw9/24L" crossorigin="anonymous">
<link rel="stylesheet" th:href="@{/webjars/font-awesome/5.0.13/web-fonts-with-css/css/fontawesome-all.min.css}">
</head>
<link
rel="stylesheet"
href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap4.min.css"
integrity="sha384-bsGkvB1NLsaPUZL6GG0N5H9GOW9DK6KiHrrDvO57EJXoD9H3gzlohtuPENw9/24L"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
th:href="@{/webjars/font-awesome/5.0.13/web-fonts-with-css/css/fontawesome-all.min.css}"
/>
</head>

<body>
<nav th:replace="fragments/header :: header"></nav>
<body>
<nav th:replace="fragments/header :: header"></nav>

<div class="container-fluid">
<div class="row">
<div class="container-fluid">
<div class="row">
<nav th:replace="admin/sidebar :: sidebar"></nav>

<main class="col-sm-9 ml-sm-auto col-md-10 p-5" role="main">
<h1>Export Sales
<a class="badge badge-danger" th:href="@{/administrator/treasurer}">
Old Treasurer Tab
</a>
</h1>
<div th:replace="fragments/messages :: messages"></div>
<form th:action="@{./csv}" th:object="${SalesexportSubmission}" method="GET">
<h1>
Export Sales
<a class="badge badge-danger" th:href="@{/administrator/treasurer}">
Old Treasurer Tab
</a>
</h1>
<div th:replace="fragments/messages :: messages"></div>
<form
th:action="@{./csv}"
th:object="${SalesExportSubmission}"
method="GET"
>
<div class="col">
<div class="row">
<div class="col">
<div class="row">
<div class="col">
<div class="card mb-4">
<h6 class="card-header">Month</h6>
<div class="card-body">
<div class="row form">
<div class="form-group col-12">
<div class="row">
<div class="form-group col-6">
<label>Year: <input type="number" class="form-control" th:field="*{year}" /></label>
</div>
<div class="form-group col-6">
<label>Month: <input type="number" class="form-control" th:field="*{month}" /></label>
</div>
</div>
</div>
</div>
</div>
<div class="card mb-4">
<h6 class="card-header">Month</h6>
<div class="card-body">
<div class="row form">
<div class="form-group col-12">
<div class="row">
<div class="form-group col-6">
<label
>Year:
<input
type="number"
class="form-control"
th:field="*{year}"
/></label>
</div>
</div>
<div class="col">
<div class="card mb-4">
<h6 class="card-header">Advanced Settings</h6>
<div class="card-body">
<div class="col form">
<h7>Include payment methods:</h7>
<div class="custom-control custom-checkbox" th:each="payMethod : ${T(ch.wisv.events.core.model.order.PaymentMethod).values()}">
<input type="checkbox" class="custom-control-input"
th:id="'includeCheck' + ${payMethod}"
th:field="*{includedPaymentMethods}"
th:value="${payMethod}"
th:checked="${SalesexportSubmission.getIncludedPaymentMethods().contains(payMethod)}">
<label class="custom-control-label text-dark font-weight-normal" th:for="'includeCheck' + ${payMethod}">[[${payMethod.getName()}]]</label>
</div>
<h7>Include free products:</h7>
<!-- <label>Include free products <input type="checkbox" class="custom-control-input" th:field="*{freeProductsIncluded}" /></label> -->
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input"
id="includeFreeProducts"
th:field="*{freeProductsIncluded}"
th:checked="${SalesexportSubmission.isFreeProductsIncluded()}"
/>
<label class="custom-control-label text-dark font-weight-normal"
for="includeFreeProducts">Include free products (also select all payment methods)</label>
</div>
</div>
</div>
<div class="form-group col-6">
<label
>Month:
<input
type="number"
class="form-control"
th:field="*{month}"
/></label>
</div>
</div>
</div>
</div>
</div>
<div class="card mb-4">
<div class="card-body">
<input type="submit" class="btn btn-secondary" value="Export" />
</div>
</div>
<div class="col">
<div class="card mb-4">
<h6 class="card-header">Advanced Settings</h6>
<div class="card-body">
<div class="col form">
<h7>Include payment methods:</h7>
<div
class="custom-control custom-checkbox"
th:each="payMethod : ${T(ch.wisv.events.core.model.order.PaymentMethod).values()}"
>
<input
type="checkbox"
class="custom-control-input"
th:id="'includeCheck' + ${payMethod}"
th:field="*{includedPaymentMethods}"
th:value="${payMethod}"
th:checked="${SalesExportSubmission.getIncludedPaymentMethods().contains(payMethod)}"
/>
<label
class="custom-control-label text-dark font-weight-normal"
th:for="'includeCheck' + ${payMethod}"
>[[${payMethod.getName()}]]</label
>
</div>
<h7>Include free products:</h7>
<!-- <label>Include free products <input type="checkbox" class="custom-control-input" th:field="*{freeProductsIncluded}" /></label> -->
<div class="custom-control custom-checkbox">
<input
type="checkbox"
class="custom-control-input"
id="includeFreeProducts"
th:field="*{freeProductsIncluded}"
th:checked="${SalesExportSubmission.isFreeProductsIncluded()}"
/>
<label
class="custom-control-label text-dark font-weight-normal"
for="includeFreeProducts"
>Include free products (also select all payment
methods)</label
>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card mb-4">
<div class="card-body">
<input
type="submit"
class="btn btn-secondary"
value="Export"
/>
</div>
</form>
</div>
</div>
</form>
</main>
</div>
</div>
</div>
</body>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = EventsApplicationTest.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class DashboardSalesexportControllerTest extends ControllerTest {
public class DashboardSalesExportControllerTest extends ControllerTest {

@Test
public void testCsvExport() throws Exception {
Expand Down

0 comments on commit 2c0978e

Please sign in to comment.