Skip to content

Commit

Permalink
SU-320 (#1304)
Browse files Browse the repository at this point in the history
* SU-320 SU-443
  • Loading branch information
faheem205 authored Nov 20, 2024
1 parent 9d03d18 commit 3f7c6c7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ public static boolean isOnOrAfter(LocalDate first, LocalDate second) {
return first != null && (second == null || first.isAfter(second) || first.isEqual(second));
}

public static boolean isOnOrBefore(LocalDate first, LocalDate second) {
return second != null && (first == null || first.isBefore(second) || first.isEqual(second));
}

public static long getDifferenceInDays(final LocalDate localDateBefore, final LocalDate localDateAfter) {
return DAYS.between(localDateBefore, localDateAfter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4248,16 +4248,16 @@ private Money calculateTotalOverpayment() {
// if total paid in transactions doesnt match repayment schedule then
// theres an overpayment.
Money overpaid = totalPaidInRepayments.minus(cumulativeTotalPaidOnInstallments);
if (overpaid.isZero()) {
Money totalPrincipalPaid = Money.zero(this.getCurrency());
for (final LoanRepaymentScheduleInstallment scheduledRepayment : installments) {
totalPrincipalPaid = totalPrincipalPaid.add(
scheduledRepayment.getPrincipalCompleted(this.getCurrency()).plus(scheduledRepayment.getAdvancePrincipalAmount()));
}
if (totalPrincipalPaid.isGreaterThan(this.getPrincipal())) {
overpaid = totalPrincipalPaid.minus(this.getPrincipal());
}
}

/*
* // This code was added initially under SU-320 to handle overpayments but later on it is no longer needed
* based on the way overpayment is now handled if (overpaid.isZero()) { Money totalPrincipalPaid =
* Money.zero(this.getCurrency()); for (final LoanRepaymentScheduleInstallment scheduledRepayment :
* installments) { totalPrincipalPaid = totalPrincipalPaid.add(
* scheduledRepayment.getPrincipalCompleted(this.getCurrency()).plus(scheduledRepayment.
* getAdvancePrincipalAmount())); } if (totalPrincipalPaid.isGreaterThan(this.getPrincipal())) { overpaid =
* totalPrincipalPaid.minus(this.getPrincipal()); } }
*/
return overpaid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ private Money processAllocationsHorizontally(LoanTransaction loanTransaction, Mo
if (transactionAmountUnprocessed.isGreaterThanZero()) {
if (inAdvanceInstallment.isLastInstallment(installments)
&& inAdvanceInstallment.isOverpaidInAdvance(currency) && transactionAmountUnprocessed
.isGreaterThan(inAdvanceInstallment.getPrincipal(currency))) {
.isGreaterThanOrEqualTo(inAdvanceInstallment.getPrincipal(currency))) {
// This MUST be true only in case of advance overpayment after repayment
// schedule is regenerated
// Process principal and move the remaining amount to overpaid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,32 @@ public void populate(Workbook workbook, String dateFormat) {
writeString(CURRENCY_CODE_COL, row, currencies.getCode());
}
int channelRowIndex = 1;
for (ChannelData channelData : channelOptions) {
Row row;
if (channelRowIndex < currencyCodeRowIndex || currencyCodeRowIndex < paymentTypeRowIndex
|| currencyCodeRowIndex < fundRowIndex) {
row = extrasSheet.getRow(channelRowIndex++);
} else {
row = extrasSheet.createRow(channelRowIndex++);
if (channelOptions != null) {
for (ChannelData channelData : channelOptions) {
Row row;
if (channelRowIndex < currencyCodeRowIndex || currencyCodeRowIndex < paymentTypeRowIndex
|| currencyCodeRowIndex < fundRowIndex) {
row = extrasSheet.getRow(channelRowIndex++);
} else {
row = extrasSheet.createRow(channelRowIndex++);
}
writeLong(CHANNEL_ID_COL, row, channelData.getId());
writeString(CHANNEL_NAME_COL, row, channelData.getName().trim().replaceAll("[ )(]", "_"));
}
writeLong(CHANNEL_ID_COL, row, channelData.getId());
writeString(CHANNEL_NAME_COL, row, channelData.getName().trim().replaceAll("[ )(]", "_"));
}
int bankRowIndex = 1;
for (CodeValueData bankCodeValueData : bankOptions) {
Row row;
if (bankRowIndex < channelRowIndex || channelRowIndex < currencyCodeRowIndex || currencyCodeRowIndex < paymentTypeRowIndex
|| currencyCodeRowIndex < fundRowIndex) {
row = extrasSheet.getRow(bankRowIndex++);
} else {
row = extrasSheet.createRow(bankRowIndex++);
if (bankOptions != null) {
for (CodeValueData bankCodeValueData : bankOptions) {
Row row;
if (bankRowIndex < channelRowIndex || channelRowIndex < currencyCodeRowIndex || currencyCodeRowIndex < paymentTypeRowIndex
|| currencyCodeRowIndex < fundRowIndex) {
row = extrasSheet.getRow(bankRowIndex++);
} else {
row = extrasSheet.createRow(bankRowIndex++);
}
writeLong(BANK_ID_COL, row, bankCodeValueData.getId());
writeString(BANK_NAME_COL, row, bankCodeValueData.getName().trim().replaceAll("[ )(]", "_"));
}
writeLong(BANK_ID_COL, row, bankCodeValueData.getId());
writeString(BANK_NAME_COL, row, bankCodeValueData.getName().trim().replaceAll("[ )(]", "_"));
}
extrasSheet.protectSheet("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3071,7 +3071,9 @@ private LoanScheduleDTO rescheduleNextInstallmentsForProgressiveLoans(final Math
}
}
// Extra amount paid in advance
if (outstandingBalance.isLessThanZero()) {
if (outstandingBalance.isZero() || outstandingBalance.isLessThanZero()) {
// Check outstandingBalance.isZero() in case customer pays exact amount equal to outstanding
// balance
// If overpaid in advance then add the last installment to keep track of advance payment amount
outstandingBalanceAsPerRest = outstandingBalance.zero();
outstandingBalance = outstandingBalance.zero();
Expand Down Expand Up @@ -3283,7 +3285,7 @@ private LoanScheduleDTO rescheduleNextInstallmentsForProgressiveLoans(final Math
.plus(totalPenaltyChargesCharged);

// for partial schedule generation
if (!newRepaymentScheduleInstallments.isEmpty() && totalCumulativeInterest.isGreaterThanZero()) {
if (!newRepaymentScheduleInstallments.isEmpty()) {
Money totalOutstandingInterestPaymentDueToGrace = Money.zero(currency);
loanScheduleParams = LoanScheduleParams.createLoanScheduleParamsForPartialUpdate(periodNumber, instalmentNumber,
loanTermInDays, periodStartDate, actualRepaymentDate, totalCumulativePrincipal, totalCumulativeInterest,
Expand Down Expand Up @@ -3362,7 +3364,7 @@ private List<LoanRepaymentScheduleInstallment> fetchRetainedInstallmentsForProgr
MonetaryCurrency currency) {
List<LoanRepaymentScheduleInstallment> newRepaymentScheduleInstallments = new ArrayList<>();
for (LoanRepaymentScheduleInstallment installment : repaymentScheduleInstallments) {
if (DateUtils.isBefore(installment.getFromDate(), rescheduleFrom)) {
if (DateUtils.isOnOrBefore(installment.getFromDate(), rescheduleFrom)) {
newRepaymentScheduleInstallments.add(installment);
} else {
// Check if there is any installment having advance payment then add the installment to calculate
Expand Down

0 comments on commit 3f7c6c7

Please sign in to comment.