From 0b55ef9149566aca23d6fc2005286dafb351a672 Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Sat, 20 Oct 2012 14:11:55 +0100 Subject: [PATCH] update tomcat plugin, handle change of disbursement date when modifying loan application for now. --- mifosng-provider/build.gradle | 2 +- .../mifosng/platform/loan/domain/Loan.java | 24 +++++++++++++++---- ...WritePlatformServiceJpaRepositoryImpl.java | 4 ++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/mifosng-provider/build.gradle b/mifosng-provider/build.gradle index 8c889bf0e..2780602fb 100644 --- a/mifosng-provider/build.gradle +++ b/mifosng-provider/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath 'bmuschko:gradle-tomcat-plugin:0.9.3' + classpath 'bmuschko:gradle-tomcat-plugin:0.9.5' } } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/domain/Loan.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/domain/Loan.java index d82751f25..15885c146 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/domain/Loan.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/domain/Loan.java @@ -274,7 +274,8 @@ public class Loan extends AbstractAuditableCustom { public void modifyLoanApplication(final LoanApplicationCommand command, final Client client, final LoanProduct loanProduct, final Fund fund, final LoanTransactionProcessingStrategy strategy, final LoanScheduleData modifiedLoanSchedule, final Set charges, - final Staff loanOfficer) { + final Staff loanOfficer, + final LoanLifecycleStateMachine loanLifecycleStateMachine) { if (command.isClientChanged()) { this.client = client; @@ -307,6 +308,8 @@ public class Loan extends AbstractAuditableCustom { if (command.isExpectedDisbursementDateChanged()) { if (command.getExpectedDisbursementDate() != null) { this.expectedDisbursedOnDate = command.getExpectedDisbursementDate().toDate(); + removeFirstDisbursementTransaction(); + disburse(command.getExpectedDisbursementDate(), loanLifecycleStateMachine, false); } else { this.expectedDisbursedOnDate = null; } @@ -358,6 +361,15 @@ public class Loan extends AbstractAuditableCustom { loanRepaymentScheduleTransactionProcessor.handleTransaction(repaymentsOrWaivers, getCurrency(), this.repaymentScheduleInstallments); } + private void removeFirstDisbursementTransaction() { + for (LoanTransaction loanTransaction : loanTransactions) { + if (loanTransaction.isDisbursement()) { + loanTransactions.remove(loanTransaction); + break; + } + } + } + public void submitApplication( final Integer loanTermFrequency, final PeriodFrequencyType loanTermFrequencyType, @@ -502,13 +514,15 @@ public class Loan extends AbstractAuditableCustom { modifiedInstallment.updateLoan(this); this.repaymentScheduleInstallments.add(modifiedInstallment); } - disburse(disbursedOn, loanLifecycleStateMachine); + disburse(disbursedOn, loanLifecycleStateMachine, true); } - public void disburse(final LocalDate disbursedOn, final LoanLifecycleStateMachine loanLifecycleStateMachine) { + public void disburse(final LocalDate disbursedOn, final LoanLifecycleStateMachine loanLifecycleStateMachine, final boolean statusTransition) { - LoanStatus statusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_DISBURSED, LoanStatus.fromInt(this.loanStatus)); - this.loanStatus = statusEnum.getValue(); + if (statusTransition) { + LoanStatus statusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_DISBURSED, LoanStatus.fromInt(this.loanStatus)); + this.loanStatus = statusEnum.getValue(); + } this.disbursedOnDate = disbursedOn.toDateTimeAtCurrentTime().toDate(); this.expectedMaturityDate = this.repaymentScheduleInstallments diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformServiceJpaRepositoryImpl.java index 005bd462c..2898ab7a4 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -163,7 +163,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf final Set charges = this.loanChargeAssembler.assembleFrom(command.getCharges(), loanProduct.getCharges(), loan.getPrincpal().getAmount()); final LoanScheduleData loanSchedule = this.calculationPlatformService.calculateLoanScheduleNew(command.toCalculateLoanScheduleCommand()); - loan.modifyLoanApplication(command, client, loanProduct, fund, strategy, loanSchedule, charges, loanOfficer); + loan.modifyLoanApplication(command, client, loanProduct, fund, strategy, loanSchedule, charges, loanOfficer, defaultLoanLifecycleStateMachine()); this.loanRepository.save(loan); @@ -391,7 +391,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf } loan.disburseWithModifiedRepaymentSchedule(actualDisbursementDate, modifiedLoanRepaymentSchedule, defaultLoanLifecycleStateMachine()); } else { - loan.disburse(actualDisbursementDate, defaultLoanLifecycleStateMachine()); + loan.disburse(actualDisbursementDate, defaultLoanLifecycleStateMachine(), true); } this.loanRepository.save(loan);