diff --git a/src/main/java/de/deadlocker8/budgetmaster/templates/Template.java b/src/main/java/de/deadlocker8/budgetmaster/templates/Template.java index 52de03249ad0a656442fc19ef665cc1d58e81790..74e4478ce90d273e33bdcf2fcac22be7ce298743 100644 --- a/src/main/java/de/deadlocker8/budgetmaster/templates/Template.java +++ b/src/main/java/de/deadlocker8/budgetmaster/templates/Template.java @@ -184,6 +184,16 @@ public class Template implements TransactionBase return transferAccount != null; } + public boolean isPayment() + { + if(this.amount == null) + { + return true; + } + + return this.amount <= 0; + } + @Override public String toString() { diff --git a/src/main/java/de/deadlocker8/budgetmaster/templates/TemplateController.java b/src/main/java/de/deadlocker8/budgetmaster/templates/TemplateController.java index f42e236ba5ed54217ac32dbdfdc8c4b49ed69340..e4749937537862d81f7c26432595c8307b769df9 100644 --- a/src/main/java/de/deadlocker8/budgetmaster/templates/TemplateController.java +++ b/src/main/java/de/deadlocker8/budgetmaster/templates/TemplateController.java @@ -76,7 +76,10 @@ public class TemplateController extends BaseController @RequestParam(value = "includeCategory") Boolean includeCategory, @RequestParam(value = "includeAccount") Boolean includeAccount) { - transactionService.handleAmount(transaction, isPayment); + if(transaction.getAmount() != null) + { + transactionService.handleAmount(transaction, isPayment); + } transactionService.handleTags(transaction); if(templateName == null || templateName.isEmpty()) @@ -172,7 +175,10 @@ public class TemplateController extends BaseController TemplateValidator templateValidator = new TemplateValidator(previousTemplateName, templateService.getExistingTemplateNames()); templateValidator.validate(template, bindingResult); - transactionService.handleAmount(template, isPayment); + if(template.getAmount() != null) + { + transactionService.handleAmount(template, isPayment); + } transactionService.handleTags(template); if(bindingResult.hasErrors()) @@ -207,7 +213,7 @@ public class TemplateController extends BaseController Template template = templateOptional.get(); templateService.prepareTemplateForNewTransaction(template, false); - templateService.prepareModelNewOrEdit(model, true, template, template.getAmount() <= 0, accountService.getAllAccountsAsc()); + templateService.prepareModelNewOrEdit(model, true, template, template.isPayment(), accountService.getAllAccountsAsc()); return "templates/newTemplate"; } diff --git a/src/main/resources/static/js/transactions.js b/src/main/resources/static/js/transactions.js index 04e6ee14b3a50168271d4d2ba3e2a15970f207a8..b24b599c20a16b89f9de20dc26e7da5ec3fad9ef 100644 --- a/src/main/resources/static/js/transactions.js +++ b/src/main/resources/static/js/transactions.js @@ -249,7 +249,7 @@ function validateAmount(text, allowEmpty=false) if(allowEmpty && text.length === 0) { removeTooltip(id); - document.getElementById("hidden-" + id).value = 0; + document.getElementById("hidden-" + id).value = ""; return true; }