add behaviour for checking if accounting enabled for loan product to loan and product rather than ask for data each time.

This commit is contained in:
Keith Woodlock
2013-01-16 16:41:17 +00:00
parent 5240d308b8
commit 11e4a38796
4 changed files with 27 additions and 21 deletions
@@ -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();
@@ -495,10 +495,6 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
return this.client;
}
public LoanProduct loanProduct() {
return this.loanProduct;
}
public LoanProductRelatedDetail repaymentScheduleDetail() {
return this.loanRepaymentScheduleDetail;
}
@@ -2003,5 +1999,12 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
public List<LoanTransaction> getLoanTransactions() {
return this.loanTransactions;
}
public boolean isAccountingEnabledOnLoanProduct() {
return this.loanProduct.isAccountingEnabled();
}
public Long productId() {
return this.loanProduct.getId();
}
}
@@ -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<String, Object> 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<Long> existingLoanTransactionIds = new HashSet<Long>();
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<LoanTransaction> newLoanTransactions = new ArrayList<LoanTransaction>();
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);
}
@@ -146,7 +146,7 @@ public class LoanProduct extends AbstractAuditableCustom<AppUser, Long> {
public void update(final Set<Charge> charges) {
this.charges = charges;
}
public Integer getAccountingType() {
return this.accountingType;
}
@@ -161,7 +161,7 @@ public class LoanProduct extends AbstractAuditableCustom<AppUser, Long> {
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<AppUser, Long> {
return chargeIds.toArray(new String[chargeIds.size()]);
}
public boolean isAccountingEnabled() {
return AccountingRuleType.NONE.getValue().equals(this.accountingType);
}
}