From cf309b1f8ff883dbda51b727f4c2c78bbc9d5ac5 Mon Sep 17 00:00:00 2001 From: Manoj Date: Fri, 19 Nov 2021 01:57:36 +0530 Subject: [PATCH] FINERACT-1413 : charge-payment-narration --- .../savings/data/SavingsAccountConstant.java | 2 +- .../savings/domain/SavingsAccount.java | 15 ++++++++------- ...WritePlatformServiceJpaRepositoryImpl.java | 19 +++++++++++++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountConstant.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountConstant.java index 150eabade..e7cbb41ed 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountConstant.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountConstant.java @@ -67,6 +67,6 @@ public class SavingsAccountConstant extends SavingsApiConstants { feeOnMonthDayParamName, monthDayFormatParamName, feeIntervalParamName)); protected static final Set SAVINGS_ACCOUNT_CHARGES_PAY_CHARGE_REQUEST_DATA_PARAMETERS = new HashSet<>( - Arrays.asList(amountParamName, dueAsOfDateParamName, dateFormatParamName, localeParamName)); + Arrays.asList(amountParamName, dueAsOfDateParamName, dateFormatParamName, localeParamName, noteParamName)); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java index bc0301e50..b88295542 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java @@ -2708,8 +2708,8 @@ public class SavingsAccount extends AbstractPersistableCustom { return false; } - public void payCharge(final SavingsAccountCharge savingsAccountCharge, final BigDecimal amountPaid, final LocalDate transactionDate, - final DateTimeFormatter formatter, final AppUser user) { + public SavingsAccountTransaction payCharge(final SavingsAccountCharge savingsAccountCharge, final BigDecimal amountPaid, + final LocalDate transactionDate, final DateTimeFormatter formatter, final AppUser user) { final List dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) @@ -2797,16 +2797,16 @@ public class SavingsAccount extends AbstractPersistableCustom { } } - this.payCharge(savingsAccountCharge, chargePaid, transactionDate, user); + return this.payCharge(savingsAccountCharge, chargePaid, transactionDate, user); } - public void payCharge(final SavingsAccountCharge savingsAccountCharge, final Money amountPaid, final LocalDate transactionDate, - final AppUser user) { + public SavingsAccountTransaction payCharge(final SavingsAccountCharge savingsAccountCharge, final Money amountPaid, + final LocalDate transactionDate, final AppUser user) { savingsAccountCharge.pay(getCurrency(), amountPaid); - handlePayChargeTransactions(savingsAccountCharge, amountPaid, transactionDate, user); + return handlePayChargeTransactions(savingsAccountCharge, amountPaid, transactionDate, user); } - private void handlePayChargeTransactions(SavingsAccountCharge savingsAccountCharge, Money transactionAmount, + private SavingsAccountTransaction handlePayChargeTransactions(SavingsAccountCharge savingsAccountCharge, Money transactionAmount, final LocalDate transactionDate, final AppUser user) { SavingsAccountTransaction chargeTransaction = null; @@ -2819,6 +2819,7 @@ public class SavingsAccount extends AbstractPersistableCustom { } handleChargeTransactions(savingsAccountCharge, chargeTransaction); + return chargeTransaction; } private void handleWaiverChargeTransactions(SavingsAccountCharge savingsAccountCharge, Money transactionAmount, AppUser user) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java index e03b897f0..e43786496 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java @@ -1232,7 +1232,14 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi } } - this.payCharge(savingsAccountCharge, transactionDate, amountPaid, fmt, user); + SavingsAccountTransaction chargeTransaction = this.payCharge(savingsAccountCharge, transactionDate, amountPaid, fmt, user); + + final String noteText = command.stringValueOfParameterNamed("note"); + if (StringUtils.isNotBlank(noteText)) { + final Note note = Note.savingsTransactionNote(savingsAccountCharge.savingsAccount(), chargeTransaction, noteText); + this.noteRepository.save(note); + } + return new CommandProcessingResultBuilder() // .withEntityId(savingsAccountCharge.getId()) // .withOfficeId(savingsAccountCharge.savingsAccount().officeId()) // @@ -1261,8 +1268,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi } @Transactional - private void payCharge(final SavingsAccountCharge savingsAccountCharge, final LocalDate transactionDate, final BigDecimal amountPaid, - final DateTimeFormatter formatter, final AppUser user) { + private SavingsAccountTransaction payCharge(final SavingsAccountCharge savingsAccountCharge, final LocalDate transactionDate, + final BigDecimal amountPaid, final DateTimeFormatter formatter, final AppUser user) { final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); @@ -1274,7 +1281,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi final Set existingTransactionIds = new HashSet<>(); final Set existingReversedTransactionIds = new HashSet<>(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); - account.payCharge(savingsAccountCharge, amountPaid, transactionDate, formatter, user); + SavingsAccountTransaction chargeTransaction = account.payCharge(savingsAccountCharge, amountPaid, transactionDate, formatter, user); boolean isInterestTransfer = false; LocalDate postInterestOnDate = null; final MathContext mc = MathContext.DECIMAL64; @@ -1296,9 +1303,13 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi account.validateAccountBalanceDoesNotBecomeNegative("." + SavingsAccountTransactionType.PAY_CHARGE.getCode(), depositAccountOnHoldTransactions); + saveTransactionToGenerateTransactionId(chargeTransaction); + this.savingAccountRepositoryWrapper.saveAndFlush(account); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); + + return chargeTransaction; } private void updateExistingTransactionsDetails(SavingsAccount account, Set existingTransactionIds,