Skip to content
Snippets Groups Projects
Commit f0025c9e authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#577 - added route to fill transaction form from existing one

parent 2e50c0d9
Branches
Tags v1.1.0
No related merge requests found
...@@ -333,4 +333,39 @@ public class TransactionController extends BaseController ...@@ -333,4 +333,39 @@ public class TransactionController extends BaseController
return redirectUrl; return redirectUrl;
} }
@GetMapping("/{ID}/newFromExisting")
public String newFromExisting(Model model, @PathVariable("ID") Integer ID, @CookieValue("currentDate") String cookieDate)
{
Optional<Transaction> transactionOptional = transactionService.getRepository().findById(ID);
if(transactionOptional.isEmpty())
{
throw new ResourceNotFoundException();
}
Transaction existingTransaction = transactionOptional.get();
// select first transaction in order to provide correct start date for repeating transactions
if(existingTransaction.getRepeatingOption() != null)
{
existingTransaction = existingTransaction.getRepeatingOption().getReferringTransactions().get(0);
}
final Transaction newTransaction = new Transaction(existingTransaction);
newTransaction.setID(null);
if(newTransaction.getAccount().getAccountState() != AccountState.FULL_ACCESS)
{
newTransaction.setAccount(helpers.getCurrentAccountOrDefault());
}
DateTime date = dateService.getDateTimeFromCookie(cookieDate);
transactionService.prepareModelNewOrEdit(model, false, date, false, newTransaction, accountService.getAllActivatedAccountsAsc());
if(newTransaction.isTransfer())
{
return "transactions/newTransactionTransfer";
}
return "transactions/newTransactionNormal";
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment