Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SU-450 : Novelty management - Update Charge-Off #1302

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading