Skip to content
Snippets Groups Projects
Commit 7be958ef authored by GAYDAMAKHA MIKHAIL's avatar GAYDAMAKHA MIKHAIL
Browse files

Merge branch 'feature/post_registry' into 'develop'

Feature/post registry

See merge request !40
parents 5472fbd4 797c9ad4
Branches
2 merge requests!41Develop,!40Feature/post registry
......@@ -5,17 +5,27 @@
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.model.RegistryInfo;
import fr.unistra.sil.erp.back.repository.DatabaseConnectionException;
import fr.unistra.sil.erp.back.model.RegistryEntry;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import fr.unistra.sil.erp.back.repository.IRegistryRepository;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
/**
* Web controller for the registry display page.
......@@ -28,8 +38,7 @@ public class WebRegistryController {
private final IRegistryRepository repository;
/**
*
* @param repository
* @param repository registry repository
*/
public WebRegistryController(IRegistryRepository repository) {
this.repository = repository;
......@@ -45,10 +54,28 @@ public class WebRegistryController {
public String registry(Model model) {
try {
List<RegistryEntry> lr = repository.getRegistry();
model.addAttribute("RegistryInfo", new RegistryInfo(
0, "0", 0, new BigDecimal(0), new BigDecimal(0), ""
));
model.addAttribute("registry", lr);
} catch (DatabaseConnectionException ex) {
Logger.getLogger(WebRegistryController.class.getName()).log(Level.SEVERE, null, ex);
}
return "registry";
}
@PostMapping(WEB_MAPPING_REGISTRY)
public String createUser(@ModelAttribute RegistryInfo registryInfo, Model model) throws ParseException {
RegistryEntry entry = new RegistryEntry(
0,
registryInfo.getTransactionType(),
(new SimpleDateFormat("yyyy-MM-dd HH:mm")).parse(registryInfo.getDate()),
registryInfo.getAccountId(),
registryInfo.getDebit(),
registryInfo.getCredit(),
registryInfo.getRemarks()
);
repository.store(entry);
return registry(model);
}
}
package fr.unistra.sil.erp.back.model;
import java.math.BigDecimal;
import java.util.Date;
public class RegistryInfo {
/**
* The transaction's type.
*/
private final int transactionType;
/**
* The date and time for this transaction.
*/
private final String date;
/**
* The ID of the associated account.
*/
private final int accountId;
/**
* The amount of money, if it's a debit.
*/
private final BigDecimal debit;
/**
* The amount of money, if it's a credit.
*/
private final BigDecimal credit;
/**
* Arbitrary remarks. Optional.
*/
private final String remarks;
public RegistryInfo(
int transactionType,
String date,
int accountId,
BigDecimal debit,
BigDecimal credit,
String remarks
) {
this.transactionType = transactionType;
this.date = date;
this.accountId = accountId;
this.debit = debit;
this.credit = credit;
this.remarks = remarks;
}
public int getTransactionType() {
return transactionType;
}
public String getDate() {
return date;
}
public int getAccountId() {
return accountId;
}
public BigDecimal getDebit() {
return debit;
}
public BigDecimal getCredit() {
return credit;
}
public String getRemarks() {
return remarks;
}
}
......@@ -62,3 +62,7 @@
text-align: left;
}
}
table, td, th {
border: 1px solid black;
}
......@@ -26,6 +26,18 @@
<td th:text="${entry.credit}"></td>
<td th:text="${entry.remarks}"></td>
</tr>
<tr>
<form th:action="@{/registry}" th:object="${RegistryInfo}" method="post">
<td><input type="datetime-local" th:field="*{date}" /></td>
<td><input type="number" th:field="*{transactionType}" /></td>
<td><input type="number" th:field="*{accountId}" /></td>
<td><input type="number" th:field="*{debit}" /></td>
<td><input type="number" th:field="*{credit}" /></td>
<td><input type="text" th:field="*{remarks}" /></td>
<td><input type="submit" /></td>
</form>
</tr>
</table>
</div>
</article>
......
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