Skip to content

Commit

Permalink
SU-316 : Redefinición de Honorarios / Redefinition of Fees (Honorarios)
Browse files Browse the repository at this point in the history
  • Loading branch information
tabrez-fiter committed Nov 21, 2024
1 parent c4ebb8f commit 6c0388d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ public class DelinquencyRange extends AbstractAuditableWithUTCDateTimeCustom {
@Version
private Long version;

protected DelinquencyRange(@NotNull String classification, @NotNull Integer minimumAgeDays, Integer maximumAgeDays, Integer percentageValue) {
protected DelinquencyRange(@NotNull String classification, @NotNull Integer minimumAgeDays, Integer maximumAgeDays,
Integer percentageValue) {
this.classification = classification;
this.minimumAgeDays = minimumAgeDays;
this.maximumAgeDays = maximumAgeDays;
this.percentageValue = percentageValue;
}

public static DelinquencyRange instance(@NotNull String classification, @NotNull Integer minimumAge, Integer maximumAge, Integer percentageValue) {
public static DelinquencyRange instance(@NotNull String classification, @NotNull Integer minimumAge, Integer maximumAge,
Integer percentageValue) {
return new DelinquencyRange(classification, minimumAge, maximumAge, percentageValue);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public LoanTransaction makeRepayment(final LoanTransactionType repaymentTransact
if (loan.getAgeOfOverdueDays(DateUtils.getBusinessLocalDate()) > 0) {
for (LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment : loanRepaymentScheduleInstallments) {
if (loanRepaymentScheduleInstallment.isOverdueOn(transactionDate) && !loanRepaymentScheduleInstallment.isObligationsMet()) {

updateCalculationHonoLoanChargeOverDueVat(repaymentAmount.getAmount(), loanRepaymentScheduleInstallment);
break;
}
Expand Down Expand Up @@ -337,33 +338,50 @@ private void updateCalculationHonoLoanChargeOverDueVat(BigDecimal repaymentAmoun
// Step 4: Fee VAT = Value of fee with VAT - Fee basis
BigDecimal feeVat = feewithTax.subtract(feeBasis).setScale(2, MoneyHelper.getRoundingMode());
BigDecimal feeHono = feeVat.add(feeBasis).setScale(0, MoneyHelper.getRoundingMode());

Optional<LoanCharge> charges = loanRepaymentScheduleInstallment.getLoan().getActiveCharges().stream()
// End Calculate
Loan loan = loanRepaymentScheduleInstallment.getLoan();
Optional<LoanCharge> charges = loan.getActiveCharges().stream()
.filter(charge -> charge.getChargeCalculation().isFlatHono() || charge.getChargeCalculation().isPercentageOfHonorarios())
.findFirst();

if (charges.isPresent()) {
LoanCharge chargeHono = charges.get();
Money newAmountHono = chargeHono.getAmount(currency).minus(feeHono);
chargeHono.setInstallmentChargeAmount(newAmountHono.getAmount());
Set<CustomChargeHonorarioMap> honoMap = chargeHono.getCustomChargeHonorarioMaps();
CustomChargeHonorarioMap current = new CustomChargeHonorarioMap();
current.setFeeBaseAmount(feeBasis);
current.setNit("120843958");
current.setLoanId(loanRepaymentScheduleInstallment.getLoan().getId());
current.setFeeTotalAmount(feeHono);
current.setFeeVatAmount(feeVat);
current.setLoanInstallmentNr(loanRepaymentScheduleInstallment.getInstallmentNumber());
current.setCreatedBy(this.platformSecurityContext.authenticatedUser().getId());
current.setCreatedAt(DateUtils.getLocalDateTimeOfTenant());
current.setUpdatedAt(DateUtils.getLocalDateTimeOfTenant());
current.setUpdatedBy(this.platformSecurityContext.authenticatedUser().getId());
current.setUpdatedAt(DateUtils.getLocalDateTimeOfTenant());
current.setLoanChargeId(chargeHono.getId());

customChargeHonorarioMapRepository.saveAndFlush(current);

// loanRepaymentScheduleInstallment.getLoan().updateLoanDerivedFields();
// loanRepaymentScheduleInstallment.getLoan().updateLoanScheduleAfterCustomChargeApplied();
chargeHono.setInstallmentChargeAmount(chargeHono.chargeAmount().add(feeHono));
chargeHono.resetAndUpdateInstallmentCharges();
Optional<CustomChargeHonorarioMap> honoMap = chargeHono.getCustomChargeHonorarioMaps().stream()
.filter(customChargeHonorarioMap -> customChargeHonorarioMap.getLoanInstallmentNr() == loanRepaymentScheduleInstallment
.getInstallmentNumber() && !loanRepaymentScheduleInstallment.isObligationsMet())
.findFirst();
if (!honoMap.isEmpty()) {
// for (CustomChargeHonorarioMap honorarioMap : honoMap) {
CustomChargeHonorarioMap honorarioMap = honoMap.get();
honorarioMap.setFeeBaseAmount(feeBasis);
honorarioMap.setFeeTotalAmount(feeHono);
honorarioMap.setFeeVatAmount(feeVat);
honorarioMap.setUpdatedBy(this.platformSecurityContext.authenticatedUser().getId());
honorarioMap.setUpdatedAt(DateUtils.getLocalDateTimeOfTenant());
honorarioMap.setLoanChargeId(chargeHono.getId());
// customChargeHonorarioMapRepository.save(honorarioMap);
// }
} else {
CustomChargeHonorarioMap current = new CustomChargeHonorarioMap();
current.setNit("120843958");
current.setFeeBaseAmount(feeBasis);
current.setFeeTotalAmount(feeHono);
current.setFeeVatAmount(feeVat);
current.setLoanId(loan.getId());
current.setLoanInstallmentNr(loanRepaymentScheduleInstallment.getInstallmentNumber());
current.setCreatedBy(platformSecurityContext.authenticatedUser().getId());
current.setCreatedAt(DateUtils.getLocalDateTimeOfTenant());
current.setUpdatedBy(this.platformSecurityContext.authenticatedUser().getId());
current.setUpdatedAt(DateUtils.getLocalDateTimeOfTenant());
current.setLoanChargeId(chargeHono.getId());
customChargeHonorarioMapRepository.save(current);
}

loan.addLoanCharge(chargeHono);
saveAndFlushLoanWithDataIntegrityViolationChecks(loan);
loan.updateLoanScheduleAfterCustomChargeApplied();

}

Expand Down

0 comments on commit 6c0388d

Please sign in to comment.