diff --git a/src/main/java/fr/unistra/sil/erp/back/WebMvcConfig.java b/src/main/java/fr/unistra/sil/erp/back/WebMvcConfig.java index 60a8b36726385e7b3e1c4dcba7ba98c053062f84..69bedfbca9ad81ff9ef69fe4d16443d191b61968 100644 --- a/src/main/java/fr/unistra/sil/erp/back/WebMvcConfig.java +++ b/src/main/java/fr/unistra/sil/erp/back/WebMvcConfig.java @@ -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 */ diff --git a/src/main/java/fr/unistra/sil/erp/back/controller/web/WebRegistryController.java b/src/main/java/fr/unistra/sil/erp/back/controller/web/WebRegistryController.java index 7bed52b3441e6af21a28ace605579b9a1e368ad0..e0a82ad151934ea04d79b06cae16e74405040157 100644 --- a/src/main/java/fr/unistra/sil/erp/back/controller/web/WebRegistryController.java +++ b/src/main/java/fr/unistra/sil/erp/back/controller/web/WebRegistryController.java @@ -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); } diff --git a/src/main/java/fr/unistra/sil/erp/back/model/RegistryEntry.java b/src/main/java/fr/unistra/sil/erp/back/model/RegistryEntry.java index 17d6f5137a699664f573029c6f92a0ffc78658ea..c3b521df9ee7b892888d3375b3a8382596fe1b07 100644 --- a/src/main/java/fr/unistra/sil/erp/back/model/RegistryEntry.java +++ b/src/main/java/fr/unistra/sil/erp/back/model/RegistryEntry.java @@ -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. diff --git a/src/main/java/fr/unistra/sil/erp/back/repository/registry/SqliteRegistryRepository.java b/src/main/java/fr/unistra/sil/erp/back/repository/registry/SqliteRegistryRepository.java index 74f36fbf2436865d293b7d244c0bcb82fae547f9..eff4ebc9f8f9270a4b3bbadd2e673bdabe114d4e 100644 --- a/src/main/java/fr/unistra/sil/erp/back/repository/registry/SqliteRegistryRepository.java +++ b/src/main/java/fr/unistra/sil/erp/back/repository/registry/SqliteRegistryRepository.java @@ -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); diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 25749d62d89f261343db35be2c9adc9830ebc304..84289dcfa3fdb5df1f6f94571199af8781ad5ee2 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -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 diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 25749d62d89f261343db35be2c9adc9830ebc304..84289dcfa3fdb5df1f6f94571199af8781ad5ee2 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -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 diff --git a/src/main/resources/messages_fr.properties b/src/main/resources/messages_fr.properties index d62bf94bcf875540c2d79172aab349de6896c365..a32b34d74075179febb4e5c49edfdb34e78d8667 100644 --- a/src/main/resources/messages_fr.properties +++ b/src/main/resources/messages_fr.properties @@ -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 diff --git a/src/main/resources/templates/registry.html b/src/main/resources/templates/registry.html index 7b929370b66af7213286315e17d00b909ae0dfcd..b251900cb1dc16cb42af35bcb65ea3258c9537c0 100644 --- a/src/main/resources/templates/registry.html +++ b/src/main/resources/templates/registry.html @@ -1,24 +1,30 @@ <!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> diff --git a/src/main/resources/templates/stocks.html b/src/main/resources/templates/stocks.html deleted file mode 100644 index cf26c473c3649e97d555a10979dc92ccf2a40793..0000000000000000000000000000000000000000 --- a/src/main/resources/templates/stocks.html +++ /dev/null @@ -1,30 +0,0 @@ -<!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