overdue charge lock issue fix
This commit is contained in:
+8
-8
@@ -3652,10 +3652,10 @@ public class ClientLoanIntegrationTest {
|
|||||||
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
|
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
|
||||||
expectedvalues = new ArrayList<>();
|
expectedvalues = new ArrayList<>();
|
||||||
todaysDate = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
todaysDate = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
||||||
addRepaymentValues(expectedvalues, todaysDate, -2, "2482.76", "46.15", "0.0", "0.0");
|
addRepaymentValues(expectedvalues, todaysDate, -2, "2482.76", "46.15", "0.0", "252.89");
|
||||||
addRepaymentValues(expectedvalues, todaysDate, 1, "2494.22", "34.69", "0.0", "252.89");
|
addRepaymentValues(expectedvalues, todaysDate, 1, "2493.05", "35.86", "0.0", "252.89");
|
||||||
addRepaymentValues(expectedvalues, todaysDate, 1, "2492.89", "36.02", "0.0", "0.0");
|
addRepaymentValues(expectedvalues, todaysDate, 1, "2491.72", "37.19", "0.0", "0.0");
|
||||||
addRepaymentValues(expectedvalues, todaysDate, 1, "2517.23", "11.68", "0.0", "0.0");
|
addRepaymentValues(expectedvalues, todaysDate, 1, "2517.22", "11.69", "0.0", "0.0");
|
||||||
verifyLoanRepaymentSchedule(loanSchedule, expectedvalues);
|
verifyLoanRepaymentSchedule(loanSchedule, expectedvalues);
|
||||||
|
|
||||||
repaymentDate = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
repaymentDate = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
||||||
@@ -3667,10 +3667,10 @@ public class ClientLoanIntegrationTest {
|
|||||||
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
|
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
|
||||||
expectedvalues = new ArrayList<>();
|
expectedvalues = new ArrayList<>();
|
||||||
todaysDate = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
todaysDate = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
||||||
addRepaymentValues(expectedvalues, todaysDate, -2, "2482.76", "46.15", "0.0", "0.0");
|
addRepaymentValues(expectedvalues, todaysDate, -2, "2482.76", "46.15", "0.0", "252.89");
|
||||||
addRepaymentValues(expectedvalues, todaysDate, 1, "2494.22", "34.69", "0.0", "252.89");
|
addRepaymentValues(expectedvalues, todaysDate, 1, "2493.05", "35.86", "0.0", "252.89");
|
||||||
addRepaymentValues(expectedvalues, todaysDate, 1, "2498.39", "30.52", "0.0", "0.0");
|
addRepaymentValues(expectedvalues, todaysDate, 1, "2491.72", "37.19", "0.0", "0.0");
|
||||||
addRepaymentValues(expectedvalues, todaysDate, 1, "2517.26", "11.65", "0.0", "0.0");
|
addRepaymentValues(expectedvalues, todaysDate, 1, "2517.22", "11.69", "0.0", "0.0");
|
||||||
verifyLoanRepaymentSchedule(loanSchedule, expectedvalues);
|
verifyLoanRepaymentSchedule(loanSchedule, expectedvalues);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-15
@@ -502,8 +502,7 @@ public class Loan extends AbstractPersistable<Long> {
|
|||||||
this.accountNumberRequiresAutoGeneration = accountNumberRequiresAutoGeneration;
|
this.accountNumberRequiresAutoGeneration = accountNumberRequiresAutoGeneration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChangedTransactionDetail addLoanCharge(final LoanCharge loanCharge) {
|
public void addLoanCharge(final LoanCharge loanCharge) {
|
||||||
ChangedTransactionDetail changedTransactionDetail = null;
|
|
||||||
|
|
||||||
validateLoanIsNotClosed(loanCharge);
|
validateLoanIsNotClosed(loanCharge);
|
||||||
|
|
||||||
@@ -554,27 +553,29 @@ public class Loan extends AbstractPersistable<Long> {
|
|||||||
}
|
}
|
||||||
this.charges.add(loanCharge);
|
this.charges.add(loanCharge);
|
||||||
this.summary = updateSummaryWithTotalFeeChargesDueAtDisbursement(deriveSumTotalOfChargesDueAtDisbursement());
|
this.summary = updateSummaryWithTotalFeeChargesDueAtDisbursement(deriveSumTotalOfChargesDueAtDisbursement());
|
||||||
final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.transactionProcessorFactory
|
|
||||||
.determineProcessor(this.transactionProcessingStrategy);
|
|
||||||
|
|
||||||
// store Id's of existing loan transactions and existing reversed loan
|
// store Id's of existing loan transactions and existing reversed loan
|
||||||
// transactions
|
// transactions
|
||||||
final LoanRepaymentScheduleProcessingWrapper wrapper = new LoanRepaymentScheduleProcessingWrapper();
|
final LoanRepaymentScheduleProcessingWrapper wrapper = new LoanRepaymentScheduleProcessingWrapper();
|
||||||
wrapper.reprocess(getCurrency(), getDisbursementDate(), this.repaymentScheduleInstallments, charges(),
|
wrapper.reprocess(getCurrency(), getDisbursementDate(), this.repaymentScheduleInstallments, charges(),
|
||||||
getLastUserTransactionForChargeCalc());
|
getLastUserTransactionForChargeCalc());
|
||||||
if (!loanCharge.isDueAtDisbursement()) {
|
|
||||||
final List<LoanTransaction> allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement();
|
|
||||||
changedTransactionDetail = loanRepaymentScheduleTransactionProcessor.handleTransaction(getDisbursementDate(),
|
|
||||||
allNonContraTransactionsPostDisbursement, getCurrency(), this.repaymentScheduleInstallments, charges(),
|
|
||||||
getLastUserTransactionForChargeCalc());
|
|
||||||
for (final Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail.getNewTransactionMappings().entrySet()) {
|
|
||||||
mapEntry.getValue().updateLoan(this);
|
|
||||||
}
|
|
||||||
// this.loanTransactions.addAll(changedTransactionDetail.getNewTransactionMappings().values());
|
|
||||||
}
|
|
||||||
|
|
||||||
updateLoanSummaryDerivedFields();
|
updateLoanSummaryDerivedFields();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChangedTransactionDetail reprocessTransactions() {
|
||||||
|
ChangedTransactionDetail changedTransactionDetail = null;
|
||||||
|
final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.transactionProcessorFactory
|
||||||
|
.determineProcessor(this.transactionProcessingStrategy);
|
||||||
|
final List<LoanTransaction> allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement();
|
||||||
|
changedTransactionDetail = loanRepaymentScheduleTransactionProcessor.handleTransaction(getDisbursementDate(),
|
||||||
|
allNonContraTransactionsPostDisbursement, getCurrency(), this.repaymentScheduleInstallments, charges(),
|
||||||
|
getLastUserTransactionForChargeCalc());
|
||||||
|
for (final Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail.getNewTransactionMappings().entrySet()) {
|
||||||
|
mapEntry.getValue().updateLoan(this);
|
||||||
|
}
|
||||||
|
this.loanTransactions.addAll(changedTransactionDetail.getNewTransactionMappings().values());
|
||||||
|
updateLoanSummaryDerivedFields();
|
||||||
return changedTransactionDetail;
|
return changedTransactionDetail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+73
-68
@@ -790,9 +790,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
this.paymentDetailWritePlatformService.persistPaymentDetail(paymentDetail);
|
this.paymentDetailWritePlatformService.persistPaymentDetail(paymentDetail);
|
||||||
}
|
}
|
||||||
final CommandProcessingResultBuilder commandProcessingResultBuilder = new CommandProcessingResultBuilder();
|
final CommandProcessingResultBuilder commandProcessingResultBuilder = new CommandProcessingResultBuilder();
|
||||||
LoanTransaction loanTransaction = this.loanAccountDomainService.makeRepayment(loan, commandProcessingResultBuilder, bulkRepaymentCommand.getTransactionDate(),
|
LoanTransaction loanTransaction = this.loanAccountDomainService.makeRepayment(loan, commandProcessingResultBuilder,
|
||||||
singleLoanRepaymentCommand.getTransactionAmount(), paymentDetail, bulkRepaymentCommand.getNote(), null,
|
bulkRepaymentCommand.getTransactionDate(), singleLoanRepaymentCommand.getTransactionAmount(), paymentDetail,
|
||||||
isRecoveryRepayment, isAccountTransfer);
|
bulkRepaymentCommand.getNote(), null, isRecoveryRepayment, isAccountTransfer);
|
||||||
transactionIds.add(loanTransaction.getId());
|
transactionIds.add(loanTransaction.getId());
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1305,13 +1305,27 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
final List<Long> existingReversedTransactionIds = new ArrayList<>(loan.findExistingReversedTransactionIds());
|
final List<Long> existingReversedTransactionIds = new ArrayList<>(loan.findExistingReversedTransactionIds());
|
||||||
|
|
||||||
boolean isAppliedOnBackDate = addCharge(loan, chargeDefinition, loanCharge);
|
boolean isAppliedOnBackDate = addCharge(loan, chargeDefinition, loanCharge);
|
||||||
|
boolean reprocessRequired = true;
|
||||||
if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled()) {
|
if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled()) {
|
||||||
if (isAppliedOnBackDate && loan.isFeeCompoundingEnabledForInterestRecalculation()) {
|
if (isAppliedOnBackDate && loan.isFeeCompoundingEnabledForInterestRecalculation()) {
|
||||||
runScheduleRecalculation(loan);
|
runScheduleRecalculation(loan);
|
||||||
|
reprocessRequired = false;
|
||||||
}
|
}
|
||||||
updateOriginalSchedule(loan);
|
updateOriginalSchedule(loan);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reprocessRequired) {
|
||||||
|
ChangedTransactionDetail changedTransactionDetail = loan.reprocessTransactions();
|
||||||
|
if (changedTransactionDetail != null) {
|
||||||
|
for (final Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail.getNewTransactionMappings().entrySet()) {
|
||||||
|
this.loanTransactionRepository.save(mapEntry.getValue());
|
||||||
|
// update loan with references to the newly created
|
||||||
|
// transactions
|
||||||
|
loan.getLoanTransactions().add(mapEntry.getValue());
|
||||||
|
this.accountTransfersWritePlatformService.updateLoanTransaction(mapEntry.getKey(), mapEntry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveLoanWithDataIntegrityViolationChecks(loan);
|
||||||
}
|
}
|
||||||
|
|
||||||
postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds);
|
postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds);
|
||||||
@@ -1447,36 +1461,16 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
|
|
||||||
this.loanChargeRepository.save(loanCharge);
|
this.loanChargeRepository.save(loanCharge);
|
||||||
|
|
||||||
final ChangedTransactionDetail changedTransactionDetail = loan.addLoanCharge(loanCharge);
|
loan.addLoanCharge(loanCharge);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* we want to apply charge transactions only for those loans charges
|
* we want to apply charge transactions only for those loans charges
|
||||||
* that are applied when a loan is active and the loan product uses
|
* that are applied when a loan is active and the loan product uses
|
||||||
* Upfront Accruals
|
* Upfront Accruals
|
||||||
**/
|
**/
|
||||||
if (loan.status().isActive()) {
|
if (loan.status().isActive() && loan.isNoneOrCashOrUpfrontAccrualAccountingEnabledOnLoanProduct()) {
|
||||||
if (loan.isNoneOrCashOrUpfrontAccrualAccountingEnabledOnLoanProduct()) {
|
final LoanTransaction applyLoanChargeTransaction = loan.handleChargeAppliedTransaction(loanCharge, null, currentUser);
|
||||||
final LoanTransaction applyLoanChargeTransaction = loan.handleChargeAppliedTransaction(loanCharge, null, currentUser);
|
this.loanTransactionRepository.save(applyLoanChargeTransaction);
|
||||||
this.loanTransactionRepository.save(applyLoanChargeTransaction);
|
|
||||||
}
|
|
||||||
/***
|
|
||||||
* TODO Vishwas Batch save is giving me a
|
|
||||||
* HibernateOptimisticLockingFailureException, looping and saving
|
|
||||||
* for the time being, not a major issue for now as this loop is
|
|
||||||
* entered only in edge cases (when a payment is made before the
|
|
||||||
* latest payment recorded against the loan)
|
|
||||||
***/
|
|
||||||
saveLoanWithDataIntegrityViolationChecks(loan);
|
|
||||||
if (changedTransactionDetail != null) {
|
|
||||||
for (final Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail.getNewTransactionMappings().entrySet()) {
|
|
||||||
this.loanTransactionRepository.save(mapEntry.getValue());
|
|
||||||
// update loan with references to the newly created
|
|
||||||
// transactions
|
|
||||||
loan.getLoanTransactions().add(mapEntry.getValue());
|
|
||||||
this.accountTransfersWritePlatformService.updateLoanTransaction(mapEntry.getKey(), mapEntry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
boolean isAppliedOnBackDate = false;
|
boolean isAppliedOnBackDate = false;
|
||||||
if (loanCharge.getDueLocalDate() == null || LocalDate.now().isAfter(loanCharge.getDueLocalDate())) {
|
if (loanCharge.getDueLocalDate() == null || LocalDate.now().isAfter(loanCharge.getDueLocalDate())) {
|
||||||
@@ -2403,13 +2397,29 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
runInterestRecalculation = runInterestRecalculation || overdueDTO.isRunInterestRecalculation();
|
runInterestRecalculation = runInterestRecalculation || overdueDTO.isRunInterestRecalculation();
|
||||||
}
|
}
|
||||||
if (loan != null) {
|
if (loan != null) {
|
||||||
|
boolean reprocessRequired = true;
|
||||||
if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled()) {
|
if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled()) {
|
||||||
if (runInterestRecalculation && loan.isFeeCompoundingEnabledForInterestRecalculation()) {
|
if (runInterestRecalculation && loan.isFeeCompoundingEnabledForInterestRecalculation()) {
|
||||||
runScheduleRecalculation(loan);
|
runScheduleRecalculation(loan);
|
||||||
|
reprocessRequired = false;
|
||||||
}
|
}
|
||||||
updateOriginalSchedule(loan);
|
updateOriginalSchedule(loan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (reprocessRequired) {
|
||||||
|
ChangedTransactionDetail changedTransactionDetail = loan.reprocessTransactions();
|
||||||
|
if (changedTransactionDetail != null) {
|
||||||
|
for (final Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail.getNewTransactionMappings().entrySet()) {
|
||||||
|
this.loanTransactionRepository.save(mapEntry.getValue());
|
||||||
|
// update loan with references to the newly created
|
||||||
|
// transactions
|
||||||
|
loan.getLoanTransactions().add(mapEntry.getValue());
|
||||||
|
this.accountTransfersWritePlatformService.updateLoanTransaction(mapEntry.getKey(), mapEntry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveLoanWithDataIntegrityViolationChecks(loan);
|
||||||
|
}
|
||||||
|
|
||||||
postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds);
|
postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds);
|
||||||
|
|
||||||
if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled() && runInterestRecalculation
|
if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled() && runInterestRecalculation
|
||||||
@@ -2556,59 +2566,54 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateMultiDisbursementData(final JsonCommand command, LocalDate expectedDisbursementDate){
|
private void validateMultiDisbursementData(final JsonCommand command, LocalDate expectedDisbursementDate) {
|
||||||
final String json = command.json();
|
final String json = command.json();
|
||||||
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
|
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
|
||||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan");
|
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan");
|
||||||
final JsonArray disbursementDataArray = command.arrayOfParameterNamed(LoanApiConstants.disbursementDataParameterName);
|
final JsonArray disbursementDataArray = command.arrayOfParameterNamed(LoanApiConstants.disbursementDataParameterName);
|
||||||
if(disbursementDataArray == null || disbursementDataArray.size() == 0){
|
if (disbursementDataArray == null || disbursementDataArray.size() == 0) {
|
||||||
final String errorMessage = "For this loan product, disbursement details must be provided";
|
final String errorMessage = "For this loan product, disbursement details must be provided";
|
||||||
throw new MultiDisbursementDataRequiredException(LoanApiConstants.disbursementDataParameterName, errorMessage);
|
throw new MultiDisbursementDataRequiredException(LoanApiConstants.disbursementDataParameterName, errorMessage);
|
||||||
}
|
}
|
||||||
final BigDecimal principal = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("approvedLoanAmount", element);
|
final BigDecimal principal = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("approvedLoanAmount", element);
|
||||||
|
|
||||||
loanApplicationCommandFromApiJsonHelper.validateLoanMultiDisbursementdate(element, baseDataValidator, expectedDisbursementDate, principal);
|
loanApplicationCommandFromApiJsonHelper.validateLoanMultiDisbursementdate(element, baseDataValidator, expectedDisbursementDate,
|
||||||
|
principal);
|
||||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public CommandProcessingResult addAndDeleteLoanDisburseDetails(Long loanId, JsonCommand command) {
|
public CommandProcessingResult addAndDeleteLoanDisburseDetails(Long loanId, JsonCommand command) {
|
||||||
|
|
||||||
final Loan loan = this.loanAssembler.assembleFrom(loanId);
|
final Loan loan = this.loanAssembler.assembleFrom(loanId);
|
||||||
checkClientOrGroupActive(loan);
|
checkClientOrGroupActive(loan);
|
||||||
final Map<String, Object> actualChanges = new LinkedHashMap<>();
|
final Map<String, Object> actualChanges = new LinkedHashMap<>();
|
||||||
LocalDate expectedDisbursementDate = loan.getExpectedDisbursedOnLocalDate();
|
LocalDate expectedDisbursementDate = loan.getExpectedDisbursedOnLocalDate();
|
||||||
validateMultiDisbursementData(command, expectedDisbursementDate);
|
validateMultiDisbursementData(command, expectedDisbursementDate);
|
||||||
|
|
||||||
loan.updateDisbursementDetails(command, actualChanges);
|
loan.updateDisbursementDetails(command, actualChanges);
|
||||||
|
|
||||||
if (loan.getDisbursementDetails().isEmpty()) {
|
if (loan.getDisbursementDetails().isEmpty()) {
|
||||||
final String errorMessage = "For this loan product, disbursement details must be provided";
|
final String errorMessage = "For this loan product, disbursement details must be provided";
|
||||||
throw new MultiDisbursementDataRequiredException(
|
throw new MultiDisbursementDataRequiredException(LoanApiConstants.disbursementDataParameterName, errorMessage);
|
||||||
LoanApiConstants.disbursementDataParameterName,
|
}
|
||||||
errorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loan.getDisbursementDetails().size() > loan.loanProduct()
|
if (loan.getDisbursementDetails().size() > loan.loanProduct().maxTrancheCount()) {
|
||||||
.maxTrancheCount()) {
|
final String errorMessage = "Number of tranche shouldn't be greter than " + loan.loanProduct().maxTrancheCount();
|
||||||
final String errorMessage = "Number of tranche shouldn't be greter than "
|
throw new ExceedingTrancheCountException(LoanApiConstants.disbursementDataParameterName, errorMessage, loan.loanProduct()
|
||||||
+ loan.loanProduct().maxTrancheCount();
|
.maxTrancheCount(), loan.getDisbursementDetails().size());
|
||||||
throw new ExceedingTrancheCountException(
|
}
|
||||||
LoanApiConstants.disbursementDataParameterName,
|
LoanDisbursementDetails updateDetails = null;
|
||||||
errorMessage, loan.loanProduct().maxTrancheCount(),
|
return processLoanDisbursementDetail(loan, loanId, command, updateDetails);
|
||||||
loan.getDisbursementDetails().size());
|
|
||||||
}
|
|
||||||
LoanDisbursementDetails updateDetails = null;
|
|
||||||
return processLoanDisbursementDetail(loan, loanId, command, updateDetails);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandProcessingResult processLoanDisbursementDetail(final Loan loan, Long loanId, JsonCommand command,
|
private CommandProcessingResult processLoanDisbursementDetail(final Loan loan, Long loanId, JsonCommand command,
|
||||||
LoanDisbursementDetails loanDisbursementDetails){
|
LoanDisbursementDetails loanDisbursementDetails) {
|
||||||
final CalendarInstance calendarInstance = this.calendarInstanceRepository.findCalendarInstaneByEntityId(loan.getId(),
|
final CalendarInstance calendarInstance = this.calendarInstanceRepository.findCalendarInstaneByEntityId(loan.getId(),
|
||||||
CalendarEntityType.LOANS.getValue());
|
CalendarEntityType.LOANS.getValue());
|
||||||
final LocalDate calculatedRepaymentsStartingFromDate = this.loanAccountDomainService.getCalculatedRepaymentsStartingFromDate(
|
final LocalDate calculatedRepaymentsStartingFromDate = this.loanAccountDomainService.getCalculatedRepaymentsStartingFromDate(
|
||||||
loan.getDisbursementDate(), loan, calendarInstance);
|
loan.getDisbursementDate(), loan, calendarInstance);
|
||||||
@@ -2640,20 +2645,20 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
ChangedTransactionDetail changedTransactionDetail = null;
|
ChangedTransactionDetail changedTransactionDetail = null;
|
||||||
AppUser currentUser = getAppUserIfPresent();
|
AppUser currentUser = getAppUserIfPresent();
|
||||||
|
|
||||||
if(command.entityId() != null){
|
if (command.entityId() != null) {
|
||||||
|
|
||||||
changedTransactionDetail = loan.updateDisbursementDateAndAmountForTranche(loanDisbursementDetails, command,
|
changedTransactionDetail = loan.updateDisbursementDateAndAmountForTranche(loanDisbursementDetails, command,
|
||||||
existingTransactionIds, existingReversedTransactionIds, changes, scheduleGeneratorDTO, currentUser);
|
existingTransactionIds, existingReversedTransactionIds, changes, scheduleGeneratorDTO, currentUser);
|
||||||
}else{
|
} else {
|
||||||
Collection<LoanDisbursementDetails> loanDisburseDetails = loan.getDisbursementDetails();
|
Collection<LoanDisbursementDetails> loanDisburseDetails = loan.getDisbursementDetails();
|
||||||
BigDecimal setAmount = BigDecimal.ZERO;
|
BigDecimal setAmount = BigDecimal.ZERO;
|
||||||
for (LoanDisbursementDetails details : loanDisburseDetails) {
|
for (LoanDisbursementDetails details : loanDisburseDetails) {
|
||||||
setAmount = setAmount.add(details.principal());
|
setAmount = setAmount.add(details.principal());
|
||||||
}
|
}
|
||||||
|
|
||||||
loan.repaymentScheduleDetail().setPrincipal(setAmount);
|
loan.repaymentScheduleDetail().setPrincipal(setAmount);
|
||||||
|
|
||||||
if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled()) {
|
if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled()) {
|
||||||
loan.regenerateRepaymentScheduleWithInterestRecalculation(scheduleGeneratorDTO, currentUser);
|
loan.regenerateRepaymentScheduleWithInterestRecalculation(scheduleGeneratorDTO, currentUser);
|
||||||
} else {
|
} else {
|
||||||
loan.regenerateRepaymentSchedule(scheduleGeneratorDTO, currentUser);
|
loan.regenerateRepaymentSchedule(scheduleGeneratorDTO, currentUser);
|
||||||
@@ -2678,19 +2683,19 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
.withGroupId(loan.getGroupId()) //
|
.withGroupId(loan.getGroupId()) //
|
||||||
.withLoanId(loanId) //
|
.withLoanId(loanId) //
|
||||||
.with(changes).build();
|
.with(changes).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public CommandProcessingResult updateDisbursementDateAndAmountForTranche(final Long loanId, final Long disbursementId, final JsonCommand command) {
|
public CommandProcessingResult updateDisbursementDateAndAmountForTranche(final Long loanId, final Long disbursementId,
|
||||||
|
final JsonCommand command) {
|
||||||
|
|
||||||
final Loan loan = this.loanAssembler.assembleFrom(loanId);
|
final Loan loan = this.loanAssembler.assembleFrom(loanId);
|
||||||
checkClientOrGroupActive(loan);
|
checkClientOrGroupActive(loan);
|
||||||
LoanDisbursementDetails loanDisbursementDetails = loan.fetchLoanDisbursementsById(disbursementId);
|
LoanDisbursementDetails loanDisbursementDetails = loan.fetchLoanDisbursementsById(disbursementId);
|
||||||
this.loanEventApiJsonValidator.validateUpdateDisbursementDateAndAmount(command.json(), loanDisbursementDetails);
|
this.loanEventApiJsonValidator.validateUpdateDisbursementDateAndAmount(command.json(), loanDisbursementDetails);
|
||||||
|
|
||||||
return processLoanDisbursementDetail(loan, loanId, command, loanDisbursementDetails);
|
return processLoanDisbursementDetail(loan, loanId, command, loanDisbursementDetails);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user