Add tax relevant flag to transaction and recc. transaction
This commit is contained in:
@@ -53,7 +53,7 @@ public class RecurringTransactionController {
|
||||
public ResponseEntity createRecurringTransaction(String fromAccountKey, String toAccountKey, Long amount,
|
||||
String description, String holidayWeekendType,
|
||||
String intervalType, String firstOccurrence,
|
||||
String lastOccurrence, Boolean remind
|
||||
String lastOccurrence, Boolean remind, Boolean taxRelevant
|
||||
) {
|
||||
final String decodedFrom = ControllerUtil.urlDecode(fromAccountKey);
|
||||
final String decodedTo = ControllerUtil.urlDecode(toAccountKey);
|
||||
@@ -62,13 +62,13 @@ public class RecurringTransactionController {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(String
|
||||
.format("/recurringTransactions/createRecurringTransaction got parameters: %s, %s, %s, %s, %s, " +
|
||||
"%s, %s, %s, %s", decodedFrom, decodedTo, amount, decodedDesc, holidayWeekendType,
|
||||
intervalType, firstOccurrence, lastOccurrence, remind));
|
||||
"%s, %s, %s, %s, %s", decodedFrom, decodedTo, amount, decodedDesc, holidayWeekendType,
|
||||
intervalType, firstOccurrence, lastOccurrence, remind, taxRelevant));
|
||||
}
|
||||
|
||||
final ResponseReason responseReason = this.recurringTransactionService
|
||||
.createRecurringTransaction(decodedFrom, decodedTo, amount, decodedDesc, holidayWeekendType,
|
||||
intervalType, firstOccurrence, lastOccurrence, remind);
|
||||
intervalType, firstOccurrence, lastOccurrence, remind, taxRelevant);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(String
|
||||
|
||||
@@ -39,7 +39,7 @@ public class TransactionController {
|
||||
|
||||
@RequestMapping(value = "createTransaction")
|
||||
public ResponseEntity createTransaction(String fromAccountKey, String toAccountKey, Long amount, String date,
|
||||
String description
|
||||
String description, Boolean taxRelevant
|
||||
) {
|
||||
final String decodedFrom = ControllerUtil.urlDecode(fromAccountKey);
|
||||
final String decodedTo = ControllerUtil.urlDecode(toAccountKey);
|
||||
@@ -47,12 +47,12 @@ public class TransactionController {
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(String
|
||||
.format("/transactions/createTransaction got parameters: %s, %s, %s, %s, %s",
|
||||
decodedFrom, decodedTo, amount, date, decodedDesc));
|
||||
.format("/transactions/createTransaction got parameters: %s, %s, %s, %s, %s, %s",
|
||||
decodedFrom, decodedTo, amount, date, decodedDesc, taxRelevant));
|
||||
}
|
||||
|
||||
final ResponseReason responseReason = this.transactionService
|
||||
.createTransaction(decodedFrom, decodedTo, amount, date, decodedDesc);
|
||||
.createTransaction(decodedFrom, decodedTo, amount, date, decodedDesc, taxRelevant);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(String.format("/transactions/createTransaction returns with %s", responseReason.name()));
|
||||
|
||||
@@ -318,7 +318,7 @@ public class RecurringTransactionService {
|
||||
public ResponseReason createRecurringTransaction(String fromAccountKey, String toAccountKey, Long amount,
|
||||
String description, String holidayWeekendType,
|
||||
String intervalType, String firstOccurrence,
|
||||
String lastOccurrence, Boolean remind
|
||||
String lastOccurrence, Boolean remind, Boolean taxRelevant
|
||||
) {
|
||||
final Account fromAccount = this.accountService.getAccountByKey(fromAccountKey);
|
||||
final Account toAccount = this.accountService.getAccountByKey(toAccountKey);
|
||||
@@ -332,7 +332,7 @@ public class RecurringTransactionService {
|
||||
|
||||
try {
|
||||
final RecurringTransaction transaction = buildRecurringTransaction(fromAccount, toAccount, amount,
|
||||
description, holidayWeekendType, intervalType, firstOccurrence, lastOccurrence, remind);
|
||||
description, holidayWeekendType, intervalType, firstOccurrence, lastOccurrence, remind, taxRelevant);
|
||||
|
||||
this.recurringTransactionRepository.save(transaction);
|
||||
|
||||
@@ -357,13 +357,15 @@ public class RecurringTransactionService {
|
||||
* @param firstOccurrence the first occurrence
|
||||
* @param lastOccurrence the last occurrence, may be <code>null</code>
|
||||
* @param remind the remind flag
|
||||
* @param taxRelevant whether the recurring transaction, respectively its transaction instances, are relevant for
|
||||
* tax declaration
|
||||
*
|
||||
* @return the build {@link RecurringTransaction} instance
|
||||
*/
|
||||
private RecurringTransaction buildRecurringTransaction(Account fromAccount, Account toAccount, Long amount,
|
||||
String description, String holidayWeekendType,
|
||||
String intervalType, String firstOccurrence,
|
||||
String lastOccurrence, Boolean remind
|
||||
String lastOccurrence, Boolean remind, Boolean taxRelevant
|
||||
) {
|
||||
final RecurringTransaction recurringTransaction = new RecurringTransaction();
|
||||
|
||||
@@ -378,6 +380,7 @@ public class RecurringTransactionService {
|
||||
// See 'resources/database/postgres/readme_V1_0_0__init.txt'
|
||||
recurringTransaction.setDeleted(false);
|
||||
recurringTransaction.setRemind(BooleanUtils.toBooleanDefaultIfNull(remind, true));
|
||||
recurringTransaction.setTaxRelevant(taxRelevant);
|
||||
|
||||
// lastOccurrence is optional
|
||||
if (StringUtils.isNotEmpty(lastOccurrence)) {
|
||||
@@ -472,7 +475,8 @@ public class RecurringTransactionService {
|
||||
amount.orElseGet(recurringTransaction::getAmount),
|
||||
LocalDate.now().format(DateTimeFormatter.ofPattern(this.financerConfig.getDateFormat())),
|
||||
recurringTransaction.getDescription(),
|
||||
recurringTransaction);
|
||||
recurringTransaction,
|
||||
recurringTransaction.isTaxRelevant());
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
|
||||
@@ -69,14 +69,15 @@ public class TransactionService {
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public ResponseReason createTransaction(String fromAccountKey, String toAccountKey, Long amount, String date,
|
||||
String description
|
||||
String description, Boolean taxRelevant
|
||||
) {
|
||||
return this.createTransaction(fromAccountKey, toAccountKey, amount, date, description, null);
|
||||
return this.createTransaction(fromAccountKey, toAccountKey, amount, date, description, null, taxRelevant);
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public ResponseReason createTransaction(String fromAccountKey, String toAccountKey, Long amount, String date,
|
||||
String description, RecurringTransaction recurringTransaction
|
||||
String description, RecurringTransaction recurringTransaction,
|
||||
Boolean taxRelevant
|
||||
) {
|
||||
final Account fromAccount = this.accountService.getAccountByKey(fromAccountKey);
|
||||
final Account toAccount = this.accountService.getAccountByKey(toAccountKey);
|
||||
@@ -88,7 +89,8 @@ public class TransactionService {
|
||||
}
|
||||
|
||||
try {
|
||||
final Transaction transaction = buildTransaction(fromAccount, toAccount, amount, description, date, recurringTransaction);
|
||||
final Transaction transaction =
|
||||
buildTransaction(fromAccount, toAccount, amount, description, date, recurringTransaction, taxRelevant);
|
||||
|
||||
transaction.setPeriods(getRelevantPeriods(transaction));
|
||||
|
||||
@@ -143,11 +145,12 @@ public class TransactionService {
|
||||
* @param date the date of the transaction
|
||||
* @param recurringTransaction the recurring transaction that caused the creation of this transaction, may be
|
||||
* <code>null</code>
|
||||
* @param taxRelevant whether the transaction is relevant for tax declaration
|
||||
*
|
||||
* @return the build {@link Transaction} instance
|
||||
*/
|
||||
private Transaction buildTransaction(Account fromAccount, Account toAccount, Long amount, String description,
|
||||
String date, RecurringTransaction recurringTransaction
|
||||
String date, RecurringTransaction recurringTransaction, Boolean taxRelevant
|
||||
) {
|
||||
final Transaction transaction = new Transaction();
|
||||
|
||||
@@ -157,6 +160,7 @@ public class TransactionService {
|
||||
transaction.setDescription(description);
|
||||
transaction.setDate(LocalDate.parse(date, DateTimeFormatter.ofPattern(this.financerConfig.getDateFormat())));
|
||||
transaction.setRecurringTransaction(recurringTransaction);
|
||||
transaction.setTaxRelevant(taxRelevant);
|
||||
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
-- Add a new column to the transaction table that denotes whether this transaction is
|
||||
-- relevant for tax declaration
|
||||
ALTER TABLE "transaction"
|
||||
ADD COLUMN tax_relevant BOOLEAN DEFAULT FALSE NOT NULL;
|
||||
|
||||
ALTER TABLE recurring_transaction
|
||||
ADD COLUMN tax_relevant BOOLEAN DEFAULT FALSE NOT NULL;
|
||||
@@ -0,0 +1,7 @@
|
||||
-- Add a new column to the transaction table that denotes whether this transaction is
|
||||
-- relevant for tax declaration
|
||||
ALTER TABLE "transaction"
|
||||
ADD COLUMN tax_relevant BOOLEAN DEFAULT 'FALSE' NOT NULL;
|
||||
|
||||
ALTER TABLE recurring_transaction
|
||||
ADD COLUMN tax_relevant BOOLEAN DEFAULT 'FALSE' NOT NULL;
|
||||
@@ -52,7 +52,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
"INTERVAL_TYPE",
|
||||
"FIRST_OCCURRENCE",
|
||||
"LAST_OCCURRENCE",
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.FROM_AND_TO_ACCOUNT_NOT_FOUND, response);
|
||||
@@ -72,7 +73,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
"INTERVAL_TYPE",
|
||||
"FIRST_OCCURRENCE",
|
||||
"LAST_OCCURRENCE",
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.TO_ACCOUNT_NOT_FOUND, response);
|
||||
@@ -92,7 +94,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
"INTERVAL_TYPE",
|
||||
"FIRST_OCCURRENCE",
|
||||
"LAST_OCCURRENCE",
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.FROM_ACCOUNT_NOT_FOUND, response);
|
||||
@@ -113,7 +116,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
"INTERVAL_TYPE",
|
||||
"FIRST_OCCURRENCE",
|
||||
"LAST_OCCURRENCE",
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.INVALID_BOOKING_ACCOUNTS, response);
|
||||
@@ -134,7 +138,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
"INTERVAL_TYPE",
|
||||
"FIRST_OCCURRENCE",
|
||||
"LAST_OCCURRENCE",
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.MISSING_AMOUNT, response);
|
||||
@@ -155,7 +160,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
"INTERVAL_TYPE",
|
||||
"FIRST_OCCURRENCE",
|
||||
"LAST_OCCURRENCE",
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.AMOUNT_ZERO, response);
|
||||
@@ -176,7 +182,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
"INTERVAL_TYPE",
|
||||
"FIRST_OCCURRENCE",
|
||||
"LAST_OCCURRENCE",
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.MISSING_HOLIDAY_WEEKEND_TYPE, response);
|
||||
@@ -197,7 +204,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
"INTERVAL_TYPE",
|
||||
"FIRST_OCCURRENCE",
|
||||
"LAST_OCCURRENCE",
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.INVALID_HOLIDAY_WEEKEND_TYPE, response);
|
||||
@@ -218,7 +226,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
null,
|
||||
"FIRST_OCCURRENCE",
|
||||
"LAST_OCCURRENCE",
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.MISSING_INTERVAL_TYPE, response);
|
||||
@@ -239,7 +248,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
"INTERVAL_TYPE",
|
||||
"FIRST_OCCURRENCE",
|
||||
"LAST_OCCURRENCE",
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.INVALID_INTERVAL_TYPE, response);
|
||||
@@ -260,7 +270,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
IntervalType.DAILY.name(),
|
||||
null,
|
||||
"LAST_OCCURRENCE",
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.MISSING_FIRST_OCCURRENCE, response);
|
||||
@@ -281,7 +292,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
IntervalType.DAILY.name(),
|
||||
"FIRST_OCCURRENCE",
|
||||
"LAST_OCCURRENCE",
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.INVALID_FIRST_OCCURRENCE_FORMAT, response);
|
||||
@@ -302,7 +314,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
IntervalType.DAILY.name(),
|
||||
"07.03.2019",
|
||||
"LAST_OCCURRENCE",
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.INVALID_LAST_OCCURRENCE_FORMAT, response);
|
||||
@@ -324,7 +337,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
IntervalType.DAILY.name(),
|
||||
"07.03.2019",
|
||||
null,
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.UNKNOWN_ERROR, response);
|
||||
@@ -345,7 +359,8 @@ public class RecurringTransactionService_createRecurringTransactionTest {
|
||||
IntervalType.DAILY.name(),
|
||||
"07.03.2019",
|
||||
null,
|
||||
Boolean.TRUE);
|
||||
Boolean.TRUE,
|
||||
Boolean.FALSE);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.OK, response);
|
||||
|
||||
@@ -48,7 +48,7 @@ public class TransactionService_createTransactionTest {
|
||||
// will not be found.
|
||||
|
||||
// Act
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.invalid", "account.invalid", Long.valueOf(150l), "24.02.2019", "XXX");
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.invalid", "account.invalid", Long.valueOf(150l), "24.02.2019", "XXX", false);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.FROM_AND_TO_ACCOUNT_NOT_FOUND, response);
|
||||
@@ -60,7 +60,7 @@ public class TransactionService_createTransactionTest {
|
||||
Mockito.when(this.accountService.getAccountByKey(Mockito.anyString())).thenReturn(createAccount(), null);
|
||||
|
||||
// Act
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.invalid", Long.valueOf(150l), "24.02.2019", "XXX");
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.invalid", Long.valueOf(150l), "24.02.2019", "XXX", false);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.TO_ACCOUNT_NOT_FOUND, response);
|
||||
@@ -72,7 +72,7 @@ public class TransactionService_createTransactionTest {
|
||||
Mockito.when(this.accountService.getAccountByKey(Mockito.anyString())).thenReturn(null, createAccount());
|
||||
|
||||
// Act
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.invalid", "account.to", Long.valueOf(150l), "24.02.2019", "XXX");
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.invalid", "account.to", Long.valueOf(150l), "24.02.2019", "XXX", false);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.FROM_ACCOUNT_NOT_FOUND, response);
|
||||
@@ -85,7 +85,7 @@ public class TransactionService_createTransactionTest {
|
||||
Mockito.when(this.ruleService.isValidBooking(Mockito.any(Account.class), Mockito.any(Account.class))).thenReturn(Boolean.FALSE);
|
||||
|
||||
// Act
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.to", Long.valueOf(150l), "24.02.2019", "XXX");
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.to", Long.valueOf(150l), "24.02.2019", "XXX", false);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.INVALID_BOOKING_ACCOUNTS, response);
|
||||
@@ -98,7 +98,7 @@ public class TransactionService_createTransactionTest {
|
||||
Mockito.when(this.ruleService.isValidBooking(Mockito.any(Account.class), Mockito.any(Account.class))).thenReturn(Boolean.TRUE);
|
||||
|
||||
// Act
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.to", null, "24.02.2019", "XXX");
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.to", null, "24.02.2019", "XXX", false);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.MISSING_AMOUNT, response);
|
||||
@@ -111,7 +111,7 @@ public class TransactionService_createTransactionTest {
|
||||
Mockito.when(this.ruleService.isValidBooking(Mockito.any(Account.class), Mockito.any(Account.class))).thenReturn(Boolean.TRUE);
|
||||
|
||||
// Act
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.to", Long.valueOf(0l), "24.02.2019", "XXX");
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.to", Long.valueOf(0l), "24.02.2019", "XXX", false);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.AMOUNT_ZERO, response);
|
||||
@@ -124,7 +124,7 @@ public class TransactionService_createTransactionTest {
|
||||
Mockito.when(this.ruleService.isValidBooking(Mockito.any(Account.class), Mockito.any(Account.class))).thenReturn(Boolean.TRUE);
|
||||
|
||||
// Act
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.to", Long.valueOf(125l), null, "XXX");
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.to", Long.valueOf(125l), null, "XXX", false);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.MISSING_DATE, response);
|
||||
@@ -137,7 +137,7 @@ public class TransactionService_createTransactionTest {
|
||||
Mockito.when(this.ruleService.isValidBooking(Mockito.any(Account.class), Mockito.any(Account.class))).thenReturn(Boolean.TRUE);
|
||||
|
||||
// Act
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.to", Long.valueOf(125l), "2019-01-01", "XXX");
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.to", Long.valueOf(125l), "2019-01-01", "XXX", false);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.INVALID_DATE_FORMAT, response);
|
||||
@@ -156,7 +156,7 @@ public class TransactionService_createTransactionTest {
|
||||
Mockito.when(toAccount.getCurrentBalance()).thenReturn(Long.valueOf(0l));
|
||||
|
||||
// Act
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.to", Long.valueOf(125l), "24.02.2019", "XXX");
|
||||
final ResponseReason response = this.classUnderTest.createTransaction("account.from", "account.to", Long.valueOf(125l), "24.02.2019", "XXX", false);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(ResponseReason.OK, response);
|
||||
|
||||
Reference in New Issue
Block a user