Skip to content

Commit

Permalink
Merge pull request #1302 from fiterlatam/bug/SU-450
Browse files Browse the repository at this point in the history
SU-450 : Novelty management - Update Charge-Off
  • Loading branch information
tabrez-fiter authored Nov 20, 2024
2 parents c33f270 + 6c8ffc7 commit 23e8028
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public void validateChargeOffTransaction(final String json) {
}

final Set<String> chargeOffParameters = new HashSet<>(
Arrays.asList("transactionDate", "note", "locale", "dateFormat", "chargeOffReasonId", "externalId"));
Arrays.asList("transactionDate", "note", "locale", "dateFormat", "chargeOffReasonId", "externalId", "incidentTypeId"));

final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, chargeOffParameters);
Expand All @@ -456,6 +456,9 @@ public void validateChargeOffTransaction(final String json) {
final Long chargeOffReasonId = fromApiJsonHelper.extractLongNamed("chargeOffReasonId", element);
baseDataValidator.reset().parameter("chargeOffReasonId").value(chargeOffReasonId).ignoreIfNull().integerGreaterThanZero();

final Long incidentTypeId = fromApiJsonHelper.extractLongNamed("incidentTypeId", element);
baseDataValidator.reset().parameter("incidentTypeId").value(incidentTypeId).ignoreIfNull().integerGreaterThanZero();

throwExceptionIfValidationWarningsExist(dataValidationErrors);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3612,18 +3612,37 @@ public CommandProcessingResult chargeOff(JsonCommand command) {

checkIfProductAllowsCancelationOrReversal(loan);

businessEventNotifierService.notifyPreBusinessEvent(new LoanChargeOffPreBusinessEvent(loan));
loan.markAsChargedOff(transactionDate, currentUser, null);

if (command.hasParameter(LoanApiConstants.chargeOffReasonIdParamName)) {
Long chargeOffReasonId = command.longValueOfParameterNamed(LoanApiConstants.chargeOffReasonIdParamName);
CodeValue chargeOffReason = this.codeValueRepository
.findOneByCodeNameAndIdWithNotFoundDetection(LoanApiConstants.CHARGE_OFF_REASONS, chargeOffReasonId);
changes.put(LoanApiConstants.chargeOffReasonIdParamName, chargeOffReasonId);
loan.markAsChargedOff(transactionDate, currentUser, chargeOffReason);
} else {
loan.markAsChargedOff(transactionDate, currentUser, null);
InsuranceIncidentType incidentType = InsuranceIncidentType.DEATH_CANCELLATION;
if (command.hasParameter("incidentTypeId")) {
Integer incidentTypeId = command.integerValueOfParameterNamed("incidentTypeId");
incidentType = InsuranceIncidentType.fromInt(incidentTypeId);
}

this.loanScheduleHistoryWritePlatformService.createAndSaveLoanScheduleArchive(loan.getRepaymentScheduleInstallments(), loan, null);
List<DefaultOrCancelInsuranceInstallmentData> cancelInsuranceInstallmentIds = this.loanReadPlatformService
.getLoanDataWithDefaultOrCancelInsurance(loanId, null, transactionDate);
InsuranceIncident incident = this.insuranceIncidentRepository.findByIncidentType(incidentType);
if (incident == null) {
throw new InsuranceIncidentNotFoundException(InsuranceIncidentType.DEATH_CANCELLATION.name());
}
for (final DefaultOrCancelInsuranceInstallmentData data : cancelInsuranceInstallmentIds) {
LoanCharge loanCharge = null;
Optional<LoanCharge> loanChargeOptional = loan.getLoanCharges().stream()
.filter(lc -> Objects.equals(lc.getId(), data.loanChargeId())).findFirst();
if (loanChargeOptional.isPresent()) {
loanCharge = loanChargeOptional.get();
}
BigDecimal cumulative = BigDecimal.ZERO;
cumulative = processInsuranceChargeCancellation(cumulative, loan, loanCharge, data, true);
InsuranceIncidentNoveltyNews insuranceIncidentNoveltyNews = InsuranceIncidentNoveltyNews.instance(loan, loanCharge,
data.installment(), incident, transactionDate, cumulative);
this.insuranceIncidentNoveltyNewsRepository.saveAndFlush(insuranceIncidentNoveltyNews);
}

businessEventNotifierService.notifyPreBusinessEvent(new LoanChargeOffPreBusinessEvent(loan));

final List<Long> existingTransactionIds = loan.findExistingTransactionIds();
final List<Long> existingReversedTransactionIds = loan.findExistingReversedTransactionIds();
loan.getLoanCustomizationDetail().recordActivity();
Expand All @@ -3640,6 +3659,11 @@ public CommandProcessingResult chargeOff(JsonCommand command) {
this.noteRepository.save(note);
}

this.loanAccountDomainService.foreCloseLoan(loan, transactionDate, noteText, txnExternalId, changes);
final BlockingReasonSetting blockingReasonSetting = loanBlockingReasonRepository.getSingleBlockingReasonSettingByReason(
BlockingReasonSettingEnum.CREDIT_CANCELADO.getDatabaseString(), BlockLevel.CREDIT.toString());
loanBlockWritePlatformService.blockLoan(loan.getId(), blockingReasonSetting, "CANCELADO", DateUtils.getLocalDateOfTenant());

postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds);
businessEventNotifierService.notifyPostBusinessEvent(new LoanChargeOffPostBusinessEvent(chargeOffTransaction));
return new CommandProcessingResultBuilder() //
Expand Down

0 comments on commit 23e8028

Please sign in to comment.