fix for MIFOSX-884
This commit is contained in:
+69
-72
@@ -295,7 +295,6 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
@Column(name = "max_outstanding_loan_balance", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal maxOutstandingLoanBalance;
|
||||
|
||||
|
||||
@LazyCollection(LazyCollectionOption.FALSE)
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "loan", orphanRemoval = true)
|
||||
private Set<LoanDisbursementDetails> disbursementDetails = new HashSet<LoanDisbursementDetails>();
|
||||
@@ -305,7 +304,6 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "loan", orphanRemoval = true)
|
||||
private final Set<LoanTermVariations> loanTermVariations = new HashSet<LoanTermVariations>();
|
||||
|
||||
|
||||
public static Loan newIndividualLoanApplication(final String accountNo, final Client client, final Integer loanType,
|
||||
final LoanProduct loanProduct, final Fund fund, final Staff officer, final CodeValue loanPurpose,
|
||||
final LoanTransactionProcessingStrategy transactionProcessingStrategy,
|
||||
@@ -473,8 +471,6 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
|
||||
validateChargeHasValidSpecifiedDateIfApplicable(loanCharge, getDisbursementDate(), getLastRepaymentPeriodDueDate());
|
||||
|
||||
|
||||
|
||||
loanCharge.update(this);
|
||||
|
||||
final BigDecimal amount = calculateAmountPercentageAppliedTo(loanCharge);
|
||||
@@ -907,8 +903,11 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
|
||||
public void updateLoanCharges(final Set<LoanCharge> loanCharges) {
|
||||
List<Long> existingCharges = fetchAllLoanChargeIds();
|
||||
|
||||
/** Process new and updated charges **/
|
||||
for (final LoanCharge loanCharge : loanCharges) {
|
||||
LoanCharge charge = loanCharge;
|
||||
// add new charges
|
||||
if (loanCharge.getId() == null) {
|
||||
loanCharge.update(this);
|
||||
this.charges.add(loanCharge);
|
||||
@@ -933,6 +932,8 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
charge.update(chargeAmt, loanCharge.getDueLocalDate(), amount, repaymentScheduleDetail().getNumberOfRepayments(),
|
||||
totalChargeAmt);
|
||||
}
|
||||
|
||||
/** Updated deleted charges **/
|
||||
for (Long id : existingCharges) {
|
||||
fetchLoanChargesById(id).setActive(false);
|
||||
}
|
||||
@@ -1245,8 +1246,10 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
if (command.isChangeInBigDecimalParameterNamed(LoanApiConstants.emiAmountParameterName, this.fixedEmiAmount)) {
|
||||
this.fixedEmiAmount = command.bigDecimalValueOfParameterNamed(LoanApiConstants.emiAmountParameterName);
|
||||
}
|
||||
if (command.isChangeInBigDecimalParameterNamed(LoanApiConstants.maxOutstandingBalanceParameterName, this.maxOutstandingLoanBalance)) {
|
||||
this.maxOutstandingLoanBalance = command.bigDecimalValueOfParameterNamed(LoanApiConstants.maxOutstandingBalanceParameterName);
|
||||
if (command.isChangeInBigDecimalParameterNamed(LoanApiConstants.maxOutstandingBalanceParameterName,
|
||||
this.maxOutstandingLoanBalance)) {
|
||||
this.maxOutstandingLoanBalance = command
|
||||
.bigDecimalValueOfParameterNamed(LoanApiConstants.maxOutstandingBalanceParameterName);
|
||||
}
|
||||
if (this.disbursementDetails.isEmpty()) {
|
||||
final String errorMessage = "For this loan product, disbursement details must be provided";
|
||||
@@ -1265,7 +1268,6 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
return actualChanges;
|
||||
}
|
||||
|
||||
|
||||
private void updateDisbursementDetails(final JsonCommand command, final Map<String, Object> actualChanges) {
|
||||
|
||||
List<Long> list = fetchDisbursementIds();
|
||||
@@ -1415,7 +1417,6 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
|
||||
updateLoanSchedule(loanSchedule);
|
||||
|
||||
|
||||
LoanStatus from = null;
|
||||
if (this.loanStatus != null) {
|
||||
from = LoanStatus.fromInt(this.loanStatus);
|
||||
@@ -1685,9 +1686,9 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
return ids;
|
||||
}
|
||||
|
||||
public void disburse(final LoanScheduleGeneratorFactory loanScheduleFactory, final AppUser currentUser,
|
||||
final JsonCommand command, final ApplicationCurrency currency, final List<Long> existingTransactionIds,
|
||||
final List<Long> existingReversedTransactionIds, final Map<String, Object> actualChanges, final PaymentDetail paymentDetail,
|
||||
public void disburse(final LoanScheduleGeneratorFactory loanScheduleFactory, final AppUser currentUser, final JsonCommand command,
|
||||
final ApplicationCurrency currency, final List<Long> existingTransactionIds, final List<Long> existingReversedTransactionIds,
|
||||
final Map<String, Object> actualChanges, final PaymentDetail paymentDetail,
|
||||
final LocalDate calculatedRepaymentsStartingFromDate, final boolean isHolidayEnabled, final List<Holiday> holidays,
|
||||
final WorkingDays workingDays, final boolean allowTransactionsOnHoliday, final boolean allowTransactionsOnNonWorkingDay) {
|
||||
|
||||
@@ -1706,7 +1707,8 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
}
|
||||
if (actualDisbursementDate.toDate().before(lastDusburseDate)) {
|
||||
final String errorMsg = "Loan can't be disbursed before " + lastDusburseDate;
|
||||
throw new LoanDisbursalException(errorMsg, "actualdisbursementdate.before.lastdusbursedate", lastDusburseDate,actualDisbursementDate.toDate());
|
||||
throw new LoanDisbursalException(errorMsg, "actualdisbursementdate.before.lastdusbursedate", lastDusburseDate,
|
||||
actualDisbursementDate.toDate());
|
||||
}
|
||||
isMultiTrancheDisburse = true;
|
||||
}
|
||||
@@ -1718,7 +1720,6 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
this.loanStatus = statusEnum.getValue();
|
||||
actualChanges.put("status", LoanEnumerations.status(this.loanStatus));
|
||||
|
||||
|
||||
final String txnExternalId = command.stringValueOfParameterNamedAllowingNull("externalId");
|
||||
Money disburseAmount = this.loanRepaymentScheduleDetail.getPrincipal().zero();
|
||||
BigDecimal principalDisbursed = command.bigDecimalValueOfParameterNamed(LoanApiConstants.principalDisbursedParameterName);
|
||||
@@ -1770,11 +1771,13 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
BigDecimal emiAmount = command.bigDecimalValueOfParameterNamed(LoanApiConstants.emiAmountParameterName);
|
||||
boolean isEmiAmountChanged = false;
|
||||
if (this.loanProduct.isMultiDisburseLoan() && emiAmount != null && emiAmount.compareTo(retriveLastEmiAmount()) != 0) {
|
||||
LoanTermVariations loanVariationTerms = new LoanTermVariations(LoanTermVariationType.EMI_AMOUNT.getValue(),actualDisbursementDate.toDate(),emiAmount,this);
|
||||
LoanTermVariations loanVariationTerms = new LoanTermVariations(LoanTermVariationType.EMI_AMOUNT.getValue(),
|
||||
actualDisbursementDate.toDate(), emiAmount, this);
|
||||
this.loanTermVariations.add(loanVariationTerms);
|
||||
isEmiAmountChanged = true;
|
||||
}
|
||||
if (isRepaymentScheduleRegenerationRequiredForDisbursement(actualDisbursementDate) || diff.compareTo(BigDecimal.ZERO) !=0 || isEmiAmountChanged) {
|
||||
if (isRepaymentScheduleRegenerationRequiredForDisbursement(actualDisbursementDate) || diff.compareTo(BigDecimal.ZERO) != 0
|
||||
|| isEmiAmountChanged) {
|
||||
regenerateRepaymentSchedule(loanScheduleFactory, currency, calculatedRepaymentsStartingFromDate, isHolidayEnabled,
|
||||
holidays, workingDays);
|
||||
updateLoanRepaymentPeriodsDerivedFields(actualDisbursementDate);
|
||||
@@ -1788,7 +1791,8 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
actualDisbursementDate);
|
||||
this.loanTransactions.add(interestAppliedTransaction);
|
||||
|
||||
// changedTransactionDetail = reprocessTransactionForDisbursement(changedTransactionDetail);
|
||||
// changedTransactionDetail =
|
||||
// reprocessTransactionForDisbursement(changedTransactionDetail);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1817,7 +1821,6 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
updateLoanSummaryDerivedFields();
|
||||
}
|
||||
|
||||
|
||||
return changedTransactionDetail;
|
||||
}
|
||||
|
||||
@@ -1845,8 +1848,7 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
if (date != null) {
|
||||
for (LoanDisbursementDetails disbursementDetail : this.disbursementDetails) {
|
||||
if (disbursementDetail.actualDisbursementDate() != null) {
|
||||
if(disbursementDetail.actualDisbursementDate().after(date) ||
|
||||
disbursementDetail.actualDisbursementDate().equals(date)){
|
||||
if (disbursementDetail.actualDisbursementDate().after(date) || disbursementDetail.actualDisbursementDate().equals(date)) {
|
||||
date = disbursementDetail.actualDisbursementDate();
|
||||
details = disbursementDetail;
|
||||
}
|
||||
@@ -1935,15 +1937,16 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
}
|
||||
}
|
||||
if (isDefaultEmiAmountReq) {
|
||||
LoanTermVariationsData data = new LoanTermVariationsData(null, LoanEnumerations.loanvariationType(LoanTermVariationType.EMI_AMOUNT), this.getDisbursementDate(), this.fixedEmiAmount);
|
||||
LoanTermVariationsData data = new LoanTermVariationsData(null,
|
||||
LoanEnumerations.loanvariationType(LoanTermVariationType.EMI_AMOUNT), this.getDisbursementDate(), this.fixedEmiAmount);
|
||||
loanVariationTermsData.add(data);
|
||||
}
|
||||
|
||||
final LoanApplicationTerms loanApplicationTerms = LoanApplicationTerms
|
||||
.assembleFrom(applicationCurrency, loanTermFrequency, loanTermPeriodFrequencyType, getDisbursementDate(),
|
||||
getExpectedFirstRepaymentOnDate(), calculatedRepaymentsStartingFromDate, getInArrearsTolerance(),
|
||||
this.loanRepaymentScheduleDetail, this.loanProduct.isMultiDisburseLoan(), this.fixedEmiAmount, disbursementData,
|
||||
this.maxOutstandingLoanBalance,loanVariationTermsData);
|
||||
final LoanApplicationTerms loanApplicationTerms = LoanApplicationTerms.assembleFrom(applicationCurrency, loanTermFrequency,
|
||||
loanTermPeriodFrequencyType, getDisbursementDate(), getExpectedFirstRepaymentOnDate(),
|
||||
calculatedRepaymentsStartingFromDate, getInArrearsTolerance(), this.loanRepaymentScheduleDetail,
|
||||
this.loanProduct.isMultiDisburseLoan(), this.fixedEmiAmount, disbursementData, this.maxOutstandingLoanBalance,
|
||||
loanVariationTermsData);
|
||||
|
||||
final LoanScheduleModel loanSchedule = loanScheduleGenerator.generate(mc, applicationCurrency, loanApplicationTerms, charges(),
|
||||
isHolidayEnabled, holidays, workingDays);
|
||||
@@ -1954,8 +1957,8 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
private LoanTransaction handleDisbursementTransaction(final PaymentDetail paymentDetail, final LocalDate disbursedOn,
|
||||
final String txnExternalId, Money disburseAmt) {
|
||||
// track disbursement transaction
|
||||
final LoanTransaction disbursementTransaction = LoanTransaction.disbursement(getOffice(),
|
||||
disburseAmt, paymentDetail, disbursedOn, txnExternalId);
|
||||
final LoanTransaction disbursementTransaction = LoanTransaction.disbursement(getOffice(), disburseAmt, paymentDetail, disbursedOn,
|
||||
txnExternalId);
|
||||
disbursementTransaction.updateLoan(this);
|
||||
this.loanTransactions.add(disbursementTransaction);
|
||||
|
||||
@@ -1978,7 +1981,8 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
null);
|
||||
for (final LoanCharge charge : charges()) {
|
||||
if (charge.isDueAtDisbursement()) {
|
||||
if (totalFeeChargesDueAtDisbursement.isGreaterThanZero() && !charge.getChargePaymentMode().isPaymentModeAccountTransfer()) {
|
||||
if (totalFeeChargesDueAtDisbursement.isGreaterThanZero()
|
||||
&& !charge.getChargePaymentMode().isPaymentModeAccountTransfer()) {
|
||||
charge.markAsFullyPaid();
|
||||
// Add "Loan Charge Paid By" details to this transaction
|
||||
final LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(chargesPayment, charge, charge.amount());
|
||||
@@ -2004,14 +2008,13 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
getApprovedOnDate());
|
||||
}
|
||||
|
||||
if(getExpectedFirstRepaymentOnDate() != null && disbursedOn.isAfter(getExpectedFirstRepaymentOnDate()))
|
||||
{
|
||||
final String errorMessage = "submittedOnDate cannot be after the loans expectedFirstRepaymentOnDate: " + getExpectedFirstRepaymentOnDate().toString();
|
||||
throw new InvalidLoanStateTransitionException("disbursal", "cannot.be.after.expected.first.repayment.date", errorMessage, disbursedOn,
|
||||
getExpectedFirstRepaymentOnDate());
|
||||
if (getExpectedFirstRepaymentOnDate() != null && disbursedOn.isAfter(getExpectedFirstRepaymentOnDate())) {
|
||||
final String errorMessage = "submittedOnDate cannot be after the loans expectedFirstRepaymentOnDate: "
|
||||
+ getExpectedFirstRepaymentOnDate().toString();
|
||||
throw new InvalidLoanStateTransitionException("disbursal", "cannot.be.after.expected.first.repayment.date", errorMessage,
|
||||
disbursedOn, getExpectedFirstRepaymentOnDate());
|
||||
}
|
||||
|
||||
|
||||
validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_DISBURSED, disbursedOn);
|
||||
|
||||
if (disbursedOn.isAfter(new LocalDate())) {
|
||||
@@ -2324,8 +2327,7 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
|
||||
boolean isAllChargesPaid = true;
|
||||
for (final LoanCharge loanCharge : this.charges) {
|
||||
if (loanCharge.isActive()
|
||||
&& !(loanCharge.isPaid() || loanCharge.isWaived())) {
|
||||
if (loanCharge.isActive() && !(loanCharge.isPaid() || loanCharge.isWaived())) {
|
||||
isAllChargesPaid = false;
|
||||
break;
|
||||
}
|
||||
@@ -2583,11 +2585,10 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
final LocalDate calculatedRepaymentsStartingFromDate, final boolean isHolidayEnabled, final List<Holiday> holidays,
|
||||
final WorkingDays workingDays) {
|
||||
|
||||
|
||||
final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.transactionProcessorFactory
|
||||
.determineProcessor(this.transactionProcessingStrategy);
|
||||
ChangedTransactionDetail changedTransactionDetail = closeDisbursements(loanScheduleFactory, currency, calculatedRepaymentsStartingFromDate, isHolidayEnabled, holidays,
|
||||
workingDays, loanRepaymentScheduleTransactionProcessor);
|
||||
ChangedTransactionDetail changedTransactionDetail = closeDisbursements(loanScheduleFactory, currency,
|
||||
calculatedRepaymentsStartingFromDate, isHolidayEnabled, holidays, workingDays, loanRepaymentScheduleTransactionProcessor);
|
||||
|
||||
validateAccountStatus(LoanEvent.WRITE_OFF_OUTSTANDING);
|
||||
|
||||
@@ -2646,15 +2647,16 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
return changedTransactionDetail;
|
||||
}
|
||||
|
||||
private ChangedTransactionDetail closeDisbursements(final LoanScheduleGeneratorFactory loanScheduleFactory, final ApplicationCurrency currency,
|
||||
final LocalDate calculatedRepaymentsStartingFromDate, final boolean isHolidayEnabled, final List<Holiday> holidays,
|
||||
final WorkingDays workingDays, final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor) {
|
||||
private ChangedTransactionDetail closeDisbursements(final LoanScheduleGeneratorFactory loanScheduleFactory,
|
||||
final ApplicationCurrency currency, final LocalDate calculatedRepaymentsStartingFromDate, final boolean isHolidayEnabled,
|
||||
final List<Holiday> holidays, final WorkingDays workingDays,
|
||||
final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor) {
|
||||
ChangedTransactionDetail changedTransactionDetail = null;
|
||||
if (isDisbursementAllowed() && atleastOnceDisbursed()) {
|
||||
this.loanRepaymentScheduleDetail.setPrincipal(getDisbursedAmount());
|
||||
removeDisbursementDetail();
|
||||
regenerateRepaymentSchedule(loanScheduleFactory, currency, calculatedRepaymentsStartingFromDate, isHolidayEnabled,
|
||||
holidays, workingDays);
|
||||
regenerateRepaymentSchedule(loanScheduleFactory, currency, calculatedRepaymentsStartingFromDate, isHolidayEnabled, holidays,
|
||||
workingDays);
|
||||
|
||||
final List<LoanTransaction> allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement();
|
||||
changedTransactionDetail = loanRepaymentScheduleTransactionProcessor.handleTransaction(getDisbursementDate(),
|
||||
@@ -2673,8 +2675,8 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
private LoanTransaction findlatestTransaction() {
|
||||
LoanTransaction transaction = null;
|
||||
for (LoanTransaction loanTransaction : this.loanTransactions) {
|
||||
if(!loanTransaction.isReversed() &&
|
||||
(transaction == null || transaction.getTransactionDate().isBefore(loanTransaction.getTransactionDate()))){
|
||||
if (!loanTransaction.isReversed()
|
||||
&& (transaction == null || transaction.getTransactionDate().isBefore(loanTransaction.getTransactionDate()))) {
|
||||
transaction = loanTransaction;
|
||||
}
|
||||
}
|
||||
@@ -2687,7 +2689,6 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
final LocalDate calculatedRepaymentsStartingFromDate, final boolean isHolidayEnabled, final List<Holiday> holidays,
|
||||
final WorkingDays workingDays) {
|
||||
|
||||
|
||||
validateAccountStatus(LoanEvent.LOAN_CLOSED);
|
||||
|
||||
existingTransactionIds.addAll(findExistingTransactionIds());
|
||||
@@ -2713,8 +2714,8 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
}
|
||||
final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.transactionProcessorFactory
|
||||
.determineProcessor(this.transactionProcessingStrategy);
|
||||
ChangedTransactionDetail changedTransactionDetail = closeDisbursements(loanScheduleFactory, currency, calculatedRepaymentsStartingFromDate, isHolidayEnabled, holidays,
|
||||
workingDays, loanRepaymentScheduleTransactionProcessor);
|
||||
ChangedTransactionDetail changedTransactionDetail = closeDisbursements(loanScheduleFactory, currency,
|
||||
calculatedRepaymentsStartingFromDate, isHolidayEnabled, holidays, workingDays, loanRepaymentScheduleTransactionProcessor);
|
||||
|
||||
LoanTransaction loanTransaction = null;
|
||||
if (isOpen()) {
|
||||
@@ -2868,8 +2869,7 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
|
||||
private boolean isAllTranchesNotDisbursed() {
|
||||
return this.loanProduct.isMultiDisburseLoan()
|
||||
&& (LoanStatus.fromInt(this.loanStatus).isActive()
|
||||
||LoanStatus.fromInt(this.loanStatus).isApproved())
|
||||
&& (LoanStatus.fromInt(this.loanStatus).isActive() || LoanStatus.fromInt(this.loanStatus).isApproved())
|
||||
&& isDisbursementAllowed();
|
||||
}
|
||||
|
||||
@@ -3399,8 +3399,6 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Group group() {
|
||||
return this.group;
|
||||
}
|
||||
@@ -3414,9 +3412,7 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
}
|
||||
|
||||
public Integer getLoanProductLoanCounter() {
|
||||
if(this.loanProductCounter == null){
|
||||
return 0;
|
||||
}
|
||||
if (this.loanProductCounter == null) { return 0; }
|
||||
return this.loanProductCounter;
|
||||
}
|
||||
|
||||
@@ -3585,8 +3581,8 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
}
|
||||
break;
|
||||
case LOAN_DISBURSED:
|
||||
if ((!(isApproved() && isNotDisbursed()) && !this.loanProduct.isMultiDisburseLoan()) ||
|
||||
(this.loanProduct.isMultiDisburseLoan() && !isAllTranchesNotDisbursed())) {
|
||||
if ((!(isApproved() && isNotDisbursed()) && !this.loanProduct.isMultiDisburseLoan())
|
||||
|| (this.loanProduct.isMultiDisburseLoan() && !isAllTranchesNotDisbursed())) {
|
||||
final String defaultUserMessage = "Loan Disbursal is not allowed. Loan Account is not in approved and not disbursed state.";
|
||||
final ApiParameterError error = ApiParameterError.generalError(
|
||||
"error.msg.loan.disbursal.account.is.not.approve.not.disbursed.state", defaultUserMessage);
|
||||
@@ -3698,26 +3694,29 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
return this.disbursementDetails;
|
||||
}
|
||||
|
||||
public ChangedTransactionDetail updateDisbursementDateForTranche(final LoanDisbursementDetails disbursementDetails,final JsonCommand command,final List<Long> existingTransactionIds,
|
||||
final List<Long> existingReversedTransactionIds, final Map<String, Object> actualChanges,
|
||||
final LoanScheduleGeneratorFactory loanScheduleFactory, final ApplicationCurrency currency,
|
||||
final LocalDate calculatedRepaymentsStartingFromDate, final boolean isHolidayEnabled, final List<Holiday> holidays,
|
||||
final WorkingDays workingDays){
|
||||
public ChangedTransactionDetail updateDisbursementDateForTranche(final LoanDisbursementDetails disbursementDetails,
|
||||
final JsonCommand command, final List<Long> existingTransactionIds, final List<Long> existingReversedTransactionIds,
|
||||
final Map<String, Object> actualChanges, final LoanScheduleGeneratorFactory loanScheduleFactory,
|
||||
final ApplicationCurrency currency, final LocalDate calculatedRepaymentsStartingFromDate, final boolean isHolidayEnabled,
|
||||
final List<Holiday> holidays, final WorkingDays workingDays) {
|
||||
validateAccountStatus(LoanEvent.LOAN_EDIT_MULTI_DISBURSE_DATE);
|
||||
final LocalDate expectedDisbursementDate = command.localDateValueOfParameterNamed(LoanApiConstants.disbursementDateParameterName);
|
||||
disbursementDetails.updateExpectedDisbursementDate(expectedDisbursementDate.toDate());
|
||||
actualChanges.put(LoanApiConstants.disbursementDateParameterName, command.stringValueOfParameterNamed(LoanApiConstants.disbursementDateParameterName));
|
||||
actualChanges.put(LoanApiConstants.disbursementIdParameterName, command.stringValueOfParameterNamed(LoanApiConstants.disbursementIdParameterName));
|
||||
actualChanges.put(LoanApiConstants.disbursementDateParameterName,
|
||||
command.stringValueOfParameterNamed(LoanApiConstants.disbursementDateParameterName));
|
||||
actualChanges.put(LoanApiConstants.disbursementIdParameterName,
|
||||
command.stringValueOfParameterNamed(LoanApiConstants.disbursementIdParameterName));
|
||||
existingTransactionIds.addAll(findExistingTransactionIds());
|
||||
existingReversedTransactionIds.addAll(findExistingReversedTransactionIds());
|
||||
regenerateRepaymentSchedule(loanScheduleFactory, currency, calculatedRepaymentsStartingFromDate, isHolidayEnabled,
|
||||
holidays, workingDays);
|
||||
regenerateRepaymentSchedule(loanScheduleFactory, currency, calculatedRepaymentsStartingFromDate, isHolidayEnabled, holidays,
|
||||
workingDays);
|
||||
|
||||
final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.transactionProcessorFactory
|
||||
.determineProcessor(this.transactionProcessingStrategy);
|
||||
final List<LoanTransaction> allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement();
|
||||
ChangedTransactionDetail changedTransactionDetail = loanRepaymentScheduleTransactionProcessor.handleTransaction(getDisbursementDate(),
|
||||
allNonContraTransactionsPostDisbursement, getCurrency(), this.repaymentScheduleInstallments, charges());
|
||||
ChangedTransactionDetail changedTransactionDetail = loanRepaymentScheduleTransactionProcessor.handleTransaction(
|
||||
getDisbursementDate(), allNonContraTransactionsPostDisbursement, getCurrency(), this.repaymentScheduleInstallments,
|
||||
charges());
|
||||
for (final Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail.getNewTransactionMappings().entrySet()) {
|
||||
mapEntry.getValue().updateLoan(this);
|
||||
this.loanTransactions.add(mapEntry.getValue());
|
||||
@@ -3726,13 +3725,11 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
return changedTransactionDetail;
|
||||
}
|
||||
|
||||
|
||||
public BigDecimal retriveLastEmiAmount() {
|
||||
BigDecimal emiAmount = this.fixedEmiAmount;
|
||||
Date startDate = this.getDisbursementDate().toDate();
|
||||
for (LoanTermVariations loanTermVariations : this.loanTermVariations) {
|
||||
if(loanTermVariations.getTermType().isEMIAmountVariation() &&
|
||||
!startDate.after(loanTermVariations.getTermApplicableFrom())){
|
||||
if (loanTermVariations.getTermType().isEMIAmountVariation() && !startDate.after(loanTermVariations.getTermApplicableFrom())) {
|
||||
startDate = loanTermVariations.getTermApplicableFrom();
|
||||
emiAmount = loanTermVariations.getTermValue();
|
||||
}
|
||||
|
||||
+27
-11
@@ -184,7 +184,8 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
if (clientId != null) {
|
||||
cycleNumber = this.loanReadPlatformService.retriveLoanCounter(clientId, loanProduct.getId());
|
||||
} else if (groupId != null) {
|
||||
cycleNumber = this.loanReadPlatformService.retriveLoanCounter(groupId, AccountType.GROUP.getValue(), loanProduct.getId());
|
||||
cycleNumber = this.loanReadPlatformService.retriveLoanCounter(groupId, AccountType.GROUP.getValue(),
|
||||
loanProduct.getId());
|
||||
}
|
||||
this.loanProductCommandFromApiJsonDeserializer.validateMinMaxConstraints(command.parsedJson(), baseDataValidator,
|
||||
loanProduct, cycleNumber);
|
||||
@@ -277,15 +278,33 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
chargesMap.put(charge.getId(), chargeData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores all charges which are passed in during modify loan
|
||||
* application
|
||||
**/
|
||||
final Set<LoanCharge> possiblyModifedLoanCharges = this.loanChargeAssembler.fromParsedJson(command.parsedJson());
|
||||
/** Boolean determines if any charge has been modified **/
|
||||
boolean isChargeModified = false;
|
||||
|
||||
/**
|
||||
* If there are any charges already present, which are now not
|
||||
* passed in as a part of the request, deem the charges as modified
|
||||
**/
|
||||
if (!possiblyModifedLoanCharges.containsAll(existingCharges)) {
|
||||
isChargeModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If any new charges are added or values of existing charges are
|
||||
* modified
|
||||
**/
|
||||
for (LoanCharge loanCharge : possiblyModifedLoanCharges) {
|
||||
if (loanCharge.getId() == null) {
|
||||
isChargeModified = true;
|
||||
} else {
|
||||
LoanChargeData chargeData = chargesMap.get(loanCharge.getId());
|
||||
if(loanCharge.amountOrPercentage().compareTo(chargeData.amountOrPercentage()) != 0 ||
|
||||
(loanCharge.isSpecifiedDueDate() && !loanCharge.getDueLocalDate().equals(chargeData.getDueDate()))){
|
||||
if (loanCharge.amountOrPercentage().compareTo(chargeData.amountOrPercentage()) != 0
|
||||
|| (loanCharge.isSpecifiedDueDate() && !loanCharge.getDueLocalDate().equals(chargeData.getDueDate()))) {
|
||||
isChargeModified = true;
|
||||
}
|
||||
}
|
||||
@@ -338,7 +357,8 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
if (clientId != null) {
|
||||
cycleNumber = this.loanReadPlatformService.retriveLoanCounter(clientId, loanProduct.getId());
|
||||
} else if (groupId != null) {
|
||||
cycleNumber = this.loanReadPlatformService.retriveLoanCounter(groupId, AccountType.GROUP.getValue(), loanProduct.getId());
|
||||
cycleNumber = this.loanReadPlatformService.retriveLoanCounter(groupId, AccountType.GROUP.getValue(),
|
||||
loanProduct.getId());
|
||||
}
|
||||
this.loanProductCommandFromApiJsonDeserializer.validateMinMaxConstraints(command.parsedJson(), baseDataValidator,
|
||||
loanProduct, cycleNumber);
|
||||
@@ -728,17 +748,13 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
submittedOnDate.toString(), closeDate.toString());
|
||||
}
|
||||
|
||||
if(expectedFirstRepaymentOnDate != null && submittedOnDate.isAfter(expectedFirstRepaymentOnDate))
|
||||
{
|
||||
if (expectedFirstRepaymentOnDate != null && submittedOnDate.isAfter(expectedFirstRepaymentOnDate)) {
|
||||
defaultUserMessage = "submittedOnDate cannot be after the loans expectedFirstRepaymentOnDate.";
|
||||
throw new LoanApplicationDateException("submitted.on.date.cannot.be.after.the.loan.expected.first.repayment.date", defaultUserMessage,
|
||||
submittedOnDate.toString(), expectedFirstRepaymentOnDate.toString());
|
||||
throw new LoanApplicationDateException("submitted.on.date.cannot.be.after.the.loan.expected.first.repayment.date",
|
||||
defaultUserMessage, submittedOnDate.toString(), expectedFirstRepaymentOnDate.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void checkClientOrGroupActive(final Loan loan) {
|
||||
final Client client = loan.client();
|
||||
if (client != null) {
|
||||
|
||||
Reference in New Issue
Block a user