MIFOSX-57 Add possibility to modify loan application charges.

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