Merge pull request #489 from ShruthiRajaram/FINERACT-659

FINERACT-659 Account Id issue while importing loan transaction
This commit is contained in:
ShruthiRajaram
2018-11-12 14:57:58 +05:30
committed by GitHub
5 changed files with 40 additions and 23 deletions
@@ -18,8 +18,10 @@
*/
package org.apache.fineract.infrastructure.bulkimport.importhandler.loanrepayment;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
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.ImportHandlerUtils;
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.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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
@Service
public class LoanRepaymentImportHandler implements ImportHandler {
private Workbook workbook;
private List<LoanTransactionData> loanRepayments;
private Integer loanAccountId;
private Long loanAccountId;
private final LoanReadPlatformService loanReadPlatformService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public LoanRepaymentImportHandler(final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService) {
commandsSourceWritePlatformService, final LoanReadPlatformService loanReadPlatformService) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.loanReadPlatformService = loanReadPlatformService;
}
@Override
@@ -75,7 +81,7 @@ public class LoanRepaymentImportHandler implements ImportHandler {
String loanaccountInfo=ImportHandlerUtils.readAsString(LoanRepaymentConstants.LOAN_ACCOUNT_NO_COL, row);
if (loanaccountInfo!=null){
String loanAccountAr[]=loanaccountInfo.split("-");
loanAccountId=Integer.parseInt(loanAccountAr[0]);
loanAccountId = this.loanReadPlatformService.retrieveLoanIdByAccountNumber(loanAccountAr[0]);
}
BigDecimal repaymentAmount=null;
if (ImportHandlerUtils.readAsDouble(LoanRepaymentConstants.AMOUNT_COL, row)!=null)
@@ -107,10 +113,10 @@ public class LoanRepaymentImportHandler implements ImportHandler {
loanRepaymentJsonob.remove("manuallyReversed");
String payload=loanRepaymentJsonob.toString();
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.loanRepaymentTransaction(loanRepayment.getAccountId().longValue()) //
.loanRepaymentTransaction(loanRepayment.getAccountId()) //
.withJson(payload) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
commandsSourceWritePlatformService.logCommandSource(commandRequest);
successCount++;
Cell statusCell = loanRepaymentSheet.getRow(loanRepayment.getRowIndex()).createCell(LoanRepaymentConstants.STATUS_COL);
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
@@ -213,7 +213,7 @@ public class LoanRepaymentWorkbookPopulator extends AbstractWorkbookPopulator {
row = loanRepaymentSheet.createRow(rowIndex++);
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_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());
writeDouble(LoanRepaymentConstants.LOOKUP_PRINCIPAL_COL, row, loan.getPrincipal().doubleValue());
if (loan.getDisbursementDate() != null) {
@@ -21,7 +21,6 @@ package org.apache.fineract.portfolio.loanaccount.data;
import java.math.BigDecimal;
import java.util.Collection;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.infrastructure.codes.data.CodeValueData;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.portfolio.account.data.AccountTransferData;
@@ -32,6 +31,7 @@ import org.joda.time.LocalDate;
/**
* Immutable data object representing a loan transaction.
*/
@SuppressWarnings("unused")
public class LoanTransactionData {
private final Long id;
@@ -56,16 +56,14 @@ public class LoanTransactionData {
private final AccountTransferData transfer;
private final BigDecimal fixedEmiAmount;
private final BigDecimal outstandingLoanBalance;
@SuppressWarnings("unused")
private final LocalDate submittedOnDate;
private final boolean manuallyReversed;
@SuppressWarnings("unused")
private final LocalDate possibleNextRepaymentDate;
// templates
final Collection<PaymentTypeData> paymentTypeOptions;
private Collection<CodeValueData> writeOffReasonOptions = null;
private Collection<CodeValueData> writeOffReasonOptions = null;
//import fields
private transient Integer rowIndex;
@@ -79,7 +77,7 @@ public class LoanTransactionData {
private Integer routingCode;
private Integer receiptNumber;
private Integer bankNumber;
private transient Integer accountId;
private transient Long accountId;
private transient String transactionType;
public static LoanTransactionData importInstance(BigDecimal repaymentAmount,LocalDate lastRepaymentDate,
@@ -120,7 +118,7 @@ public class LoanTransactionData {
}
public static LoanTransactionData importInstance(BigDecimal repaymentAmount,LocalDate repaymentDate,
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){
return new LoanTransactionData(repaymentAmount, repaymentDate, repaymentTypeId, accountNumber,
checkNumber, routingCode, receiptNumber, bankNumber, loanAccountId, "",
@@ -129,7 +127,7 @@ public class LoanTransactionData {
private LoanTransactionData(BigDecimal transactionAmount,LocalDate transactionDate, Long paymentTypeId,
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) {
this.transactionAmount = transactionAmount;
this.transactionDate = transactionDate;
@@ -169,7 +167,7 @@ public class LoanTransactionData {
this.writeOffReasonOptions = null;
}
public Integer getAccountId() {
public Long getAccountId() {
return accountId;
}
@@ -132,4 +132,6 @@ public interface LoanReadPlatformService {
LoanTransactionData retrieveLoanForeclosureTemplate(final Long loanId, final LocalDate transactionDate);
LoanAccountData retrieveLoanByLoanAccount(String loanAccountNumber);
Long retrieveLoanIdByAccountNumber(String loanAccountNumber);
}
@@ -2197,5 +2197,16 @@ 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;
}
}
}