FINERACT-2081: Code quality, eliminate duplicated methods, use utility
This commit is contained in:
committed by
Adam Saghy
parent
001d586e30
commit
9812f14ad7
+1
-2
@@ -32,7 +32,6 @@ import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -906,7 +905,7 @@ public class LoanScheduleAssembler {
|
||||
|
||||
LocalDate previousDate = loan.getDisbursementDate();
|
||||
for (LocalDate duedate : dueDates) {
|
||||
int gap = Math.toIntExact(ChronoUnit.DAYS.between(previousDate, duedate));
|
||||
int gap = DateUtils.getExactDifferenceInDays(previousDate, duedate);
|
||||
previousDate = duedate;
|
||||
if (gap < minGap || (maxGap != null && gap > maxGap)) {
|
||||
baseDataValidator.reset().value(duedate).failWithCodeNoParameterAddedToErrorCode(
|
||||
|
||||
+2
-2
@@ -22,12 +22,12 @@ import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.apache.fineract.organisation.monetary.data.CurrencyData;
|
||||
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
|
||||
@@ -181,7 +181,7 @@ public class LoanScheduleHistoryReadPlatformServiceImpl implements LoanScheduleH
|
||||
|
||||
Integer daysInPeriod = 0;
|
||||
if (fromDate != null) {
|
||||
daysInPeriod = Math.toIntExact(ChronoUnit.DAYS.between(fromDate, dueDate));
|
||||
daysInPeriod = DateUtils.getExactDifferenceInDays(fromDate, dueDate);
|
||||
loanTermInDays = loanTermInDays + daysInPeriod;
|
||||
}
|
||||
|
||||
|
||||
+7
-20
@@ -22,7 +22,6 @@ import static org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction.a
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
@@ -158,7 +157,6 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
/**
|
||||
* method adds accrual for batch job "Add Accrual Transactions"
|
||||
*/
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void addAccrualAccounting(final Long loanId, final Collection<LoanScheduleAccrualData> loanScheduleAccrualData) {
|
||||
@@ -239,7 +237,6 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
reprocessNonPeriodicAccruals(loan, accruals);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,7 +296,6 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
/**
|
||||
* method calculates accruals for loan on loan closure
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void processAccrualsForLoanClosure(Loan loan) {
|
||||
// check and process accruals for loan WITHOUT interest recalculation details and compounding posted as income
|
||||
@@ -307,13 +303,11 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
|
||||
// check and process accruals for loan WITH interest recalculation details and compounding posted as income
|
||||
processIncomeAndAccrualTransactionOnLoanClosure(loan);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* method calculates accruals for loan on loan fore closure
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void processAccrualsForLoanForeClosure(Loan loan, LocalDate foreClosureDate,
|
||||
Collection<LoanTransaction> newAccrualTransactions) {
|
||||
@@ -337,7 +331,6 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
feePortion, penaltyPortion, total);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void calculateFinalAccrualsForScheduleTillSpecificDateAndAddAccrualAccounting(final LocalDate tillDate,
|
||||
@@ -414,7 +407,7 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
}
|
||||
}
|
||||
|
||||
int totalNumberOfDays = Math.toIntExact(ChronoUnit.DAYS.between(interestStartDate, accrualData.getDueDateAsLocaldate()));
|
||||
int totalNumberOfDays = DateUtils.getExactDifferenceInDays(interestStartDate, accrualData.getDueDateAsLocaldate());
|
||||
LocalDate startDate = accrualData.getFromDateAsLocaldate();
|
||||
if (DateUtils.isBefore(startDate, accrualData.getInterestCalculatedFrom())) {
|
||||
if (DateUtils.isBefore(accrualData.getInterestCalculatedFrom(), tillDate)) {
|
||||
@@ -423,7 +416,7 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
startDate = tillDate;
|
||||
}
|
||||
}
|
||||
int daysToBeAccrued = Math.toIntExact(ChronoUnit.DAYS.between(startDate, tillDate));
|
||||
int daysToBeAccrued = DateUtils.getExactDifferenceInDays(startDate, tillDate);
|
||||
double interestPerDay = accrualData.getAccruableIncome().doubleValue() / totalNumberOfDays;
|
||||
|
||||
if (daysToBeAccrued >= totalNumberOfDays) {
|
||||
@@ -535,7 +528,8 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
|
||||
// update repayment schedule portions
|
||||
|
||||
LoanRepaymentScheduleInstallment loanScheduleInstallment = loan.getRepaymentScheduleInstallment(scheduleAccrualData.getDueDate());
|
||||
LoanRepaymentScheduleInstallment loanScheduleInstallment = loan
|
||||
.fetchLoanRepaymentScheduleInstallmentByDueDate(scheduleAccrualData.getDueDate());
|
||||
loanScheduleInstallment.updateAccrualPortion(Money.of(currency, totalAccInterest), Money.of(currency, totalAccFee),
|
||||
Money.of(currency, totalAccPenalty));
|
||||
|
||||
@@ -972,9 +966,7 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
}
|
||||
|
||||
for (final LoanCharge loanCharge : loanCharges) {
|
||||
boolean isDue = isFirstNormalInstallment
|
||||
? loanCharge.isDueForCollectionFromIncludingAndUpToAndIncluding(installment.getFromDate(), chargesTillDate)
|
||||
: loanCharge.isDueForCollectionFromAndUpToAndIncluding(installment.getFromDate(), chargesTillDate);
|
||||
boolean isDue = loanCharge.isDueInPeriod(installment.getFromDate(), chargesTillDate, isFirstNormalInstallment);
|
||||
if (isDue) {
|
||||
if (loanCharge.isFeeCharge()) {
|
||||
dueDateFeeIncome = dueDateFeeIncome.add(loanCharge.amount());
|
||||
@@ -1010,9 +1002,7 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
loan.addLoanTransaction(accrualTransaction);
|
||||
Set<LoanChargePaidBy> accrualCharges = accrualTransaction.getLoanChargesPaid();
|
||||
for (LoanCharge loanCharge : loan.getActiveCharges()) {
|
||||
boolean isDue = DateUtils.isEqual(fromDate, loan.getDisbursementDate())
|
||||
? loanCharge.isDueForCollectionFromIncludingAndUpToAndIncluding(fromDate, foreClosureDate)
|
||||
: loanCharge.isDueForCollectionFromAndUpToAndIncluding(fromDate, foreClosureDate);
|
||||
boolean isDue = loanCharge.isDueInPeriod(fromDate, foreClosureDate, DateUtils.isEqual(fromDate, loan.getDisbursementDate()));
|
||||
if (loanCharge.isActive() && !loanCharge.isPaid() && (isDue || loanCharge.isInstalmentFee())) {
|
||||
final LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(accrualTransaction, loanCharge,
|
||||
loanCharge.getAmountOutstanding(currency).getAmount(), null);
|
||||
@@ -1177,9 +1167,7 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
List<LoanCharge> loanCharges = new ArrayList<>();
|
||||
List<LoanInstallmentCharge> loanInstallmentCharges = new ArrayList<>();
|
||||
for (LoanCharge loanCharge : loan.getActiveCharges()) {
|
||||
boolean isDue = DateUtils.isEqual(fromDate, loan.getDisbursementDate())
|
||||
? loanCharge.isDueForCollectionFromIncludingAndUpToAndIncluding(fromDate, toDate)
|
||||
: loanCharge.isDueForCollectionFromAndUpToAndIncluding(fromDate, toDate);
|
||||
boolean isDue = loanCharge.isDueInPeriod(fromDate, toDate, DateUtils.isEqual(fromDate, loan.getDisbursementDate()));
|
||||
if (isDue) {
|
||||
if (loanCharge.isPenaltyCharge() && !loanCharge.isInstalmentFee()) {
|
||||
penalties = penalties.add(loanCharge.amount());
|
||||
@@ -1339,7 +1327,6 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
}
|
||||
|
||||
private void determineReceivableIncomeDetailsForLoanClosure(Loan loan, Map<String, Object> incomeDetails) {
|
||||
|
||||
MonetaryCurrency currency = loan.getCurrency();
|
||||
Money interestPortion = Money.zero(currency);
|
||||
Money feePortion = Money.zero(currency);
|
||||
|
||||
+6
-2
@@ -405,12 +405,16 @@ public class LoanAssembler {
|
||||
.map(r -> new LoanPaymentAllocationRule(loanApplication, r.getTransactionType(), r.getAllocationTypes(),
|
||||
r.getFutureInstallmentAllocationRule()))
|
||||
.toList();
|
||||
loanApplication.setPaymentAllocationRules(loanPaymentAllocationRules);
|
||||
List<LoanPaymentAllocationRule> paymentAllocationRules = loanApplication.getPaymentAllocationRules();
|
||||
paymentAllocationRules.clear();
|
||||
paymentAllocationRules.addAll(loanPaymentAllocationRules);
|
||||
|
||||
if (loanProduct.getCreditAllocationRules() != null && !loanProduct.getCreditAllocationRules().isEmpty()) {
|
||||
List<LoanCreditAllocationRule> loanCreditAllocationRules = loanProduct.getCreditAllocationRules().stream()
|
||||
.map(r -> new LoanCreditAllocationRule(loanApplication, r.getTransactionType(), r.getAllocationTypes())).toList();
|
||||
loanApplication.setCreditAllocationRules(loanCreditAllocationRules);
|
||||
List<LoanCreditAllocationRule> creditAllocationRules = loanApplication.getCreditAllocationRules();
|
||||
creditAllocationRules.clear();
|
||||
creditAllocationRules.addAll(loanCreditAllocationRules);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -25,7 +25,6 @@ import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -1245,7 +1244,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService, Loa
|
||||
|
||||
Integer daysInPeriod = 0;
|
||||
if (fromDate != null) {
|
||||
daysInPeriod = Math.toIntExact(ChronoUnit.DAYS.between(fromDate, dueDate));
|
||||
daysInPeriod = DateUtils.getExactDifferenceInDays(fromDate, dueDate);
|
||||
loanTermInDays = loanTermInDays + daysInPeriod;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -1081,8 +1081,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
loan.addLoanTransaction(newInterestPaymentWaiverTransaction);
|
||||
}
|
||||
|
||||
final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = loan.getTransactionProcessorFactory()
|
||||
.determineProcessor(loan.getTransactionProcessingStrategyCode());
|
||||
final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = loan.getTransactionProcessor();
|
||||
|
||||
final LoanRepaymentScheduleInstallment currentInstallment = loan
|
||||
.fetchLoanRepaymentScheduleInstallmentByDueDate(newInterestPaymentWaiverTransaction.getTransactionDate());
|
||||
|
||||
+5
-5
@@ -57,23 +57,23 @@ public class GenerateAdhocClientScheduleTasklet implements Tasklet {
|
||||
switch (ReportRunFrequency.fromId(adhoc.getReportRunFrequency())) {
|
||||
case DAILY -> {
|
||||
next = start.plusDays(1);
|
||||
run = Math.toIntExact(ChronoUnit.DAYS.between(start, end)) >= 1;
|
||||
run = DateUtils.getExactDifferenceInDays(start, end) >= 1;
|
||||
}
|
||||
case WEEKLY -> {
|
||||
next = start.plusDays(7);
|
||||
run = Math.toIntExact(ChronoUnit.DAYS.between(start, end)) >= 7;
|
||||
run = DateUtils.getExactDifferenceInDays(start, end) >= 7;
|
||||
}
|
||||
case MONTHLY -> {
|
||||
next = start.plusMonths(1);
|
||||
run = Math.toIntExact(ChronoUnit.MONTHS.between(start, end)) >= 1;
|
||||
run = DateUtils.getExactDifference(start, end, ChronoUnit.MONTHS) >= 1;
|
||||
}
|
||||
case YEARLY -> {
|
||||
next = start.plusYears(1);
|
||||
run = Math.toIntExact(ChronoUnit.YEARS.between(start, end)) >= 1;
|
||||
run = DateUtils.getExactDifference(start, end, ChronoUnit.YEARS) >= 1;
|
||||
}
|
||||
case CUSTOM -> {
|
||||
next = start.plusDays((long) adhoc.getReportRunEvery());
|
||||
run = Math.toIntExact(ChronoUnit.DAYS.between(start, end)) >= adhoc.getReportRunEvery();
|
||||
run = DateUtils.getExactDifferenceInDays(start, end) >= adhoc.getReportRunEvery();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-13
@@ -25,7 +25,6 @@ import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -462,16 +461,16 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
|
||||
LocalDate currentDate = DateUtils.getBusinessLocalDate();
|
||||
if (isDormancyTrackingActive && statusEnum.equals(SavingsAccountStatusType.ACTIVE.getValue())) {
|
||||
if (subStatusEnum < SavingsAccountSubStatusEnum.ESCHEAT.getValue()) {
|
||||
daysToEscheat = Math
|
||||
.toIntExact(ChronoUnit.DAYS.between(currentDate, lastActiveTransactionDate.plusDays(numDaysToEscheat)));
|
||||
daysToEscheat = DateUtils.getExactDifferenceInDays(currentDate,
|
||||
lastActiveTransactionDate.plusDays(numDaysToEscheat));
|
||||
}
|
||||
if (subStatusEnum < SavingsAccountSubStatusEnum.DORMANT.getValue()) {
|
||||
daysToDormancy = Math.toIntExact(
|
||||
ChronoUnit.DAYS.between(currentDate, lastActiveTransactionDate.plusDays(numDaysToDormancy)));
|
||||
daysToDormancy = DateUtils.getExactDifferenceInDays(currentDate,
|
||||
lastActiveTransactionDate.plusDays(numDaysToDormancy));
|
||||
}
|
||||
if (subStatusEnum < SavingsAccountSubStatusEnum.INACTIVE.getValue()) {
|
||||
daysToInactive = Math.toIntExact(
|
||||
ChronoUnit.DAYS.between(currentDate, lastActiveTransactionDate.plusDays(numDaysToInactive)));
|
||||
daysToInactive = DateUtils.getExactDifferenceInDays(currentDate,
|
||||
lastActiveTransactionDate.plusDays(numDaysToInactive));
|
||||
}
|
||||
}
|
||||
final LocalDate approvedOnDate = JdbcSupport.getLocalDate(rs, "approvedOnDate");
|
||||
@@ -837,16 +836,13 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
|
||||
LocalDate currentDate = DateUtils.getBusinessLocalDate();
|
||||
if (isDormancyTrackingActive && statusEnum.equals(SavingsAccountStatusType.ACTIVE.getValue())) {
|
||||
if (subStatusEnum < SavingsAccountSubStatusEnum.ESCHEAT.getValue()) {
|
||||
daysToEscheat = Math
|
||||
.toIntExact(ChronoUnit.DAYS.between(currentDate, lastActiveTransactionDate.plusDays(numDaysToEscheat)));
|
||||
daysToEscheat = DateUtils.getExactDifferenceInDays(currentDate, lastActiveTransactionDate.plusDays(numDaysToEscheat));
|
||||
}
|
||||
if (subStatusEnum < SavingsAccountSubStatusEnum.DORMANT.getValue()) {
|
||||
daysToDormancy = Math
|
||||
.toIntExact(ChronoUnit.DAYS.between(currentDate, lastActiveTransactionDate.plusDays(numDaysToDormancy)));
|
||||
daysToDormancy = DateUtils.getExactDifferenceInDays(currentDate, lastActiveTransactionDate.plusDays(numDaysToDormancy));
|
||||
}
|
||||
if (subStatusEnum < SavingsAccountSubStatusEnum.INACTIVE.getValue()) {
|
||||
daysToInactive = Math
|
||||
.toIntExact(ChronoUnit.DAYS.between(currentDate, lastActiveTransactionDate.plusDays(numDaysToInactive)));
|
||||
daysToInactive = DateUtils.getExactDifferenceInDays(currentDate, lastActiveTransactionDate.plusDays(numDaysToInactive));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -20,7 +20,6 @@ package org.apache.fineract.portfolio.shareproducts.service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -102,13 +101,13 @@ public class ShareProductDividendAssembler {
|
||||
if (DateUtils.isBefore(shareStartDate, lastDividendPostDate)) {
|
||||
shareStartDate = lastDividendPostDate;
|
||||
}
|
||||
int numberOfPurchseDays = Math.toIntExact(ChronoUnit.DAYS.between(shareStartDate, postingDate));
|
||||
int numberOfPurchseDays = DateUtils.getExactDifferenceInDays(shareStartDate, postingDate);
|
||||
if (type.isPurchased() && numberOfPurchseDays < minimumActivePeriod) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lastDividendAppliedDate != null) {
|
||||
numberOfShareDaysPerAccount += Math.toIntExact(ChronoUnit.DAYS.between(lastDividendAppliedDate, shareStartDate))
|
||||
numberOfShareDaysPerAccount += DateUtils.getExactDifferenceInDays(lastDividendAppliedDate, shareStartDate)
|
||||
* numberOfShares;
|
||||
}
|
||||
lastDividendAppliedDate = shareStartDate;
|
||||
@@ -121,8 +120,7 @@ public class ShareProductDividendAssembler {
|
||||
}
|
||||
}
|
||||
if (lastDividendAppliedDate != null) {
|
||||
numberOfShareDaysPerAccount += Math.toIntExact(ChronoUnit.DAYS.between(lastDividendAppliedDate, postingDate))
|
||||
* numberOfShares;
|
||||
numberOfShareDaysPerAccount += DateUtils.getExactDifferenceInDays(lastDividendAppliedDate, postingDate) * numberOfShares;
|
||||
}
|
||||
numberOfShareDays += numberOfShareDaysPerAccount;
|
||||
numberOfSharesdaysPerAccount.put(accountData.getId(), numberOfShareDaysPerAccount);
|
||||
|
||||
Reference in New Issue
Block a user