Skip to content
Snippets Groups Projects
Commit 45301624 authored by BEAUVAIS ANTOINE's avatar BEAUVAIS ANTOINE
Browse files

Added interface for Registry.

parent b1042778
Branches
1 merge request!33Sample Registry interface + fixed header for "CORS".
......@@ -81,6 +81,11 @@ public class WebMvcConfig implements WebMvcConfigurer {
*/
public static final String WEB_MAPPING_ITEMS = "/products";
/**
* Web mapping for the registry.
*/
public static final String WEB_MAPPING_REGISTRY = "/registry";
/**
* @param env
*/
......
......@@ -4,6 +4,7 @@
*/
package fr.unistra.sil.erp.back.controller.web;
import static fr.unistra.sil.erp.back.WebMvcConfig.WEB_MAPPING_REGISTRY;
import fr.unistra.sil.erp.back.repository.DatabaseConnectionException;
import fr.unistra.sil.erp.back.model.RegistryEntry;
......@@ -40,11 +41,11 @@ public class WebRegistryController {
* @param model the model to populate the template with.
* @return the view.
*/
@GetMapping("registry")
public String stocks(Model model) {
@GetMapping(WEB_MAPPING_REGISTRY)
public String regisry(Model model) {
try {
List<RegistryEntry> lr = repository.getRegistry();
model.addAttribute("stocks", lr);
model.addAttribute("registry", lr);
} catch (DatabaseConnectionException ex) {
Logger.getLogger(WebRegistryController.class.getName()).log(Level.SEVERE, null, ex);
}
......
......@@ -26,16 +26,33 @@ public class RegistryEntry {
* The transaction's type.
*/
private final int transactionType;
/**
* Transaction type name.
*/
private final String typeName;
/**
* The date and time for this transaction.
*/
private final Date dt;
/**
* String version of the date.
*
* For some reason Thymeleaf cannot parse the Date object.
*/
private final String dateString;
/**
* The ID of the associated account.
*/
private final int accountId;
/**
* Account string name.
*/
private final String account;
/**
* The amount of money, if it's a debit.
......@@ -68,8 +85,27 @@ public class RegistryEntry {
{
this.id = id;
this.transactionType = transactionType;
this.typeName = null;
this.dt = dt;
this.dateString = this.dt.toString();
this.accountId = accountId;
this.account = null;
this.debit = debit;
this.credit = credit;
this.remarks = remarks;
}
public RegistryEntry(Integer id, int transactionType, String tName, Date dt,
int accountId, String account, BigDecimal debit, BigDecimal credit,
String remarks)
{
this.id = id;
this.transactionType = transactionType;
this.typeName = tName;
this.dt = dt;
this.dateString = this.dt.toString();
this.accountId = accountId;
this.account = account;
this.debit = debit;
this.credit = credit;
this.remarks = remarks;
......@@ -92,6 +128,15 @@ public class RegistryEntry {
{
return this.transactionType;
}
/**
* Returns the transaction type's name.
* @return the name.
*/
public String getTypeName()
{
return this.typeName;
}
/**
* Returns the transaction's date and time.
......@@ -101,6 +146,11 @@ public class RegistryEntry {
{
return this.dt;
}
public String getDateString()
{
return this.dateString;
}
/**
* Returns the associated account's ID.
......@@ -110,6 +160,11 @@ public class RegistryEntry {
{
return this.accountId;
}
public String getAccount()
{
return this.account;
}
/**
* Returns the debit amount.
......
......@@ -25,9 +25,13 @@ public class SqliteRegistryRepository extends SqliteRepository implements IRegis
* Query used to retrieve the registry.
*/
private static final String SQL_GETREGISTRY =
"SELECT r.id AS id, r.dt AS date, r.type AS type, " +
"r.account_id AS account, r.debit AS debit, r.credit AS credit, " +
"r.remarks AS remarks FROM Registry r";
"SELECT r.id AS id, r.dt AS date, r.type AS typeId, " +
"t.name AS type, " +
"r.account_id AS accountId, a.name AS account, " +
"r.debit AS debit, r.credit AS credit, " +
"r.remarks AS remarks FROM Registry r " +
"LEFT JOIN accounts a ON r.account_id = a.id " +
"LEFT JOIN transaction_types t ON r.type = t.id";
/**
* Class constructor.
......@@ -47,8 +51,9 @@ public class SqliteRegistryRepository extends SqliteRepository implements IRegis
try {
while (rs.next()) {
RegistryEntry r = new RegistryEntry(rs.getInt("id"),
rs.getInt("type"), new Date(rs.getInt("date") * 1000L),
rs.getInt("account"),
rs.getInt("typeID"), rs.getString("type"),
new Date(rs.getInt("date") * 1000L),
rs.getInt("accountId"), rs.getString("account"),
rs.getBigDecimal("debit"), rs.getBigDecimal("credit"),
rs.getString("remarks"));
res.add(r);
......
......@@ -25,14 +25,14 @@ web.ui.stock=Stock
#Stocks
web.ui.stocks=Stocks
#Type transaction (achat, vente...)
web.ui.stock.type=Type
web.ui.registry.type=Type
#Date label.
web.ui.stock.date=Date
web.ui.registry.date=Date
#Financial Account
web.ui.stock.account=Account
web.ui.registry.account=Account
#Debit amount label.
web.ui.stock.debit=Debit
web.ui.registry.debit=Debit
#Credit amount label.
web.ui.stock.credit=Credit
web.ui.registry.credit=Credit
#Arbitrary remarks for stock
web.ui.stock.remarks=Remarks
web.ui.registry.remarks=Remarks
......@@ -25,14 +25,14 @@ web.ui.stock=Stock
#Stocks
web.ui.stocks=Stocks
#Type transaction (achat, vente...)
web.ui.stock.type=Type
web.ui.registry.type=Type
#Date label.
web.ui.stock.date=Date
web.ui.registry.date=Date
#Financial Account
web.ui.stock.account=Account
web.ui.registry.account=Account
#Debit amount label.
web.ui.stock.debit=Debit
web.ui.registry.debit=Debit
#Credit amount label.
web.ui.stock.credit=Credit
web.ui.registry.credit=Credit
#Arbitrary remarks for stock
web.ui.stock.remarks=Remarks
web.ui.registry.remarks=Remarks
......@@ -25,14 +25,14 @@ web.ui.stock=Stock
#Stocks
web.ui.stocks=Stocks
#Type transaction (achat, vente...)
web.ui.stock.type=Type
web.ui.registry.type=Type
#Date label.
web.ui.stock.date=Date
web.ui.registry.date=Date
#Financial Account
web.ui.stock.account=Compte
web.ui.registry.account=Compte
#Debit amount label.
web.ui.stock.debit=D\u00e9bit
web.ui.registry.debit=D\u00e9bit
#Credit amount label.
web.ui.stock.credit=Cr\u00e9dit
web.ui.registry.credit=Cr\u00e9dit
#Arbitrary remarks for stock
web.ui.stock.remarks=Commentaires
web.ui.registry.remarks=Commentaires
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="fragments/head :: sharedHead (pageName=#{web.ui.products})">
<head th:replace="fragments/head :: sharedHead (pageName=#{web.ui.registry})">
</head>
<body>
<div th:replace="fragments/navbar :: topNavBar"></div>
<article>
<h1 th:text="#{web.ui.products}"></h1>
<h1 th:text="#{web.ui.registry}"></h1>
<div class="mainFrame" id="productsArea">
<table class="mainList" id="productsList">
<table class="mainList" id="stocksList">
<tr>
<th th:text="#{web.ui.product}"></th>
<th th:text="#{web.ui.price}"></th>
<th th:text="#{web.ui.subscriberPrice}"></th>
<th th:text="#{web.ui.registry.date}"></th>
<th th:text="#{web.ui.registry.type}"></th>
<th th:text="#{web.ui.registry.account}"></th>
<th th:text="#{web.ui.registry.debit}"></th>
<th th:text="#{web.ui.registry.credit}"></th>
<th th:text="#{web.ui.registry.remarks}"></th>
</tr>
<tr th:each="item: ${items}">
<td th:text="${item.name}"></td>
<td th:text="${item.price}"></td>
<td th:text="${item.subscriberPrice}"></td>
<tr th:each="entry: ${registry}">
<td th:text="${entry.dateString}"></td>
<td th:text="${entry.typeName}"></td>
<td th:text="${entry.account}"></td>
<td th:text="${entry.debit}"></td>
<td th:text="${entry.credit}"></td>
<td th:text="${entry.remarks}"></td>
</tr>
</table>
</div>
......
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="fragments/head :: sharedHead (pageName=#{web.ui.products})">
</head>
<body>
<div th:replace="fragments/navbar :: topNavBar"></div>
<article>
<h1 th:text="#{web.ui.products}"></h1>
<div class="mainFrame" id="productsArea">
<table class="mainList" id="stocksList">
<tr>
<th th:text="#{web.ui.stock.date}"></th>
<th th:text="#{web.ui.stock.type}"></th>
<th th:text="#{web.ui.stock.account}"></th>
<th th:text="#{web.ui.stock.debit}"></th>
<th th:text="#{web.ui.stock.credit}"></th>
<th th:text="#{web.ui.stock.remarks}"></th>
</tr>
<tr th:each="stock: ${stocks}">
<td th:text="${stock.date}"></td>
<td th:text="${stock.type}"></td>
<td th:text="${stock.account}"></td>
</tr>
</table>
</div>
</article>
</body>
</html>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment