You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by GitBox <gi...@apache.org> on 2018/11/12 09:27:59 UTC

[GitHub] ShruthiRajaram closed pull request #489: FINERACT-659 Account Id issue while importing loan transaction

ShruthiRajaram closed pull request #489: FINERACT-659 Account Id issue while importing loan transaction
URL: https://github.com/apache/fineract/pull/489
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loanrepayment/LoanRepaymentImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loanrepayment/LoanRepaymentImportHandler.java
index 8134bc666..c5417e3c0 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loanrepayment/LoanRepaymentImportHandler.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loanrepayment/LoanRepaymentImportHandler.java
@@ -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.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 @@ private LoanTransactionData readLoanRepayment(Row row,String locale, String date
         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 Count importEntity(String dateFormat) {
                 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);
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loanrepayment/LoanRepaymentWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loanrepayment/LoanRepaymentWorkbookPopulator.java
index 04646fbcc..fe3e8c575 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loanrepayment/LoanRepaymentWorkbookPopulator.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loanrepayment/LoanRepaymentWorkbookPopulator.java
@@ -213,7 +213,7 @@ private void populateLoansTable(Sheet loanRepaymentSheet,String dateFormat) {
 			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) {
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanTransactionData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanTransactionData.java
index e3424fa88..7b6501769 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanTransactionData.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanTransactionData.java
@@ -21,7 +21,6 @@
 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 @@
 /**
  * Immutable data object representing a loan transaction.
  */
+@SuppressWarnings("unused")
 public class LoanTransactionData {
 
     private final Long id;
@@ -56,16 +56,14 @@
     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 @@
     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 @@ private LoanTransactionData(BigDecimal transactionAmount,LocalDate transactionDa
     }
     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 static LoanTransactionData importInstance(BigDecimal repaymentAmount,Loca
 
     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 @@ private LoanTransactionData(BigDecimal transactionAmount,LocalDate transactionDa
         this.writeOffReasonOptions = null;
     }
 
-    public Integer getAccountId() {
+    public Long getAccountId() {
         return accountId;
     }
 
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformService.java
index 73f41cfdc..e205fbf19 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformService.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformService.java
@@ -132,4 +132,6 @@ LoanScheduleData retrieveRepaymentSchedule(Long loanId, RepaymentScheduleRelated
     LoanTransactionData retrieveLoanForeclosureTemplate(final Long loanId, final LocalDate transactionDate);
 
 	LoanAccountData retrieveLoanByLoanAccount(String loanAccountNumber);
+	
+	Long retrieveLoanIdByAccountNumber(String loanAccountNumber);
 }
\ No newline at end of file
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
index edf543cdd..e2464d83b 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
@@ -2197,5 +2197,16 @@ public LoanTransactionData mapRow(ResultSet rs, int rowNum) throws SQLException
         }
 
     }
-    
+
+	@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;
+		}
+	}
+
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services