MIFOSX-57 Add possibility to modify loan application charges.
This commit is contained in:
@@ -183,7 +183,7 @@ public class LoansApiResource {
|
||||
"repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType",
|
||||
"submittedOnDate", "approvedOnDate", "expectedDisbursementDate", "actualDisbursementDate",
|
||||
"expectedFirstRepaymentOnDate", "interestChargedFromDate", "closedOnDate", "expectedMaturityDate",
|
||||
"status", "lifeCycleStatusDate", "loanOfficerName", "loanOfficerId")
|
||||
"status", "lifeCycleStatusDate", "loanOfficerName", "loanOfficerId", "charges")
|
||||
);
|
||||
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
@@ -244,8 +244,8 @@ public class LoansApiResource {
|
||||
if(template) {
|
||||
responseParameters.addAll(Arrays.asList("productOptions", "amortizationTypeOptions", "interestTypeOptions", "interestCalculationPeriodTypeOptions",
|
||||
"repaymentFrequencyTypeOptions", "interestRateFrequencyTypeOptions", "fundOptions", "transactionProcessingStrategyOptions", "chargeOptions",
|
||||
"loanOfficerOptions"));
|
||||
|
||||
"loanOfficerOptions", "chargeTemplate"));
|
||||
|
||||
productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup();
|
||||
loanTermFrequencyTypeOptions = dropdownReadPlatformService.retrieveLoanTermFrequencyTypeOptions();
|
||||
repaymentFrequencyTypeOptions = dropdownReadPlatformService.retrieveRepaymentFrequencyTypeOptions();
|
||||
@@ -262,7 +262,7 @@ public class LoansApiResource {
|
||||
chargeOptions.removeAll(charges);
|
||||
}
|
||||
allowedLoanOfficers = this.staffReadPlatformService.retrieveAllLoanOfficersByOffice(loanBasicDetails.getClientOfficeId());
|
||||
|
||||
chargeTemplate = this.chargeReadPlatformService.retrieveLoanChargeTemplate();
|
||||
}
|
||||
|
||||
final LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, convenienceDataRequired, summary, repaymentSchedule, loanRepayments, permissions, charges,
|
||||
|
||||
+4
@@ -267,6 +267,10 @@ public class LoanApplicationCommand {
|
||||
return this.modifiedParameters.contains("interestChargedFromDate");
|
||||
}
|
||||
|
||||
public boolean isChargesChanged() {
|
||||
return this.modifiedParameters.contains("charges");
|
||||
}
|
||||
|
||||
public Long getLoanOfficerId() {
|
||||
return loanOfficerId;
|
||||
}
|
||||
|
||||
+1
-1
@@ -504,7 +504,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
||||
|
||||
if (loanCharge.has("amount")){
|
||||
chargeModifiedParameters.add("amount");
|
||||
amount = loanCharge.get("amount").getAsBigDecimal();
|
||||
amount = convertFrom(loanCharge.get("amount").getAsString(), "amount", extractLocaleValue(requestMap));
|
||||
}
|
||||
if (loanCharge.has("chargeTimeType")){
|
||||
chargeModifiedParameters.add("chargeTimeType");
|
||||
|
||||
@@ -209,9 +209,9 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
|
||||
}
|
||||
|
||||
public void modifyLoanApplication(final LoanApplicationCommand command, final Client client, final LoanProduct loanProduct,
|
||||
final Fund fund, final LoanTransactionProcessingStrategy strategy, final LoanSchedule modifiedLoanSchedule,
|
||||
final Fund fund, final LoanTransactionProcessingStrategy strategy, final LoanSchedule modifiedLoanSchedule, final Set<LoanCharge> charges,
|
||||
final Staff loanOfficer) {
|
||||
|
||||
|
||||
if (command.isClientChanged()) {
|
||||
this.client = client;
|
||||
}
|
||||
@@ -263,7 +263,12 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
|
||||
this.interestChargedFromDate = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (command.isChargesChanged()) {
|
||||
this.charges.clear();
|
||||
this.charges.addAll(charges);
|
||||
}
|
||||
|
||||
this.loanRepaymentScheduleDetail.update(command.toLoanProductCommand());
|
||||
|
||||
// FIXME - rewrite over loan schedule by default for now but worth putting in check to see if required
|
||||
|
||||
@@ -107,7 +107,7 @@ public class LoanAssembler {
|
||||
Loan loan = Loan.createNew(fund,loanOfficer, loanTransactionProcessingStrategy, loanProduct, client, loanRepaymentScheduleDetail);
|
||||
loan.setExternalId(command.getExternalId());
|
||||
|
||||
final Set<LoanCharge> charges = this.assembleSetOfCharges(command, loan, loanProduct, currency.getCode());
|
||||
final Set<LoanCharge> charges = this.assembleSetOfCharges(command, loan, loanProduct);
|
||||
loan.setCharges(charges);
|
||||
|
||||
for (ScheduledLoanInstallment scheduledLoanInstallment : loanRepaymentSchedule) {
|
||||
@@ -194,11 +194,15 @@ public class LoanAssembler {
|
||||
return strategy;
|
||||
}
|
||||
|
||||
private Set<LoanCharge> assembleSetOfCharges(final LoanApplicationCommand command, final Loan loan,
|
||||
final LoanProduct product, final String currencyCode) {
|
||||
public Set<LoanCharge> assembleSetOfCharges(final LoanApplicationCommand command, final Loan loan,
|
||||
final LoanProduct product) {
|
||||
|
||||
Set<LoanCharge> charges = new HashSet<LoanCharge>();
|
||||
LoanChargeCommand[] loanChargesArray = command.getCharges();
|
||||
String loanCurrencyCode = loan.getCurrencyCode();
|
||||
if (loanCurrencyCode == null){
|
||||
loanCurrencyCode = product.getCurrency().getCode();
|
||||
}
|
||||
|
||||
if (!ObjectUtils.isEmpty(loanChargesArray)) {
|
||||
for (LoanChargeCommand loanChargeCommand : loanChargesArray) {
|
||||
@@ -210,7 +214,7 @@ public class LoanAssembler {
|
||||
if (!charge.isActive()){
|
||||
throw new ChargeIsNotActiveException(id);
|
||||
}
|
||||
if (!currencyCode.equals(charge.getCurrencyCode())){
|
||||
if (!loanCurrencyCode.equals(charge.getCurrencyCode())){
|
||||
String errorMessage = "Charge and Loan must have the same currency.";
|
||||
throw new InvalidCurrencyException("charge", "attach.to.loan", errorMessage);
|
||||
}
|
||||
|
||||
+6
-3
@@ -4,6 +4,7 @@ import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
@@ -31,6 +32,7 @@ import org.mifosng.platform.exceptions.NoAuthorizationException;
|
||||
import org.mifosng.platform.fund.domain.Fund;
|
||||
import org.mifosng.platform.loan.domain.DefaultLoanLifecycleStateMachine;
|
||||
import org.mifosng.platform.loan.domain.Loan;
|
||||
import org.mifosng.platform.loan.domain.LoanCharge;
|
||||
import org.mifosng.platform.loan.domain.LoanLifecycleStateMachine;
|
||||
import org.mifosng.platform.loan.domain.LoanProduct;
|
||||
import org.mifosng.platform.loan.domain.LoanProductRepository;
|
||||
@@ -143,10 +145,11 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
Fund fund = this.loanAssembler.findFundByIdIfProvided(command.getFundId());
|
||||
Staff loanOfficer = this.loanAssembler.findLoanOfficerByIdIfProvided(command.getLoanOfficerId());
|
||||
LoanTransactionProcessingStrategy strategy = this.loanAssembler.findStrategyByIdIfProvided(command.getTransactionProcessingStrategyId());
|
||||
|
||||
Set<LoanCharge> charges = this.loanAssembler.assembleSetOfCharges(command, loan, loanProduct) ;
|
||||
|
||||
LoanSchedule loanSchedule = this.calculationPlatformService.calculateLoanSchedule(command.toCalculateLoanScheduleCommand());
|
||||
loan.modifyLoanApplication(command, client, loanProduct, fund, strategy, loanSchedule, loanOfficer);
|
||||
|
||||
loan.modifyLoanApplication(command, client, loanProduct, fund, strategy, loanSchedule, charges, loanOfficer);
|
||||
|
||||
this.loanRepository.save(loan);
|
||||
|
||||
if (StringUtils.isNotBlank(command.getSubmittedOnNote())) {
|
||||
|
||||
Reference in New Issue
Block a user