diff --git a/src/main/java/de/deadlocker8/budgetmaster/transactions/TransactionController.java b/src/main/java/de/deadlocker8/budgetmaster/transactions/TransactionController.java index 5789be4d4cce90fb2d6ab2ef23f0086c90e65050..7b49534fa84098ddee87dc0b2259cab344c2074e 100644 --- a/src/main/java/de/deadlocker8/budgetmaster/transactions/TransactionController.java +++ b/src/main/java/de/deadlocker8/budgetmaster/transactions/TransactionController.java @@ -131,15 +131,15 @@ public class TransactionController extends BaseController return "transactions/newTransaction" + StringUtils.capitalize(type); } - @PostMapping(value = "/newTransaction/normal") - public String postRepeating(Model model, @CookieValue("currentDate") String cookieDate, - @ModelAttribute("NewTransaction") Transaction transaction, BindingResult bindingResult, - @RequestParam(value = "isRepeating", required = false) boolean isRepeating, - @RequestParam(value = "previousType", required = false) TransactionType previousType, - @RequestParam(value = "repeatingModifierNumber", required = false, defaultValue = "0") int repeatingModifierNumber, - @RequestParam(value = "repeatingModifierType", required = false) String repeatingModifierType, - @RequestParam(value = "repeatingEndType", required = false) String repeatingEndType, - @RequestParam(value = "repeatingEndValue", required = false) String repeatingEndValue) + @PostMapping(value = "/newTransaction") + public String post(Model model, @CookieValue("currentDate") String cookieDate, + @ModelAttribute("NewTransaction") Transaction transaction, BindingResult bindingResult, + @RequestParam(value = "isRepeating", required = false) boolean isRepeating, + @RequestParam(value = "previousType", required = false) TransactionType previousType, + @RequestParam(value = "repeatingModifierNumber", required = false, defaultValue = "0") int repeatingModifierNumber, + @RequestParam(value = "repeatingModifierType", required = false) String repeatingModifierType, + @RequestParam(value = "repeatingEndType", required = false) String repeatingEndType, + @RequestParam(value = "repeatingEndValue", required = false) String repeatingEndValue) { DateTime date = dateService.getDateTimeFromCookie(cookieDate); @@ -161,7 +161,17 @@ public class TransactionController extends BaseController transaction.setRepeatingOption(null); } - return handleRedirect(model, transaction.getID() != null, transaction, bindingResult, date, "transactions/newTransaction"); + String redirectUrl; + if(transaction.isTransfer()) + { + redirectUrl = "transactions/newTransactionTransfer"; + } + else + { + redirectUrl = "transactions/newTransactionNormal"; + } + + return handleRedirect(model, transaction.getID() != null, transaction, bindingResult, date, redirectUrl); } private void handlePreviousType(Transaction transaction, boolean isRepeating) @@ -197,28 +207,6 @@ public class TransactionController extends BaseController return new RepeatingOption(startDate, repeatingModifier, repeatingEnd); } - @PostMapping(value = "/newTransaction/transfer") - public String postTransfer(Model model, - @CookieValue("currentDate") String cookieDate, - @ModelAttribute("NewTransaction") Transaction transaction, BindingResult bindingResult, - @RequestParam(value = "previousType", required = false) TransactionType previousType) - { - DateTime date = dateService.getDateTimeFromCookie(cookieDate); - -// TODO -// handlePreviousType(transaction, isRepeating); - - TransactionValidator transactionValidator = new TransactionValidator(); - transactionValidator.validate(transaction, bindingResult); - - transactionService.handleAmount(transaction); - transactionService.handleTags(transaction); - - transaction.setRepeatingOption(null); - - return handleRedirect(model, transaction.getID() != null, transaction, bindingResult, date, "transactions/newTransactionTransfer"); - } - private String handleRedirect(Model model, boolean isEdit, @ModelAttribute("NewTransaction") Transaction transaction, BindingResult bindingResult, DateTime date, String url) { if(bindingResult.hasErrors()) diff --git a/src/main/resources/templates/transactions/newTransactionNormal.ftl b/src/main/resources/templates/transactions/newTransactionNormal.ftl index 87de8e513195babeb62f5b6791fbd6f061bf1dcb..9bbab097ba059d3cbf56aa8887378c1461157ce9 100644 --- a/src/main/resources/templates/transactions/newTransactionNormal.ftl +++ b/src/main/resources/templates/transactions/newTransactionNormal.ftl @@ -33,7 +33,7 @@ <@header.content> <div class="container"> <#import "../helpers/validation.ftl" as validation> - <form name="NewTransaction" action="<@s.url '/transactions/newTransaction/normal'/>" method="post" onsubmit="return validateForm()"> + <form name="NewTransaction" action="<@s.url '/transactions/newTransaction'/>" method="post" onsubmit="return validateForm()"> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> <!-- only set ID for transactions not templates, otherwise the input is filled with the template ID and saving the transaction may then override an existing transactions if the ID is also already used in transactions table --> @@ -77,7 +77,7 @@ <@newTransactionMacros.transactionRepeating transaction currentDate/> <#-- buttons --> - <@newTransactionMacros.buttons "/transactions"/> + <@newTransactionMacros.buttons '/transactions'/> <@newTransactionMacros.buttonTransactionActions isEdit true previousType??/> </form> diff --git a/src/main/resources/templates/transactions/newTransactionTransfer.ftl b/src/main/resources/templates/transactions/newTransactionTransfer.ftl index b44cc7a1c55218ad941a9d6c29b439b2d1061f79..36ca67f351de3bafc88bc52d7ce8ae049fad2dad 100644 --- a/src/main/resources/templates/transactions/newTransactionTransfer.ftl +++ b/src/main/resources/templates/transactions/newTransactionTransfer.ftl @@ -33,13 +33,14 @@ <@header.content> <div class="container"> <#import "../helpers/validation.ftl" as validation> - <form name="NewTransaction" action="<@s.url '/transactions/newTransaction/transfer'/>" method="post" onsubmit="return validateForm()"> + <form name="NewTransaction" action="<@s.url '/transactions/newTransaction'/>" method="post" onsubmit="return validateForm()"> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> <!-- only set ID for transactions not templates, otherwise the input is filled with the template ID and saving the transaction may then override an existing transactions if the ID is also already used in transactions table --> <input type="hidden" name="ID" value="<#if transaction.class.simpleName == "Transaction" && transaction.getID()??>${transaction.getID()?c}</#if>"> <input type="hidden" name="isExpenditure" value="true"> <input type="hidden" name="previousType" value="<#if previousType??>${previousType.name()}</#if>"> + <input type="hidden" name="isRepeating" value="${transaction.isRepeating()?c}"> <#assign hint=helpers.getHintByLocalizationKey("hint.transaction.save")/> <@header.hint hint=hint/> @@ -78,6 +79,9 @@ </#if> <@customSelectMacros.customAccountSelect "transfer-account-select-wrapper" "transferAccount" accounts selectedTransferAccount "col s12 m12 l8 offset-l2" locale.getString("transaction.new.label.transfer.account") "transaction-destination-account"/> + <#-- repeating options --> + <@newTransactionMacros.transactionRepeating transaction currentDate/> + <#-- buttons --> <@newTransactionMacros.buttons '/transactions'/> <@newTransactionMacros.buttonTransactionActions isEdit true previousType??/>