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 // shouldn't be before an accounting closure
GLClosure latestGLClosure = glClosureRepository.getLatestGLClosureByBranch(loan.getOfficeId()); GLClosure latestGLClosure = glClosureRepository.getLatestGLClosureByBranch(loan.getOfficeId());
Office office = loan.getClient().getOffice(); Office office = loan.getClient().getOffice();
Long loanProductId = loan.loanProduct().getId(); Long loanProductId = loan.productId();
// TODO: Check for accounting type // TODO: Check for accounting type
for (LoanTransaction loanTransaction : loanTransactions) { for (LoanTransaction loanTransaction : loanTransactions) {
Date entryDate = loanTransaction.getDateOf(); Date entryDate = loanTransaction.getDateOf();
@@ -495,10 +495,6 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
return this.client; return this.client;
} }
public LoanProduct loanProduct() {
return this.loanProduct;
}
public LoanProductRelatedDetail repaymentScheduleDetail() { public LoanProductRelatedDetail repaymentScheduleDetail() {
return this.loanRepaymentScheduleDetail; return this.loanRepaymentScheduleDetail;
} }
@@ -2004,4 +2000,11 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
return this.loanTransactions; 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.LoanChargeCommandFromApiJsonDeserializer;
import org.mifosplatform.portfolio.loanaccount.serialization.LoanStateTransitionCommandFromApiJsonDeserializer; import org.mifosplatform.portfolio.loanaccount.serialization.LoanStateTransitionCommandFromApiJsonDeserializer;
import org.mifosplatform.portfolio.loanaccount.serialization.LoanTransactionCommandFromApiJsonDeserializer; import org.mifosplatform.portfolio.loanaccount.serialization.LoanTransactionCommandFromApiJsonDeserializer;
import org.mifosplatform.portfolio.loanproduct.domain.AccountingRuleType;
import org.mifosplatform.portfolio.loanproduct.exception.InvalidCurrencyException; import org.mifosplatform.portfolio.loanproduct.exception.InvalidCurrencyException;
import org.mifosplatform.useradministration.domain.AppUser; import org.mifosplatform.useradministration.domain.AppUser;
import org.springframework.beans.factory.annotation.Autowired; 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 ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(loan.getPrincpal().getCurrencyCode());
final Map<String, Object> changes = loan.disburse(command, defaultLoanLifecycleStateMachine(), currency); 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>(); Set<Long> existingLoanTransactionIds = new HashSet<Long>();
for(LoanTransaction loanTransaction:loan.getLoanTransactions()){ for (LoanTransaction loanTransaction : loan.getLoanTransactions()) {
if(loanTransaction.getId()==null){ if (loanTransaction.getId() == null) {
existingLoanTransactionIds.add(loanTransaction.getId()); existingLoanTransactionIds.add(loanTransaction.getId());
} }
} }
@@ -136,14 +135,14 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
} }
// make a call to accounting // 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 * Variable holds list of all newly created loan transactions during
* disbursal * this disbursal
**/ **/
List<LoanTransaction> newLoanTransactions = new ArrayList<LoanTransaction>(); List<LoanTransaction> newLoanTransactions = new ArrayList<LoanTransaction>();
for(LoanTransaction loanTransaction:loan.getLoanTransactions()){ for (LoanTransaction loanTransaction : loan.getLoanTransactions()) {
if(!existingLoanTransactionIds.contains(loanTransaction.getId())){ if (!existingLoanTransactionIds.contains(loanTransaction.getId())) {
newLoanTransactions.add(loanTransaction); newLoanTransactions.add(loanTransaction);
} }
} }
@@ -226,7 +225,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
changes.put("dateFormat", command.dateFormat()); changes.put("dateFormat", command.dateFormat());
// make a call to accounting // make a call to accounting
if (loan.loanProduct().getAccountingType() != AccountingRuleType.NONE.getValue()) { if (loan.isAccountingEnabledOnLoanProduct()) {
journalEntryWritePlatformService.createJournalEntriesForLoan(loan, loanRepayment); journalEntryWritePlatformService.createJournalEntriesForLoan(loan, loanRepayment);
} }
@@ -216,4 +216,8 @@ public class LoanProduct extends AbstractAuditableCustom<AppUser, Long> {
return chargeIds.toArray(new String[chargeIds.size()]); return chargeIds.toArray(new String[chargeIds.size()]);
} }
public boolean isAccountingEnabled() {
return AccountingRuleType.NONE.getValue().equals(this.accountingType);
}
} }