diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/service/impl/GLJournalEntryWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/service/impl/GLJournalEntryWritePlatformServiceJpaRepositoryImpl.java index 6748be773..28dc7b7a1 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/service/impl/GLJournalEntryWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/service/impl/GLJournalEntryWritePlatformServiceJpaRepositoryImpl.java @@ -130,7 +130,7 @@ public class GLJournalEntryWritePlatformServiceJpaRepositoryImpl implements GLJo // shouldn't be before an accounting closure GLClosure latestGLClosure = glClosureRepository.getLatestGLClosureByBranch(loan.getOfficeId()); Office office = loan.getClient().getOffice(); - Long loanProductId = loan.loanProduct().getId(); + Long loanProductId = loan.productId(); // TODO: Check for accounting type for (LoanTransaction loanTransaction : loanTransactions) { Date entryDate = loanTransaction.getDateOf(); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java index eecc9ca3b..e87c33e5d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java @@ -495,10 +495,6 @@ public class Loan extends AbstractAuditableCustom { return this.client; } - public LoanProduct loanProduct() { - return this.loanProduct; - } - public LoanProductRelatedDetail repaymentScheduleDetail() { return this.loanRepaymentScheduleDetail; } @@ -2003,5 +1999,12 @@ public class Loan extends AbstractAuditableCustom { public List getLoanTransactions() { return this.loanTransactions; } - + + public boolean isAccountingEnabledOnLoanProduct() { + return this.loanProduct.isAccountingEnabled(); + } + + public Long productId() { + return this.loanProduct.getId(); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index f709af563..e23706838 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -45,7 +45,6 @@ import org.mifosplatform.portfolio.loanaccount.exception.LoanTransactionNotFound import org.mifosplatform.portfolio.loanaccount.serialization.LoanChargeCommandFromApiJsonDeserializer; import org.mifosplatform.portfolio.loanaccount.serialization.LoanStateTransitionCommandFromApiJsonDeserializer; import org.mifosplatform.portfolio.loanaccount.serialization.LoanTransactionCommandFromApiJsonDeserializer; -import org.mifosplatform.portfolio.loanproduct.domain.AccountingRuleType; import org.mifosplatform.portfolio.loanproduct.exception.InvalidCurrencyException; import org.mifosplatform.useradministration.domain.AppUser; import org.springframework.beans.factory.annotation.Autowired; @@ -119,12 +118,12 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(loan.getPrincpal().getCurrencyCode()); - final Map changes = loan.disburse(command, defaultLoanLifecycleStateMachine(), currency); - //variable stores Id's of all existing loan transactions (newly created loan transactions would not have an Id before save) + // variable stores Id's of all existing loan transactions (newly created + // loan transactions would not have an Id before save) Set existingLoanTransactionIds = new HashSet(); - for(LoanTransaction loanTransaction:loan.getLoanTransactions()){ - if(loanTransaction.getId()==null){ + for (LoanTransaction loanTransaction : loan.getLoanTransactions()) { + if (loanTransaction.getId() == null) { existingLoanTransactionIds.add(loanTransaction.getId()); } } @@ -134,16 +133,16 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf Note note = Note.loanNote(loan, noteText); this.noteRepository.save(note); } - + // make a call to accounting - if (loan.loanProduct().getAccountingType() != AccountingRuleType.NONE.getValue()) { + if (loan.isAccountingEnabledOnLoanProduct()) { /*** - * Variable holds list of all newly created loan transactions during this - * disbursal + * Variable holds list of all newly created loan transactions during + * this disbursal **/ List newLoanTransactions = new ArrayList(); - for(LoanTransaction loanTransaction:loan.getLoanTransactions()){ - if(!existingLoanTransactionIds.contains(loanTransaction.getId())){ + for (LoanTransaction loanTransaction : loan.getLoanTransactions()) { + if (!existingLoanTransactionIds.contains(loanTransaction.getId())) { newLoanTransactions.add(loanTransaction); } } @@ -224,9 +223,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf changes.put("locale", command.locale()); changes.put("dateFormat", command.dateFormat()); - + // make a call to accounting - if (loan.loanProduct().getAccountingType() != AccountingRuleType.NONE.getValue()) { + if (loan.isAccountingEnabledOnLoanProduct()) { journalEntryWritePlatformService.createJournalEntriesForLoan(loan, loanRepayment); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/domain/LoanProduct.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/domain/LoanProduct.java index 9d97080e8..776e2872c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/domain/LoanProduct.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/domain/LoanProduct.java @@ -146,7 +146,7 @@ public class LoanProduct extends AbstractAuditableCustom { public void update(final Set charges) { this.charges = charges; } - + public Integer getAccountingType() { return this.accountingType; } @@ -161,7 +161,7 @@ public class LoanProduct extends AbstractAuditableCustom { actualChanges.put(accountingTypeParamName, newValue); this.accountingType = newValue; } - + final String nameParamName = "name"; if (command.isChangeInStringParameterNamed(nameParamName, this.name)) { final String newValue = command.stringValueOfParameterNamed(nameParamName); @@ -216,4 +216,8 @@ public class LoanProduct extends AbstractAuditableCustom { return chargeIds.toArray(new String[chargeIds.size()]); } + + public boolean isAccountingEnabled() { + return AccountingRuleType.NONE.getValue().equals(this.accountingType); + } } \ No newline at end of file