FINERACT-659 Account Id issue while importing bulk loan transaction

This commit is contained in:
ShruthiRajaram
2018-11-07 16:04:58 +05:30
parent 99aa2b5bb2
commit 15cb800609
5 changed files with 40 additions and 23 deletions
@@ -18,8 +18,10 @@
*/ */
package org.apache.fineract.infrastructure.bulkimport.importhandler.loanrepayment; package org.apache.fineract.infrastructure.bulkimport.importhandler.loanrepayment;
import com.google.gson.GsonBuilder; import java.math.BigDecimal;
import com.google.gson.JsonObject; import java.util.ArrayList;
import java.util.List;
import org.apache.fineract.commands.domain.CommandWrapper; import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder; import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
@@ -29,28 +31,32 @@ import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler; import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils; import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer; import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.exception.*;
import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionData; import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionData;
import org.apache.poi.ss.usermodel.*; import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal; import com.google.gson.GsonBuilder;
import java.util.ArrayList; import com.google.gson.JsonObject;
import java.util.List;
@Service @Service
public class LoanRepaymentImportHandler implements ImportHandler { public class LoanRepaymentImportHandler implements ImportHandler {
private Workbook workbook; private Workbook workbook;
private List<LoanTransactionData> loanRepayments; private List<LoanTransactionData> loanRepayments;
private Integer loanAccountId; private Long loanAccountId;
private final LoanReadPlatformService loanReadPlatformService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired @Autowired
public LoanRepaymentImportHandler(final PortfolioCommandSourceWritePlatformService public LoanRepaymentImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) { commandsSourceWritePlatformService, final LoanReadPlatformService loanReadPlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.loanReadPlatformService = loanReadPlatformService;
} }
@Override @Override
@@ -75,7 +81,7 @@ public class LoanRepaymentImportHandler implements ImportHandler {
String loanaccountInfo=ImportHandlerUtils.readAsString(LoanRepaymentConstants.LOAN_ACCOUNT_NO_COL, row); String loanaccountInfo=ImportHandlerUtils.readAsString(LoanRepaymentConstants.LOAN_ACCOUNT_NO_COL, row);
if (loanaccountInfo!=null){ if (loanaccountInfo!=null){
String loanAccountAr[]=loanaccountInfo.split("-"); String loanAccountAr[]=loanaccountInfo.split("-");
loanAccountId=Integer.parseInt(loanAccountAr[0]); loanAccountId = this.loanReadPlatformService.retrieveLoanIdByAccountNumber(loanAccountAr[0]);
} }
BigDecimal repaymentAmount=null; BigDecimal repaymentAmount=null;
if (ImportHandlerUtils.readAsDouble(LoanRepaymentConstants.AMOUNT_COL, row)!=null) if (ImportHandlerUtils.readAsDouble(LoanRepaymentConstants.AMOUNT_COL, row)!=null)
@@ -107,10 +113,10 @@ public class LoanRepaymentImportHandler implements ImportHandler {
loanRepaymentJsonob.remove("manuallyReversed"); loanRepaymentJsonob.remove("manuallyReversed");
String payload=loanRepaymentJsonob.toString(); String payload=loanRepaymentJsonob.toString();
final CommandWrapper commandRequest = new CommandWrapperBuilder() // final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.loanRepaymentTransaction(loanRepayment.getAccountId().longValue()) // .loanRepaymentTransaction(loanRepayment.getAccountId()) //
.withJson(payload) // .withJson(payload) //
.build(); // .build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++; successCount++;
Cell statusCell = loanRepaymentSheet.getRow(loanRepayment.getRowIndex()).createCell(LoanRepaymentConstants.STATUS_COL); Cell statusCell = loanRepaymentSheet.getRow(loanRepayment.getRowIndex()).createCell(LoanRepaymentConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED); statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
@@ -213,7 +213,7 @@ public class LoanRepaymentWorkbookPopulator extends AbstractWorkbookPopulator {
row = loanRepaymentSheet.createRow(rowIndex++); row = loanRepaymentSheet.createRow(rowIndex++);
writeString(LoanRepaymentConstants.LOOKUP_CLIENT_NAME_COL, row, loan.getClientName() + "(" + loan.getClientId() + ")"); writeString(LoanRepaymentConstants.LOOKUP_CLIENT_NAME_COL, row, loan.getClientName() + "(" + loan.getClientId() + ")");
writeString(LoanRepaymentConstants.LOOKUP_CLIENT_EXTERNAL_ID,row, clientIdToClientExternalId.get(loan.getClientId())); writeString(LoanRepaymentConstants.LOOKUP_CLIENT_EXTERNAL_ID,row, clientIdToClientExternalId.get(loan.getClientId()));
writeString(LoanRepaymentConstants.LOOKUP_ACCOUNT_NO_COL, row, Long.parseLong(loan.getAccountNo())+"-"+loan.getStatusStringValue()); writeString(LoanRepaymentConstants.LOOKUP_ACCOUNT_NO_COL, row, loan.getAccountNo()+"-"+loan.getStatusStringValue());
writeString(LoanRepaymentConstants.LOOKUP_PRODUCT_COL, row, loan.getLoanProductName()); writeString(LoanRepaymentConstants.LOOKUP_PRODUCT_COL, row, loan.getLoanProductName());
writeDouble(LoanRepaymentConstants.LOOKUP_PRINCIPAL_COL, row, loan.getPrincipal().doubleValue()); writeDouble(LoanRepaymentConstants.LOOKUP_PRINCIPAL_COL, row, loan.getPrincipal().doubleValue());
if (loan.getDisbursementDate() != null) { if (loan.getDisbursementDate() != null) {
@@ -21,7 +21,6 @@ package org.apache.fineract.portfolio.loanaccount.data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Collection; import java.util.Collection;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.infrastructure.codes.data.CodeValueData;
import org.apache.fineract.organisation.monetary.data.CurrencyData; import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.portfolio.account.data.AccountTransferData; import org.apache.fineract.portfolio.account.data.AccountTransferData;
@@ -32,6 +31,7 @@ import org.joda.time.LocalDate;
/** /**
* Immutable data object representing a loan transaction. * Immutable data object representing a loan transaction.
*/ */
@SuppressWarnings("unused")
public class LoanTransactionData { public class LoanTransactionData {
private final Long id; private final Long id;
@@ -56,16 +56,14 @@ public class LoanTransactionData {
private final AccountTransferData transfer; private final AccountTransferData transfer;
private final BigDecimal fixedEmiAmount; private final BigDecimal fixedEmiAmount;
private final BigDecimal outstandingLoanBalance; private final BigDecimal outstandingLoanBalance;
@SuppressWarnings("unused")
private final LocalDate submittedOnDate; private final LocalDate submittedOnDate;
private final boolean manuallyReversed; private final boolean manuallyReversed;
@SuppressWarnings("unused")
private final LocalDate possibleNextRepaymentDate; private final LocalDate possibleNextRepaymentDate;
// templates // templates
final Collection<PaymentTypeData> paymentTypeOptions; final Collection<PaymentTypeData> paymentTypeOptions;
private Collection<CodeValueData> writeOffReasonOptions = null; private Collection<CodeValueData> writeOffReasonOptions = null;
//import fields //import fields
private transient Integer rowIndex; private transient Integer rowIndex;
@@ -79,7 +77,7 @@ public class LoanTransactionData {
private Integer routingCode; private Integer routingCode;
private Integer receiptNumber; private Integer receiptNumber;
private Integer bankNumber; private Integer bankNumber;
private transient Integer accountId; private transient Long accountId;
private transient String transactionType; private transient String transactionType;
public static LoanTransactionData importInstance(BigDecimal repaymentAmount,LocalDate lastRepaymentDate, public static LoanTransactionData importInstance(BigDecimal repaymentAmount,LocalDate lastRepaymentDate,
@@ -120,7 +118,7 @@ public class LoanTransactionData {
} }
public static LoanTransactionData importInstance(BigDecimal repaymentAmount,LocalDate repaymentDate, public static LoanTransactionData importInstance(BigDecimal repaymentAmount,LocalDate repaymentDate,
Long repaymentTypeId, String accountNumber,Integer checkNumber,Integer routingCode, Long repaymentTypeId, String accountNumber,Integer checkNumber,Integer routingCode,
Integer receiptNumber, Integer bankNumber,Integer loanAccountId,String transactionType, Integer receiptNumber, Integer bankNumber,Long loanAccountId,String transactionType,
Integer rowIndex,String locale, String dateFormat){ Integer rowIndex,String locale, String dateFormat){
return new LoanTransactionData(repaymentAmount, repaymentDate, repaymentTypeId, accountNumber, return new LoanTransactionData(repaymentAmount, repaymentDate, repaymentTypeId, accountNumber,
checkNumber, routingCode, receiptNumber, bankNumber, loanAccountId, "", checkNumber, routingCode, receiptNumber, bankNumber, loanAccountId, "",
@@ -129,7 +127,7 @@ public class LoanTransactionData {
private LoanTransactionData(BigDecimal transactionAmount,LocalDate transactionDate, Long paymentTypeId, private LoanTransactionData(BigDecimal transactionAmount,LocalDate transactionDate, Long paymentTypeId,
String accountNumber,Integer checkNumber,Integer routingCode,Integer receiptNumber, String accountNumber,Integer checkNumber,Integer routingCode,Integer receiptNumber,
Integer bankNumber,Integer accountId,String transactionType,Integer rowIndex,String locale, Integer bankNumber,Long accountId,String transactionType,Integer rowIndex,String locale,
String dateFormat) { String dateFormat) {
this.transactionAmount = transactionAmount; this.transactionAmount = transactionAmount;
this.transactionDate = transactionDate; this.transactionDate = transactionDate;
@@ -169,7 +167,7 @@ public class LoanTransactionData {
this.writeOffReasonOptions = null; this.writeOffReasonOptions = null;
} }
public Integer getAccountId() { public Long getAccountId() {
return accountId; return accountId;
} }
@@ -132,4 +132,6 @@ public interface LoanReadPlatformService {
LoanTransactionData retrieveLoanForeclosureTemplate(final Long loanId, final LocalDate transactionDate); LoanTransactionData retrieveLoanForeclosureTemplate(final Long loanId, final LocalDate transactionDate);
LoanAccountData retrieveLoanByLoanAccount(String loanAccountNumber); LoanAccountData retrieveLoanByLoanAccount(String loanAccountNumber);
Long retrieveLoanIdByAccountNumber(String loanAccountNumber);
} }
@@ -2198,4 +2198,15 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
} }
@Override
public Long retrieveLoanIdByAccountNumber(String loanAccountNumber) {
try {
return this.jdbcTemplate.queryForObject("select l.id from m_loan l where l.account_no = ?",
new Object[] { loanAccountNumber }, Long.class);
} catch (final EmptyResultDataAccessException e) {
return null;
}
}
} }