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-542] SU-535 - NOVEDADES - Adjustments for Notifications on Restru… #1437

Merged
merged 1 commit into from
Dec 26, 2024
Merged
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 @@ -56,6 +56,12 @@
import org.apache.fineract.organisation.monetary.domain.MoneyHelper;
import org.apache.fineract.portfolio.account.service.AccountTransfersWritePlatformService;
import org.apache.fineract.portfolio.delinquency.service.DelinquencyReadPlatformService;
import org.apache.fineract.portfolio.insurance.domain.InsuranceIncident;
import org.apache.fineract.portfolio.insurance.domain.InsuranceIncidentNoveltyNews;
import org.apache.fineract.portfolio.insurance.domain.InsuranceIncidentNoveltyNewsRepository;
import org.apache.fineract.portfolio.insurance.domain.InsuranceIncidentRepository;
import org.apache.fineract.portfolio.insurance.domain.InsuranceIncidentType;
import org.apache.fineract.portfolio.insurance.exception.InsuranceIncidentNotFoundException;
import org.apache.fineract.portfolio.loanaccount.data.CollectionData;
import org.apache.fineract.portfolio.loanaccount.data.LoanTermVariationsData;
import org.apache.fineract.portfolio.loanaccount.data.ScheduleGeneratorDTO;
Expand Down Expand Up @@ -122,6 +128,8 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
private final LoanReadPlatformService loanReadPlatformService;
private final DelinquencyReadPlatformService delinquencyReadPlatformService;
private final LoanTermVariationsRepository loanTermVariationsRepository;
private final InsuranceIncidentRepository insuranceIncidentRepository;
private final InsuranceIncidentNoveltyNewsRepository insuranceIncidentNoveltyNewsRepository;

/**
* create a new instance of the LoanRescheduleRequest object from the JsonCommand object and persist
Expand Down Expand Up @@ -609,6 +617,8 @@ public CommandProcessingResult approve(JsonCommand jsonCommand) {
// Trigger transaction replayed event
replayedTransactionBusinessEventService.raiseTransactionReplayedEvents(changedTransactionDetail);
}
// we need to create Novedad rediferido once the loan is rescheduled
createRediferidoNovelty(loan);
loan = saveAndFlushLoanWithDataIntegrityViolationChecks(loan);
// update the loan object
postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds);
Expand All @@ -628,6 +638,7 @@ public CommandProcessingResult approve(JsonCommand jsonCommand) {
return new CommandProcessingResultBuilder().withCommandId(jsonCommand.commandId()).withEntityId(loanRescheduleRequestId)
.withLoanId(loanRescheduleRequest.getLoan().getId()).with(changes).withClientId(loan.getClientId())
.withOfficeId(loan.getOfficeId()).withGroupId(loan.getGroupId()).build();

} catch (final JpaSystemException | DataIntegrityViolationException dve) {
// handle the data integrity violation
handleDataIntegrityViolation(dve);
Expand Down Expand Up @@ -743,4 +754,25 @@ private void handleDataIntegrityViolation(final NonTransientDataAccessException
throw ErrorHandler.getMappable(dve, "error.msg.loan.reschedule.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.");
}

private void createRediferidoNovelty(Loan loan) {
InsuranceIncidentType incidentType = InsuranceIncidentType.NOVEDAD_REDIFERIDO;
InsuranceIncident incident = this.insuranceIncidentRepository.findByIncidentType(incidentType);
if (incident == null || !incident.isValid()) {
throw new InsuranceIncidentNotFoundException(incidentType.name());
}
final LocalDate incidentDate = DateUtils.getBusinessLocalDate();
MonetaryCurrency currency = loan.getCurrency();
for (LoanCharge loanCharge : loan.getCharges()) {
boolean isChargeEligibleForNoveltyNews = loanCharge.getAmountOutstanding(currency).isGreaterThanZero()
&& ((incident.isMandatory() && loanCharge.isMandatoryInsurance())
|| (incident.isVoluntary() && loanCharge.isVoluntaryInsurance()));

if (isChargeEligibleForNoveltyNews) {
InsuranceIncidentNoveltyNews noveltyNews = InsuranceIncidentNoveltyNews.instance(loan, loanCharge, null, incident,
incidentDate, BigDecimal.ZERO);
this.insuranceIncidentNoveltyNewsRepository.saveAndFlush(noveltyNews);
}
}
}
}
Loading