fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From av...@apache.org
Subject [12/19] fineract git commit: all modules populate & import
Date Wed, 13 Dec 2017 09:03:25 GMT
http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/journalentry/JournalEntriesImportHandler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/journalentry/JournalEntriesImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/journalentry/JournalEntriesImportHandler.java
new file mode 100644
index 0000000..ad7b8a9
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/journalentry/JournalEntriesImportHandler.java
@@ -0,0 +1,226 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.bulkimport.importhandler.journalentry;
+
+import com.google.gson.GsonBuilder;
+import org.apache.fineract.accounting.journalentry.data.CreditDebit;
+import org.apache.fineract.accounting.journalentry.data.JournalEntryData;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.apache.fineract.infrastructure.bulkimport.constants.ChartOfAcountsConstants;
+import org.apache.fineract.infrastructure.bulkimport.constants.JournalEntryConstants;
+import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
+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.CurrencyDateCodeSerializer;
+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.organisation.monetary.data.CurrencyData;
+import org.apache.poi.ss.usermodel.*;
+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;
+@Service
+public class JournalEntriesImportHandler implements ImportHandler {
+    private Workbook workbook;
+    private List<JournalEntryData> gltransaction;
+    private LocalDate transactionDate;
+
+    List<CreditDebit> credits = new ArrayList<>();
+    List<CreditDebit> debits = new ArrayList<>();
+
+    private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
+
+    @Autowired
+    public JournalEntriesImportHandler(final PortfolioCommandSourceWritePlatformService
+            commandsSourceWritePlatformService) {
+        this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
+    }
+
+    @Override
+    public Count process(Workbook workbook, String locale, String dateFormat) {
+        this.workbook=workbook;
+        gltransaction=new ArrayList<>();
+        readExcelFile(locale,dateFormat);
+        return importEntity(dateFormat);
+    }
+
+    public void readExcelFile(final String locale, final String dateFormat) {
+        String currentTransactionId = null;
+        String prevTransactionId = null;
+        JournalEntryData journalEntry = null;
+
+        Sheet addJournalEntriesSheet = workbook.getSheet(TemplatePopulateImportConstants.JOURNAL_ENTRY_SHEET_NAME);
+        Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(addJournalEntriesSheet, 4);
+        for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
+            Row row;
+                row = addJournalEntriesSheet.getRow(rowIndex);
+
+                currentTransactionId = ImportHandlerUtils.readAsString(JournalEntryConstants.TRANSACTION_ID_COL, row);
+
+                if (currentTransactionId.equals(prevTransactionId)) {
+                    if (journalEntry != null) {
+
+                        String creditGLAcct = ImportHandlerUtils.readAsString(
+                                JournalEntryConstants.GL_ACCOUNT_ID_CREDIT_COL, row);
+                        Long glAccountIdCredit = ImportHandlerUtils.getIdByName(
+                                workbook.getSheet(TemplatePopulateImportConstants.GL_ACCOUNTS_SHEET_NAME), creditGLAcct);
+
+                        String debitGLAcct = ImportHandlerUtils.readAsString(
+                                JournalEntryConstants. GL_ACCOUNT_ID_DEBIT_COL, row);
+
+                        Long glAccountIdDebit = ImportHandlerUtils.getIdByName(
+                                workbook.getSheet(TemplatePopulateImportConstants.GL_ACCOUNTS_SHEET_NAME), debitGLAcct);
+
+                        BigDecimal creditAmt=null;
+                        if (ImportHandlerUtils.readAsDouble(JournalEntryConstants.AMOUNT_CREDIT_COL, row)!=null)
+                        creditAmt = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(JournalEntryConstants.AMOUNT_CREDIT_COL, row));
+                        BigDecimal debitAmount=null;
+                        if (ImportHandlerUtils.readAsDouble(JournalEntryConstants.AMOUNT_DEBIT_COL, row)!=null)
+                        debitAmount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(JournalEntryConstants.AMOUNT_DEBIT_COL, row));
+
+                        if (creditGLAcct!=null) {
+
+                            CreditDebit credit = new CreditDebit(
+                                    glAccountIdCredit, creditAmt);
+                            journalEntry.addCredits(credit);
+                        }
+                        if (debitGLAcct!=null) {
+                            CreditDebit debit = new CreditDebit(
+                                    glAccountIdDebit, debitAmount);
+
+                            journalEntry.addDebits(debit);
+                        }
+                    }
+                } else {
+
+                    if (journalEntry != null) {
+                        gltransaction.add(journalEntry);
+                        journalEntry = null;
+                    }
+
+                    journalEntry = readAddJournalEntries(row,locale,dateFormat);
+
+                }
+            prevTransactionId = currentTransactionId;
+        }
+        // Adding last JE
+        gltransaction.add(journalEntry);
+    }
+
+    private JournalEntryData readAddJournalEntries(Row row,String locale,String dateFormat) {
+        LocalDate transactionDateCheck = ImportHandlerUtils.readAsDate(JournalEntryConstants.TRANSACION_ON_DATE_COL, row);
+        if (transactionDateCheck!=null)
+            transactionDate = transactionDateCheck;
+
+        String officeName = ImportHandlerUtils.readAsString(JournalEntryConstants.OFFICE_NAME_COL, row);
+        Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName);
+        String paymentType = ImportHandlerUtils.readAsString(JournalEntryConstants.PAYMENT_TYPE_ID_COL, row);
+        Long paymentTypeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME),
+                paymentType);
+        String currencyName = ImportHandlerUtils.readAsString(JournalEntryConstants.CURRENCY_NAME_COL, row);
+        String currencyCode = ImportHandlerUtils.getCodeByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME),
+                currencyName).toString();
+        String glAccountNameCredit = ImportHandlerUtils.readAsString(JournalEntryConstants.GL_ACCOUNT_ID_CREDIT_COL, row);
+        Long glAccountIdCredit = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.GL_ACCOUNTS_SHEET_NAME),
+                glAccountNameCredit);
+        String glAccountNameDebit = ImportHandlerUtils.readAsString(JournalEntryConstants.GL_ACCOUNT_ID_DEBIT_COL, row);
+        Long glAccountIdDebit = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.GL_ACCOUNTS_SHEET_NAME),
+                glAccountNameDebit);
+
+        credits = new ArrayList<>();
+        debits = new ArrayList<>();
+
+      //  String credit = readAsString(JournalEntryConstants.GL_ACCOUNT_ID_CREDIT_COL, row);
+      //  String debit = readAsString(JournalEntryConstants.GL_ACCOUNT_ID_DEBIT_COL, row);
+
+        if (glAccountNameCredit!=null) {
+            if (ImportHandlerUtils.readAsDouble(JournalEntryConstants.AMOUNT_CREDIT_COL, row) != null){
+                credits.add(new CreditDebit(glAccountIdCredit, BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(
+                        JournalEntryConstants.AMOUNT_CREDIT_COL, row))));
+            }else {
+                credits.add(new CreditDebit(glAccountIdCredit,null));
+            }
+        }
+
+        if (glAccountNameDebit!=null) {
+            if (ImportHandlerUtils.readAsDouble(JournalEntryConstants.AMOUNT_DEBIT_COL, row)!=null) {
+                debits.add(new CreditDebit(glAccountIdDebit, BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(
+                        JournalEntryConstants.AMOUNT_DEBIT_COL, row))));
+            }else {
+                debits.add(new CreditDebit(glAccountIdDebit, null));
+            }
+        }
+        String accountNo=ImportHandlerUtils.readAsString(JournalEntryConstants.ACCOUNT_NO_COL,row);
+        String chequeNo=ImportHandlerUtils.readAsString(JournalEntryConstants.CHECK_NO_COL,row);
+        String routingCode=ImportHandlerUtils.readAsString(JournalEntryConstants.ROUTING_CODE_COL,row);
+        String receiptNo=ImportHandlerUtils.readAsString(JournalEntryConstants.RECEIPT_NO_COL,row);
+        String bankNo=ImportHandlerUtils.readAsString(JournalEntryConstants.BANK_NO_COL,row);
+        String comments=ImportHandlerUtils.readAsString(JournalEntryConstants.COMMENTS_COL,row);
+
+        return JournalEntryData.importInstance(officeId, transactionDate, currencyCode,
+                paymentTypeId, row.getRowNum(), credits, debits,accountNo,chequeNo,routingCode,receiptNo,bankNo,comments,locale,dateFormat);
+
+    }
+
+    public Count importEntity(String dateFormat) {
+        Sheet addJournalEntriesSheet = workbook.getSheet(TemplatePopulateImportConstants.JOURNAL_ENTRY_SHEET_NAME);
+        int successCount=0;
+        int errorCount=0;
+        String errorMessage="";
+        GsonBuilder gsonBuilder = new GsonBuilder();
+        gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
+        gsonBuilder.registerTypeAdapter(CurrencyData.class,new CurrencyDateCodeSerializer());
+
+        for (JournalEntryData transaction : gltransaction) {
+            try {
+                String payload  =gsonBuilder.create().toJson(transaction);
+                final CommandWrapper commandRequest = new CommandWrapperBuilder() //
+                        .createJournalEntry() //
+                        .withJson(payload) //
+                        .build(); //
+                final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+                successCount++;
+                Cell statusCell = addJournalEntriesSheet.getRow(
+                        transaction.getRowIndex()).createCell(JournalEntryConstants.STATUS_COL);
+                statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
+                statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook,
+                        IndexedColors.LIGHT_GREEN));
+            }catch (RuntimeException ex){
+                errorCount++;
+                ex.printStackTrace();
+                errorMessage=ImportHandlerUtils.getErrorMessage(ex);
+                ImportHandlerUtils.writeErrorMessage(addJournalEntriesSheet,transaction.getRowIndex(),errorMessage, JournalEntryConstants.STATUS_COL);
+            }
+
+        }
+        addJournalEntriesSheet.setColumnWidth(JournalEntryConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
+        ImportHandlerUtils.writeString(JournalEntryConstants.STATUS_COL, addJournalEntriesSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
+        return Count.instance(successCount,errorCount);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java
new file mode 100644
index 0000000..1cfe401
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java
@@ -0,0 +1,464 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.bulkimport.importhandler.loan;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.apache.fineract.infrastructure.bulkimport.constants.LoanConstants;
+import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
+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.bulkimport.importhandler.helper.EnumOptionDataValueSerializer;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import org.apache.fineract.infrastructure.core.data.EnumOptionData;
+import org.apache.fineract.infrastructure.core.exception.*;
+import org.apache.fineract.portfolio.loanaccount.data.*;
+import org.apache.poi.ss.usermodel.*;
+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 java.util.Locale;
+
+@Service
+public class LoanImportHandler implements ImportHandler {
+    private Workbook workbook;
+    private List<LoanAccountData> loans;
+    private List<LoanApprovalData> approvalDates;
+    private List<LoanTransactionData> loanRepayments;
+    private List<DisbursementData> disbursalDates;
+    private List<String> statuses;
+
+    private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
+
+    @Autowired
+    public LoanImportHandler(final PortfolioCommandSourceWritePlatformService
+            commandsSourceWritePlatformService) {
+        this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
+    }
+    @Override
+    public Count process(Workbook workbook, String locale, String dateFormat) {
+        this.workbook=workbook;
+        this.loans = new ArrayList<>();
+        this.approvalDates = new ArrayList<>();
+        this.loanRepayments = new ArrayList<>();
+        this.disbursalDates = new ArrayList<>();
+        this.statuses=new ArrayList<>();
+        readExcelFile(locale,dateFormat);
+        return importEntity(dateFormat);
+    }
+
+    public void readExcelFile(final String locale, final String dateFormat) {
+        Sheet loanSheet = workbook.getSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME);
+        Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(loanSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX);
+        for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
+            Row row;
+                row = loanSheet.getRow(rowIndex);
+                if ( ImportHandlerUtils.isNotImported(row, LoanConstants.STATUS_COL)) {
+                    loans.add(readLoan(row,locale,dateFormat));
+                    approvalDates.add(readLoanApproval(row,locale,dateFormat));
+                    disbursalDates.add(readDisbursalData(row,locale,dateFormat));
+                    loanRepayments.add(readLoanRepayment(row,locale,dateFormat));
+                }
+        }
+
+    }
+
+    private LoanTransactionData readLoanRepayment(Row row,String locale,String dateFormat) {
+        BigDecimal repaymentAmount=null;
+        if (ImportHandlerUtils.readAsDouble(LoanConstants.TOTAL_AMOUNT_REPAID_COL, row)!=null)
+            repaymentAmount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(LoanConstants.TOTAL_AMOUNT_REPAID_COL, row));
+        LocalDate lastRepaymentDate = ImportHandlerUtils.readAsDate(LoanConstants.LAST_REPAYMENT_DATE_COL, row);
+        String repaymentType = ImportHandlerUtils.readAsString(LoanConstants.REPAYMENT_TYPE_COL, row);
+        Long repaymentTypeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME), repaymentType);
+        if (repaymentAmount!=null&&lastRepaymentDate!=null&&repaymentType!=null&&repaymentTypeId!=null)
+            return  LoanTransactionData.importInstance(repaymentAmount, lastRepaymentDate, repaymentTypeId, row.getRowNum(),locale,dateFormat);
+        else
+            return null;
+    }
+
+    private DisbursementData readDisbursalData(Row row,String locale,String dateFormat) {
+        LocalDate disbursedDate = ImportHandlerUtils.readAsDate(LoanConstants.DISBURSED_DATE_COL, row);
+        String linkAccountId=null;
+        if ( ImportHandlerUtils.readAsLong(LoanConstants.LINK_ACCOUNT_ID, row)!=null)
+         linkAccountId =  ImportHandlerUtils.readAsLong(LoanConstants.LINK_ACCOUNT_ID, row).toString();
+
+        if (disbursedDate!=null) {
+            return DisbursementData.importInstance(disbursedDate,linkAccountId,row.getRowNum(),locale,dateFormat);
+        }
+        return null;
+    }
+
+    private LoanApprovalData readLoanApproval(Row row,String locale,String dateFormat) {
+        LocalDate approvedDate = ImportHandlerUtils.readAsDate(LoanConstants.APPROVED_DATE_COL, row);
+        if (approvedDate!=null)
+            return LoanApprovalData.importInstance(approvedDate, row.getRowNum(),locale,dateFormat);
+        else
+            return null;
+    }
+
+    private LoanAccountData readLoan(Row row,String locale,String dateFormat) {
+        String externalId =  ImportHandlerUtils.readAsString(LoanConstants.EXTERNAL_ID_COL, row);
+        String status =  ImportHandlerUtils.readAsString(LoanConstants.STATUS_COL, row);
+        String productName =  ImportHandlerUtils.readAsString(LoanConstants.PRODUCT_COL, row);
+        Long productId =  ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME), productName);
+        String loanOfficerName =  ImportHandlerUtils.readAsString(LoanConstants.LOAN_OFFICER_NAME_COL, row);
+        Long loanOfficerId =  ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), loanOfficerName);
+        LocalDate submittedOnDate =  ImportHandlerUtils.readAsDate(LoanConstants.SUBMITTED_ON_DATE_COL, row);
+        String fundName =  ImportHandlerUtils.readAsString(LoanConstants.FUND_NAME_COL, row);
+        Long fundId;
+        if (fundName == null)
+            fundId = null;
+        else
+            fundId =  ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME), fundName);
+
+        BigDecimal principal = null;
+        if ( ImportHandlerUtils.readAsDouble(LoanConstants.PRINCIPAL_COL, row) != null)
+            principal = BigDecimal.valueOf( ImportHandlerUtils.readAsDouble(LoanConstants.PRINCIPAL_COL, row));
+        Integer numberOfRepayments =  ImportHandlerUtils.readAsInt(LoanConstants.NO_OF_REPAYMENTS_COL, row);
+        Integer repaidEvery =  ImportHandlerUtils.readAsInt(LoanConstants.REPAID_EVERY_COL, row);
+        String repaidEveryFrequency =  ImportHandlerUtils.readAsString(LoanConstants.REPAID_EVERY_FREQUENCY_COL, row);
+        String repaidEveryFrequencyId = "";
+        EnumOptionData repaidEveryFrequencyEnums = null;
+        if (repaidEveryFrequency != null) {
+            if (repaidEveryFrequency.equalsIgnoreCase("Days"))
+                repaidEveryFrequencyId = "0";
+            else if (repaidEveryFrequency.equalsIgnoreCase("Weeks"))
+                repaidEveryFrequencyId = "1";
+            else if (repaidEveryFrequency.equalsIgnoreCase("Months")) repaidEveryFrequencyId = "2";
+            repaidEveryFrequencyEnums = new EnumOptionData(null, null, repaidEveryFrequencyId);
+        }
+        Integer loanTerm =  ImportHandlerUtils.readAsInt(LoanConstants.LOAN_TERM_COL, row);
+        String loanTermFrequency =  ImportHandlerUtils.readAsString(LoanConstants.LOAN_TERM_FREQUENCY_COL, row);
+        EnumOptionData loanTermFrequencyEnum = null;
+        if (loanTermFrequency != null) {
+            String loanTermFrequencyId = "";
+            if (loanTermFrequency.equalsIgnoreCase("Days"))
+                loanTermFrequencyId = "0";
+            else if (loanTermFrequency.equalsIgnoreCase("Weeks"))
+                loanTermFrequencyId = "1";
+            else if (loanTermFrequency.equalsIgnoreCase("Months"))
+                loanTermFrequencyId = "2";
+            loanTermFrequencyEnum = new EnumOptionData(null, null, loanTermFrequencyId);
+        }
+        BigDecimal nominalInterestRate = null;
+        if ( ImportHandlerUtils.readAsDouble(LoanConstants.NOMINAL_INTEREST_RATE_COL, row) != null)
+            nominalInterestRate = BigDecimal.valueOf( ImportHandlerUtils.readAsDouble(LoanConstants.NOMINAL_INTEREST_RATE_COL, row));
+        String amortization =  ImportHandlerUtils.readAsString(LoanConstants.AMORTIZATION_COL, row);
+        String amortizationId = "";
+        EnumOptionData amortizationEnumOption = null;
+        if (amortization != null) {
+            if (amortization.equalsIgnoreCase("Equal principal payments"))
+                amortizationId = "0";
+            else if (amortization.equalsIgnoreCase("Equal installments")) amortizationId = "1";
+            amortizationEnumOption = new EnumOptionData(null, null, amortizationId);
+        }
+        String interestMethod =  ImportHandlerUtils.readAsString(LoanConstants.INTEREST_METHOD_COL, row);
+        String interestMethodId = "";
+        EnumOptionData interestMethodEnum = null;
+        if (interestMethod != null) {
+            if (interestMethod.equalsIgnoreCase("Flat"))
+                interestMethodId = "1";
+            else if (interestMethod.equalsIgnoreCase("Declining Balance")) interestMethodId = "0";
+            interestMethodEnum = new EnumOptionData(null, null, interestMethodId);
+        }
+        String interestCalculationPeriod = ImportHandlerUtils.readAsString(LoanConstants.INTEREST_CALCULATION_PERIOD_COL, row);
+        String interestCalculationPeriodId = "";
+        EnumOptionData interestCalculationPeriodEnum = null;
+        if (interestCalculationPeriod != null) {
+            if (interestCalculationPeriod.equalsIgnoreCase("Daily"))
+                interestCalculationPeriodId = "0";
+            else if (interestCalculationPeriod.equalsIgnoreCase("Same as repayment period"))
+                interestCalculationPeriodId = "1";
+            interestCalculationPeriodEnum = new EnumOptionData(null, null, interestCalculationPeriodId);
+
+        }
+        BigDecimal arrearsTolerance = null;
+        if ( ImportHandlerUtils.readAsDouble(LoanConstants.ARREARS_TOLERANCE_COL, row) != null)
+            arrearsTolerance = BigDecimal.valueOf( ImportHandlerUtils.readAsDouble(LoanConstants.ARREARS_TOLERANCE_COL, row));
+        String repaymentStrategy =  ImportHandlerUtils.readAsString(LoanConstants.REPAYMENT_STRATEGY_COL, row);
+        Long repaymentStrategyId = null;
+        if (repaymentStrategy!=null) {
+            if (repaymentStrategy.equalsIgnoreCase("Penalties, Fees, Interest, Principal order"))
+                repaymentStrategyId = 1L;
+            else if (repaymentStrategy.equalsIgnoreCase("HeavensFamily Unique"))
+                repaymentStrategyId = 2L;
+            else if (repaymentStrategy.equalsIgnoreCase("Creocore Unique"))
+                repaymentStrategyId = 3L;
+            else if (repaymentStrategy.equalsIgnoreCase("Overdue/Due Fee/Int,Principal"))
+                repaymentStrategyId = 4L;
+            else if (repaymentStrategy.equalsIgnoreCase("Principal, Interest, Penalties, Fees Order"))
+                repaymentStrategyId = 5L;
+            else if (repaymentStrategy.equalsIgnoreCase("Interest, Principal, Penalties, Fees Order"))
+                repaymentStrategyId = 6L;
+            else if (repaymentStrategy.equalsIgnoreCase("Early Repayment Strategy"))
+                repaymentStrategyId = 7L;
+        }
+        Integer graceOnPrincipalPayment =  ImportHandlerUtils.readAsInt(LoanConstants.GRACE_ON_PRINCIPAL_PAYMENT_COL, row);
+        Integer graceOnInterestPayment =  ImportHandlerUtils.readAsInt(LoanConstants.GRACE_ON_INTEREST_PAYMENT_COL, row);
+        Integer graceOnInterestCharged =  ImportHandlerUtils.readAsInt(LoanConstants.GRACE_ON_INTEREST_CHARGED_COL, row);
+        LocalDate interestChargedFromDate =  ImportHandlerUtils.readAsDate(LoanConstants.INTEREST_CHARGED_FROM_COL, row);
+        LocalDate firstRepaymentOnDate =  ImportHandlerUtils.readAsDate(LoanConstants.FIRST_REPAYMENT_COL, row);
+        String loanType=null;
+        EnumOptionData loanTypeEnumOption=null;
+        if ( ImportHandlerUtils.readAsString(LoanConstants.LOAN_TYPE_COL, row)!=null) {
+            loanType =  ImportHandlerUtils.readAsString(LoanConstants.LOAN_TYPE_COL, row).toLowerCase(Locale.ENGLISH);
+
+            loanTypeEnumOption = new EnumOptionData(null, null, loanType);
+        }
+
+        String clientOrGroupName = ImportHandlerUtils.readAsString(LoanConstants.CLIENT_NAME_COL, row);
+
+        List<LoanChargeData> charges = new ArrayList<>();
+
+        Long charge1 =  ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_1, row);
+        Long charge2 =  ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_2, row);
+
+        Long groupId =  ImportHandlerUtils.readAsLong(LoanConstants.GROUP_ID, row);
+
+        String linkAccountId =  ImportHandlerUtils.readAsString(LoanConstants.LINK_ACCOUNT_ID, row);
+
+        if (charge1!=null) {
+            if ( ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_1, row)!=null) {
+                charges.add(new LoanChargeData( ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_1, row),
+                        ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_1, row),
+                        BigDecimal.valueOf( ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_1, row))));
+            }else {
+                charges.add(new LoanChargeData( ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_1, row),
+                        ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_1, row),null));
+            }
+        }
+
+        if (charge2!=null) {
+            if ( ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_2, row)!=null){
+            charges.add(new LoanChargeData( ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_2, row),
+                    ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_2, row),
+                    BigDecimal.valueOf( ImportHandlerUtils.readAsDouble(LoanConstants.CHARGE_AMOUNT_2, row))));
+            }else {
+                charges.add(new LoanChargeData( ImportHandlerUtils.readAsLong(LoanConstants.CHARGE_ID_2, row),
+                        ImportHandlerUtils.readAsDate(LoanConstants.CHARGE_DUE_DATE_2, row),
+                       null));
+            }
+        }
+        statuses.add(status);
+        if (loanType!=null) {
+            if (loanType.equals("individual")) {
+                Long clientId =  ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientOrGroupName);
+                return LoanAccountData.importInstanceIndividual(loanTypeEnumOption, clientId, productId, loanOfficerId, submittedOnDate, fundId,
+                        principal, numberOfRepayments,
+                        repaidEvery, repaidEveryFrequencyEnums, loanTerm, loanTermFrequencyEnum, nominalInterestRate, submittedOnDate,
+                        amortizationEnumOption, interestMethodEnum, interestCalculationPeriodEnum, arrearsTolerance, repaymentStrategyId,
+                        graceOnPrincipalPayment, graceOnInterestPayment, graceOnInterestCharged, interestChargedFromDate, firstRepaymentOnDate,
+                        row.getRowNum(), externalId, null, charges, linkAccountId,locale,dateFormat);
+            } else if (loanType.equals("jlg")) {
+                Long clientId =  ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientOrGroupName);
+                return LoanAccountData.importInstanceIndividual(loanTypeEnumOption, clientId, productId, loanOfficerId, submittedOnDate, fundId,
+                        principal, numberOfRepayments,
+                        repaidEvery, repaidEveryFrequencyEnums, loanTerm, loanTermFrequencyEnum, nominalInterestRate, submittedOnDate,
+                        amortizationEnumOption, interestMethodEnum, interestCalculationPeriodEnum, arrearsTolerance, repaymentStrategyId,
+                        graceOnPrincipalPayment, graceOnInterestPayment, graceOnInterestCharged, interestChargedFromDate, firstRepaymentOnDate,
+                        row.getRowNum(), externalId, groupId, charges, linkAccountId,locale,dateFormat);
+            } else {
+                Long groupIdforGroupLoan =  ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME), clientOrGroupName);
+                return LoanAccountData.importInstanceGroup(loanTypeEnumOption, groupIdforGroupLoan, productId, loanOfficerId, submittedOnDate, fundId,
+                        principal, numberOfRepayments,
+                        repaidEvery, repaidEveryFrequencyEnums, loanTerm, loanTermFrequencyEnum, nominalInterestRate,
+                        amortizationEnumOption, interestMethodEnum, interestCalculationPeriodEnum, arrearsTolerance,
+                        repaymentStrategyId, graceOnPrincipalPayment, graceOnInterestPayment, graceOnInterestCharged,
+                        interestChargedFromDate, firstRepaymentOnDate, row.getRowNum(), externalId, linkAccountId,locale,dateFormat);
+            }
+        }else {
+            return null;
+        }
+    }
+
+    public Count importEntity(String dateFormat) {
+        Sheet loanSheet = workbook.getSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME);
+        int successCount=0;
+        int errorCount=0;
+        int progressLevel = 0;
+        String loanId;
+        String errorMessage="";
+        for (int i = 0; i < loans.size(); i++) {
+            Row row = loanSheet.getRow(loans.get(i).getRowIndex());
+            Cell errorReportCell = row.createCell(LoanConstants.FAILURE_REPORT_COL);
+            Cell statusCell = row.createCell(LoanConstants.STATUS_COL);
+            CommandProcessingResult result=null;
+            loanId="";
+            try {
+                String status = statuses.get(i);;
+                progressLevel = getProgressLevel(status);
+
+                if (progressLevel == 0&& loans.get(i)!=null) {
+                    result = importLoan(i,dateFormat);
+                    loanId = result.getLoanId().toString();
+                    progressLevel = 1;
+                } else
+                    loanId = ImportHandlerUtils.readAsString(LoanConstants.LOAN_ID_COL, loanSheet.getRow(loans.get(i).getRowIndex()));
+
+                if (progressLevel <= 1 && approvalDates.get(i)!=null) progressLevel = importLoanApproval(result, i,dateFormat);
+
+                if (progressLevel <= 2 && disbursalDates.get(i)!=null) progressLevel = importDisbursalData(result, i,dateFormat);
+
+                if (loanRepayments.get(i) != null) progressLevel = importLoanRepayment(result, i,dateFormat);
+
+                successCount++;
+                statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
+                statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
+            }catch (RuntimeException ex){
+                errorCount++;
+                ex.printStackTrace();
+                errorMessage=ImportHandlerUtils.getErrorMessage(ex);
+                writeLoanErrorMessage(loanId,errorMessage,progressLevel,statusCell,errorReportCell,row);
+            }
+
+        }
+        setReportHeaders(loanSheet);
+        return Count.instance(successCount,errorCount);
+    }
+
+    private void writeLoanErrorMessage(String loanId,String errorMessage,int progressLevel,Cell statusCell,Cell errorReportCell,Row row){
+        String status = "";
+        if (progressLevel == 0)
+            status = TemplatePopulateImportConstants.STATUS_CREATION_FAILED;
+        else if (progressLevel == 1)
+            status = TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED;
+        else if (progressLevel == 2)
+            status = TemplatePopulateImportConstants.STATUS_DISBURSAL_FAILED;
+        else if (progressLevel == 3) status = TemplatePopulateImportConstants.STATUS_DISBURSAL_REPAYMENT_FAILED;
+        statusCell.setCellValue(status);
+        statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.RED));
+
+        if (progressLevel > 0) row.createCell(LoanConstants.LOAN_ID_COL).setCellValue(Integer.parseInt(loanId));
+        errorReportCell.setCellValue(errorMessage);
+    }
+    private void setReportHeaders(Sheet sheet) {
+        sheet.setColumnWidth(LoanConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
+        Row rowHeader = sheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
+        ImportHandlerUtils.writeString(LoanConstants.STATUS_COL, rowHeader, "Status");
+        ImportHandlerUtils.writeString(LoanConstants.LOAN_ID_COL, rowHeader, "Loan ID");
+        ImportHandlerUtils.writeString(LoanConstants.FAILURE_REPORT_COL, rowHeader, "Report");
+    }
+
+    private Integer importLoanRepayment(CommandProcessingResult result, int rowIndex,String dateFormat) {
+        GsonBuilder gsonBuilder = new GsonBuilder();
+        gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
+        JsonObject loanRepaymentJsonob=gsonBuilder.create().toJsonTree(loanRepayments.get(rowIndex)).getAsJsonObject();
+        loanRepaymentJsonob.remove("manuallyReversed");
+        String payload=loanRepaymentJsonob.toString();
+        final CommandWrapper commandRequest = new CommandWrapperBuilder() //
+                .loanRepaymentTransaction(result.getLoanId()) //
+                .withJson(payload) //
+                .build(); //
+        final CommandProcessingResult loanRepaymentResult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+        return 4;
+    }
+
+    private Integer importDisbursalData(CommandProcessingResult result, int rowIndex, String dateFormat) {
+        if (approvalDates.get(rowIndex) != null && disbursalDates.get(rowIndex) != null) {
+
+            DisbursementData disbusalData = disbursalDates.get(rowIndex);
+            String linkAccountId = disbusalData.getLinkAccountId();
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
+            if (linkAccountId != null && linkAccountId != "") {
+                String payload =gsonBuilder.create().toJson(disbusalData);
+                final CommandWrapper commandRequest = new CommandWrapperBuilder() //
+                        .disburseLoanToSavingsApplication(result.getLoanId()) //
+                        .withJson(payload) //
+                        .build(); //
+                final CommandProcessingResult loanDisburseToSavingsResult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+            } else {
+                String payload = gsonBuilder.create().toJson(disbusalData);
+                final CommandWrapper commandRequest = new CommandWrapperBuilder() //
+                        .disburseLoanApplication(result.getLoanId()) //
+                        .withJson(payload) //
+                        .build(); //
+                final CommandProcessingResult loanDisburseResult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+            }
+        }
+        return 3;
+    }
+
+    private Integer importLoanApproval(CommandProcessingResult result, int rowIndex,String dateFormat) {
+        if (approvalDates.get(rowIndex) != null) {
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
+            String payload = gsonBuilder.create().toJson(approvalDates.get(rowIndex));
+            final CommandWrapper commandRequest = new CommandWrapperBuilder() //
+                    .approveLoanApplication(result.getLoanId()) //
+                    .withJson(payload) //
+                    .build(); //
+            final CommandProcessingResult loanapprovalresult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+        }
+        return 2;
+    }
+
+    private CommandProcessingResult importLoan(int rowIndex,String dateFormat) {
+        GsonBuilder gsonBuilder = new GsonBuilder();
+        gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
+        gsonBuilder.registerTypeAdapter(EnumOptionData.class,new EnumOptionDataValueSerializer());
+        JsonObject loanJsonOb  = gsonBuilder.create().toJsonTree(loans.get(rowIndex)).getAsJsonObject();
+        loanJsonOb.remove("isLoanProductLinkedToFloatingRate");
+        loanJsonOb.remove("isInterestRecalculationEnabled");
+        loanJsonOb.remove("isFloatingInterestRate");
+        JsonArray chargesJsonAr=loanJsonOb.getAsJsonArray("charges");
+        if (chargesJsonAr!=null) {
+            for (int i = 0; i < chargesJsonAr.size(); i++) {
+                JsonElement chargesJsonElement = chargesJsonAr.get(i);
+                JsonObject chargeJsonOb = chargesJsonElement.getAsJsonObject();
+                chargeJsonOb.remove("penalty");
+                chargeJsonOb.remove("paid");
+                chargeJsonOb.remove("waived");
+                chargeJsonOb.remove("chargePayable");
+            }
+        }
+        loanJsonOb.remove("isTopup");
+        String payload=loanJsonOb.toString();
+        final CommandWrapper commandRequest = new CommandWrapperBuilder() //
+                .createLoanApplication() //
+                .withJson(payload) //
+                .build(); //
+        final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+        return result;
+    }
+
+    private int getProgressLevel(String status) {
+        if (status==null || status.equals(TemplatePopulateImportConstants.STATUS_CREATION_FAILED))
+            return 0;
+        else if (status.equals(TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED))
+            return 1;
+        else if (status.equals(TemplatePopulateImportConstants.STATUS_DISBURSAL_FAILED))
+            return 2;
+        else if (status.equals(TemplatePopulateImportConstants.STATUS_DISBURSAL_REPAYMENT_FAILED)) return 3;
+        return 0;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loanrepayment/LoanRepaymentImportHandler.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..8134bc6
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loanrepayment/LoanRepaymentImportHandler.java
@@ -0,0 +1,134 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.bulkimport.importhandler.loanrepayment;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.apache.fineract.infrastructure.bulkimport.constants.LoanRepaymentConstants;
+import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
+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.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;
+@Service
+public class LoanRepaymentImportHandler implements ImportHandler {
+    private  Workbook workbook;
+    private  List<LoanTransactionData> loanRepayments;
+    private Integer loanAccountId;
+
+    private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
+    @Autowired
+    public LoanRepaymentImportHandler(final PortfolioCommandSourceWritePlatformService
+            commandsSourceWritePlatformService) {
+        this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
+    }
+
+    @Override
+    public Count process(Workbook workbook, String locale, String dateFormat) {
+        this.workbook=workbook;
+        this.loanRepayments=new ArrayList<>();
+        readExcelFile(locale,dateFormat);
+        return importEntity(dateFormat);
+    }
+    public void readExcelFile(String locale, String dateFormat) {
+        Sheet loanRepaymentSheet = workbook.getSheet(TemplatePopulateImportConstants.LOAN_REPAYMENT_SHEET_NAME);
+        Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(loanRepaymentSheet, LoanRepaymentConstants.AMOUNT_COL);
+        for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
+            Row row;
+                row = loanRepaymentSheet.getRow(rowIndex);
+                if(ImportHandlerUtils.isNotImported(row, LoanRepaymentConstants.STATUS_COL))
+                    loanRepayments.add(readLoanRepayment(row,locale,dateFormat));
+        }
+    }
+
+    private LoanTransactionData readLoanRepayment(Row row,String locale, String dateFormat) {
+        String loanaccountInfo=ImportHandlerUtils.readAsString(LoanRepaymentConstants.LOAN_ACCOUNT_NO_COL, row);
+        if (loanaccountInfo!=null){
+            String loanAccountAr[]=loanaccountInfo.split("-");
+            loanAccountId=Integer.parseInt(loanAccountAr[0]);
+        }
+        BigDecimal repaymentAmount=null;
+        if (ImportHandlerUtils.readAsDouble(LoanRepaymentConstants.AMOUNT_COL, row)!=null)
+         repaymentAmount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(LoanRepaymentConstants.AMOUNT_COL, row));
+        LocalDate repaymentDate = ImportHandlerUtils.readAsDate(LoanRepaymentConstants.REPAID_ON_DATE_COL, row);
+        String repaymentType = ImportHandlerUtils.readAsString(LoanRepaymentConstants.REPAYMENT_TYPE_COL, row);
+        Long repaymentTypeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME), repaymentType);
+        String accountNumber = ImportHandlerUtils.readAsString(LoanRepaymentConstants.ACCOUNT_NO_COL, row);
+        Integer checkNumber = ImportHandlerUtils.readAsInt(LoanRepaymentConstants.CHECK_NO_COL, row);
+        Integer routingCode = ImportHandlerUtils.readAsInt(LoanRepaymentConstants.ROUTING_CODE_COL, row);
+        Integer receiptNumber = ImportHandlerUtils.readAsInt(LoanRepaymentConstants.RECEIPT_NO_COL, row);
+        Integer bankNumber = ImportHandlerUtils.readAsInt(LoanRepaymentConstants.BANK_NO_COL, row);
+        return LoanTransactionData.importInstance(repaymentAmount, repaymentDate, repaymentTypeId, accountNumber,
+                checkNumber, routingCode, receiptNumber, bankNumber, loanAccountId, "", row.getRowNum(),locale,dateFormat);
+    }
+
+    public Count importEntity(String dateFormat) {
+        Sheet loanRepaymentSheet = workbook.getSheet(TemplatePopulateImportConstants.LOAN_REPAYMENT_SHEET_NAME);
+        int successCount=0;
+        int errorCount=0;
+        String errorMessage="";
+        GsonBuilder gsonBuilder = new GsonBuilder();
+        gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
+
+        for (LoanTransactionData loanRepayment : loanRepayments) {
+            try {
+
+                JsonObject loanRepaymentJsonob=gsonBuilder.create().toJsonTree(loanRepayment).getAsJsonObject();
+                loanRepaymentJsonob.remove("manuallyReversed");
+                String payload=loanRepaymentJsonob.toString();
+                final CommandWrapper commandRequest = new CommandWrapperBuilder() //
+                        .loanRepaymentTransaction(loanRepayment.getAccountId().longValue()) //
+                        .withJson(payload) //
+                        .build(); //
+                final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+                successCount++;
+                Cell statusCell = loanRepaymentSheet.getRow(loanRepayment.getRowIndex()).createCell(LoanRepaymentConstants.STATUS_COL);
+                statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
+                statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
+            }catch (RuntimeException ex){
+                errorCount++;
+                ex.printStackTrace();
+                errorMessage=ImportHandlerUtils.getErrorMessage(ex);
+                ImportHandlerUtils.writeErrorMessage(loanRepaymentSheet,loanRepayment.getRowIndex(),errorMessage,LoanRepaymentConstants.STATUS_COL);
+            }
+
+        }
+        loanRepaymentSheet.setColumnWidth(LoanRepaymentConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
+        ImportHandlerUtils.writeString(LoanRepaymentConstants.STATUS_COL,
+                loanRepaymentSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX),
+                TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
+        return Count.instance(successCount,errorCount);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/office/OfficeImportHandler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/office/OfficeImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/office/OfficeImportHandler.java
new file mode 100644
index 0000000..7a3aa00
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/office/OfficeImportHandler.java
@@ -0,0 +1,123 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.bulkimport.importhandler.office;
+
+import com.google.gson.GsonBuilder;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.apache.fineract.infrastructure.bulkimport.constants.OfficeConstants;
+import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
+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.organisation.office.data.OfficeData;
+import org.apache.poi.ss.usermodel.*;
+import org.joda.time.LocalDate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class OfficeImportHandler implements ImportHandler {
+    private List<OfficeData> offices;
+    private Workbook workbook;
+    private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
+
+    @Autowired
+    public OfficeImportHandler(final PortfolioCommandSourceWritePlatformService
+            commandsSourceWritePlatformService) {
+        this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
+    }
+
+    @Override
+    public Count process(final Workbook workbook, final String locale, final String dateFormat) {
+        this.offices=new ArrayList<>();
+        this.workbook=workbook;
+        readExcelFile(locale, dateFormat);
+        return importEntity (dateFormat);
+    }
+
+
+
+    public void readExcelFile(final String locale, final String dateFormat) {
+        Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
+        Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(officeSheet,0);
+        for (int rowIndex=1;rowIndex<=noOfEntries;rowIndex++) {
+            Row row;
+            row=officeSheet.getRow(rowIndex);
+            if (ImportHandlerUtils.isNotImported(row, OfficeConstants.STATUS_COL)){
+                offices.add(readOffice(row, locale, dateFormat));
+            }
+        }
+    }
+
+    private OfficeData readOffice(Row row, final String locale, final String dateFormat) {
+        String officeName = ImportHandlerUtils.readAsString(OfficeConstants.OFFICE_NAME_COL,row);
+        Long parentId= ImportHandlerUtils.readAsLong(OfficeConstants.PARENT_OFFICE_ID_COL,row);
+        LocalDate openedDate= ImportHandlerUtils.readAsDate(OfficeConstants.OPENED_ON_COL,row);
+        String externalId= ImportHandlerUtils.readAsString(OfficeConstants.EXTERNAL_ID_COL,row);
+        OfficeData office = OfficeData.importInstance(officeName,parentId,openedDate,externalId);
+        office.setImportFields(row.getRowNum(), locale, dateFormat);
+        return office;
+    }
+
+    public Count importEntity(String dateFormat) {
+        Sheet officeSheet = workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
+        GsonBuilder gsonBuilder = new GsonBuilder();
+        gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
+
+        int successCount = 0;
+        int errorCount = 0;
+        String errorMessage="";
+        for (OfficeData office: offices) {
+            try {
+                String payload = gsonBuilder.create().toJson(office);
+                final CommandWrapper commandRequest = new CommandWrapperBuilder() //
+                        .createOffice() //
+                        .withJson(payload) //
+                        .build(); //
+                final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+                successCount ++;
+                Cell statusCell = officeSheet.getRow(office.getRowIndex()).createCell(OfficeConstants.STATUS_COL);
+                statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
+                statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
+            }catch (RuntimeException ex){
+                errorCount++;
+                ex.printStackTrace();
+                errorMessage=ImportHandlerUtils.getErrorMessage(ex);
+                ImportHandlerUtils.writeErrorMessage(officeSheet,office.getRowIndex(),errorMessage,OfficeConstants.STATUS_COL);
+            }
+        }
+        officeSheet.setColumnWidth(OfficeConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
+        ImportHandlerUtils.writeString(OfficeConstants.STATUS_COL, officeSheet.getRow(0), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER);
+        return Count.instance(successCount, errorCount);
+    }
+
+    public List<OfficeData> getOffices() {
+        return offices;
+    }
+}
+
+

http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/recurringdeposit/RecurringDepositImportHandler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/recurringdeposit/RecurringDepositImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/recurringdeposit/RecurringDepositImportHandler.java
new file mode 100644
index 0000000..0c2cb82
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/recurringdeposit/RecurringDepositImportHandler.java
@@ -0,0 +1,372 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.bulkimport.importhandler.recurringdeposit;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.apache.fineract.infrastructure.bulkimport.constants.RecurringDepositConstants;
+import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
+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.bulkimport.importhandler.helper.EnumOptionDataIdSerializer;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import org.apache.fineract.infrastructure.core.data.EnumOptionData;
+import org.apache.fineract.infrastructure.core.exception.*;
+import org.apache.fineract.portfolio.savings.data.RecurringDepositAccountData;
+import org.apache.fineract.portfolio.savings.data.SavingsAccountChargeData;
+import org.apache.fineract.portfolio.savings.data.SavingsActivation;
+import org.apache.fineract.portfolio.savings.data.SavingsApproval;
+import org.apache.poi.ss.usermodel.*;
+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;
+@Service
+public class RecurringDepositImportHandler implements ImportHandler {
+
+    private Workbook workbook;
+    private List<RecurringDepositAccountData> savings;
+    private List<SavingsApproval> approvalDates;
+    private List<SavingsActivation> activationDates;
+    private List<String> statuses;
+
+    private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
+
+    @Autowired
+    public RecurringDepositImportHandler(final PortfolioCommandSourceWritePlatformService
+            commandsSourceWritePlatformService) {
+        this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
+
+    }
+    @Override
+    public Count process(Workbook workbook, String locale, String dateFormat) {
+        this.workbook=workbook;
+        savings=new ArrayList<>();
+        approvalDates=new ArrayList<>();
+        activationDates=new ArrayList<>();
+        statuses=new ArrayList<>();
+        readExcelFile(locale,dateFormat);
+        return importEntity(dateFormat);
+    }
+
+    public void readExcelFile(String locale, String dateFormat) {
+        Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.RECURRING_DEPOSIT_SHEET_NAME);
+        Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsSheet, TemplatePopulateImportConstants.ROWHEADER_INDEX);
+        for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
+            Row row;
+                row = savingsSheet.getRow(rowIndex);
+                if (ImportHandlerUtils.isNotImported(row, RecurringDepositConstants.STATUS_COL)) {
+                    savings.add(readSavings(row,locale,dateFormat));
+                    approvalDates.add(readSavingsApproval(row,locale,dateFormat));
+                    activationDates.add(readSavingsActivation(row,locale,dateFormat));
+                }
+        }
+
+    }
+
+    private SavingsActivation readSavingsActivation(Row row,String locale, String dateFormat) {
+        LocalDate activationDate = ImportHandlerUtils.readAsDate(RecurringDepositConstants.ACTIVATION_DATE_COL, row);
+        if (activationDate!=null)
+            return SavingsActivation.importInstance(activationDate, row.getRowNum(),locale,dateFormat);
+        else
+            return null;
+    }
+
+    private SavingsApproval readSavingsApproval(Row row,String locale, String dateFormat) {
+        LocalDate approvalDate = ImportHandlerUtils.readAsDate(RecurringDepositConstants.APPROVED_DATE_COL, row);
+        if (approvalDate!=null)
+            return SavingsApproval.importInstance(approvalDate, row.getRowNum(),locale,dateFormat);
+        else
+            return null;
+    }
+
+    private RecurringDepositAccountData readSavings(Row row,String locale, String dateFormat) {
+
+        String productName = ImportHandlerUtils.readAsString(RecurringDepositConstants.PRODUCT_COL, row);
+        Long productId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME), productName);
+        String fieldOfficerName = ImportHandlerUtils.readAsString(RecurringDepositConstants.FIELD_OFFICER_NAME_COL, row);
+        Long fieldOfficerId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), fieldOfficerName);
+        LocalDate submittedOnDate = ImportHandlerUtils.readAsDate(RecurringDepositConstants.SUBMITTED_ON_DATE_COL, row);
+        String interestCompoundingPeriodType = ImportHandlerUtils.readAsString(RecurringDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL, row);
+        Long interestCompoundingPeriodTypeId = null;
+        EnumOptionData interestCompoundingPeriodTypeEnum=null;
+        if (interestCompoundingPeriodType!=null) {
+            if (interestCompoundingPeriodType.equalsIgnoreCase("Daily"))
+                interestCompoundingPeriodTypeId = 1L;
+            else if (interestCompoundingPeriodType.equalsIgnoreCase("Monthly"))
+                interestCompoundingPeriodTypeId = 4L;
+            else if (interestCompoundingPeriodType.equalsIgnoreCase("Quarterly"))
+                interestCompoundingPeriodTypeId = 5L;
+            else if (interestCompoundingPeriodType.equalsIgnoreCase("Semi-Annual"))
+                interestCompoundingPeriodTypeId = 6L;
+            else if (interestCompoundingPeriodType.equalsIgnoreCase("Annually"))
+                interestCompoundingPeriodTypeId = 7L;
+            interestCompoundingPeriodTypeEnum = new EnumOptionData(interestCompoundingPeriodTypeId, null, null);
+        }
+        String interestPostingPeriodType = ImportHandlerUtils.readAsString(RecurringDepositConstants.INTEREST_POSTING_PERIOD_COL, row);
+        Long interestPostingPeriodTypeId = null;
+        EnumOptionData interestPostingPeriodTypeEnum=null;
+        if (interestPostingPeriodType!=null) {
+            if (interestPostingPeriodType.equalsIgnoreCase("Monthly"))
+                interestPostingPeriodTypeId = 4L;
+            else if (interestPostingPeriodType.equalsIgnoreCase("Quarterly"))
+                interestPostingPeriodTypeId = 5L;
+            else if (interestPostingPeriodType.equalsIgnoreCase("Annually"))
+                interestPostingPeriodTypeId = 7L;
+            else if (interestPostingPeriodType.equalsIgnoreCase("BiAnnual"))
+                interestPostingPeriodTypeId = 6L;
+                interestPostingPeriodTypeEnum = new EnumOptionData(interestPostingPeriodTypeId, null, null);
+        }
+
+        String interestCalculationType = ImportHandlerUtils.readAsString(RecurringDepositConstants.INTEREST_CALCULATION_COL, row);
+        Long interestCalculationTypeId = null;
+        EnumOptionData interestCalculationTypeEnum=null;
+        if (interestCalculationType!=null) {
+            if (interestCalculationType.equalsIgnoreCase("Daily Balance"))
+                interestCalculationTypeId = 1L;
+            else if (interestCalculationType.equalsIgnoreCase("Average Daily Balance"))
+                interestCalculationTypeId = 2L;
+             interestCalculationTypeEnum = new EnumOptionData(interestCalculationTypeId, null, null);
+        }
+        String interestCalculationDaysInYearType = ImportHandlerUtils.readAsString(RecurringDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row);
+        EnumOptionData interestCalculationDaysInYearTypeEnum=null;
+        Long interestCalculationDaysInYearTypeId = null;
+        if (interestCalculationDaysInYearType!=null) {
+            if (interestCalculationDaysInYearType.equalsIgnoreCase("360 Days"))
+                interestCalculationDaysInYearTypeId = 360L;
+            else if (interestCalculationDaysInYearType.equalsIgnoreCase("365 Days"))
+                interestCalculationDaysInYearTypeId = 365L;
+             interestCalculationDaysInYearTypeEnum = new EnumOptionData(interestCalculationDaysInYearTypeId, null, null);
+        }
+        Integer lockinPeriodFrequency = ImportHandlerUtils.readAsInt(RecurringDepositConstants.LOCKIN_PERIOD_COL, row);
+        String lockinPeriodFrequencyType = ImportHandlerUtils.readAsString(RecurringDepositConstants.LOCKIN_PERIOD_FREQUENCY_COL, row);
+        Long lockinPeriodFrequencyTypeId = null;
+        EnumOptionData lockinPeriodFrequencyTypeEnum=null;
+        if (lockinPeriodFrequencyType!=null) {
+            if (lockinPeriodFrequencyType.equalsIgnoreCase("Days"))
+                lockinPeriodFrequencyTypeId = 0L;
+            else if (lockinPeriodFrequencyType.equalsIgnoreCase("Weeks"))
+                lockinPeriodFrequencyTypeId = 1L;
+            else if (lockinPeriodFrequencyType.equalsIgnoreCase("Months"))
+                lockinPeriodFrequencyTypeId = 2L;
+            else if (lockinPeriodFrequencyType.equalsIgnoreCase("Years"))
+                lockinPeriodFrequencyTypeId = 3L;
+             lockinPeriodFrequencyTypeEnum = new EnumOptionData(lockinPeriodFrequencyTypeId, null, null);
+        }
+        BigDecimal depositAmount=null;
+        if (ImportHandlerUtils.readAsDouble(RecurringDepositConstants.RECURRING_DEPOSIT_AMOUNT_COL, row)!=null)
+         depositAmount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(RecurringDepositConstants.RECURRING_DEPOSIT_AMOUNT_COL, row));
+        Integer depositPeriod = ImportHandlerUtils.readAsInt(RecurringDepositConstants.DEPOSIT_PERIOD_COL, row);
+        String depositPeriodFrequency = ImportHandlerUtils.readAsString(RecurringDepositConstants.DEPOSIT_PERIOD_FREQUENCY_COL, row);
+        Long depositPeriodFrequencyId = null;
+        if (depositPeriodFrequency!=null) {
+            if (depositPeriodFrequency.equalsIgnoreCase("Days"))
+                depositPeriodFrequencyId = 0L;
+            else if (depositPeriodFrequency.equalsIgnoreCase("Weeks"))
+                depositPeriodFrequencyId = 1L;
+            else if (depositPeriodFrequency.equalsIgnoreCase("Months"))
+                depositPeriodFrequencyId = 2L;
+            else if (depositPeriodFrequency.equalsIgnoreCase("Years"))
+                depositPeriodFrequencyId = 3L;
+        }
+        Integer recurringFrequency = ImportHandlerUtils.readAsInt(RecurringDepositConstants.DEPOSIT_FREQUENCY_COL, row);
+        String recurringFrequencyType = ImportHandlerUtils.readAsString(RecurringDepositConstants.DEPOSIT_FREQUENCY_TYPE_COL, row);
+        Long recurringFrequencyTypeId = null;
+        EnumOptionData recurringFrequencyTypeEnum=null;
+        if (recurringFrequencyType!=null) {
+            if (recurringFrequencyType.equalsIgnoreCase("Days"))
+                recurringFrequencyTypeId = 0L;
+            else if (recurringFrequencyType.equalsIgnoreCase("Weeks"))
+                recurringFrequencyTypeId = 1L;
+            else if (recurringFrequencyType.equalsIgnoreCase("Months"))
+                recurringFrequencyTypeId = 2L;
+            else if (recurringFrequencyType.equalsIgnoreCase("Years"))
+                recurringFrequencyTypeId = 3L;
+             recurringFrequencyTypeEnum = new EnumOptionData(recurringFrequencyTypeId, null, null);
+        }
+        LocalDate depositStartDate = ImportHandlerUtils.readAsDate(RecurringDepositConstants.DEPOSIT_START_DATE_COL, row);
+        Boolean allowWithdrawal = ImportHandlerUtils.readAsBoolean(RecurringDepositConstants.ALLOW_WITHDRAWAL_COL, row);
+        Boolean isMandatoryDeposit = ImportHandlerUtils.readAsBoolean(RecurringDepositConstants.IS_MANDATORY_DEPOSIT_COL, row);
+        Boolean inheritCalendar = ImportHandlerUtils.readAsBoolean(RecurringDepositConstants.FREQ_SAME_AS_GROUP_CENTER_COL, row);
+        Boolean adjustAdvancePayments = ImportHandlerUtils.readAsBoolean(RecurringDepositConstants.ADJUST_ADVANCE_PAYMENTS_COL, row);
+        String clientName = ImportHandlerUtils.readAsString(RecurringDepositConstants.CLIENT_NAME_COL, row);
+        String externalId = ImportHandlerUtils.readAsString(RecurringDepositConstants.EXTERNAL_ID_COL, row);
+        List<SavingsAccountChargeData> charges = new ArrayList<>();
+
+        String charge1 = ImportHandlerUtils.readAsString(RecurringDepositConstants.CHARGE_ID_1, row);
+        String charge2 = ImportHandlerUtils.readAsString(RecurringDepositConstants.CHARGE_ID_2, row);
+
+        if (charge1!=null) {
+            if (ImportHandlerUtils.readAsDouble(RecurringDepositConstants.CHARGE_AMOUNT_1, row)!=null) {
+                charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(RecurringDepositConstants.CHARGE_ID_1, row),
+                        BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(RecurringDepositConstants.CHARGE_AMOUNT_1, row)),
+                        ImportHandlerUtils.readAsDate(RecurringDepositConstants.CHARGE_DUE_DATE_1, row)));
+            }else {
+                charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(RecurringDepositConstants.CHARGE_ID_1, row),
+                       null,
+                        ImportHandlerUtils.readAsDate(RecurringDepositConstants.CHARGE_DUE_DATE_1, row)));
+            }
+        }
+
+        if (charge2!=null) {
+            if (ImportHandlerUtils.readAsDouble(RecurringDepositConstants.CHARGE_AMOUNT_2, row)!=null) {
+                charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(RecurringDepositConstants.CHARGE_ID_2, row),
+                        BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(RecurringDepositConstants.CHARGE_AMOUNT_2, row)),
+                        ImportHandlerUtils.readAsDate(RecurringDepositConstants.CHARGE_DUE_DATE_2, row)));
+            }else {
+                charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(RecurringDepositConstants.CHARGE_ID_2, row),
+                       null,
+                        ImportHandlerUtils.readAsDate(RecurringDepositConstants.CHARGE_DUE_DATE_2, row)));
+            }
+        }
+        String status = ImportHandlerUtils.readAsString(RecurringDepositConstants.STATUS_COL, row);
+        statuses.add(status);
+        Long clientId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientName);
+        return RecurringDepositAccountData.importInstance(clientId, productId, fieldOfficerId, submittedOnDate,
+                interestCompoundingPeriodTypeEnum,interestPostingPeriodTypeEnum,interestCalculationTypeEnum,
+                interestCalculationDaysInYearTypeEnum, lockinPeriodFrequency, lockinPeriodFrequencyTypeEnum,
+                depositAmount, depositPeriod, depositPeriodFrequencyId, depositStartDate,
+                recurringFrequency, recurringFrequencyTypeEnum, inheritCalendar, isMandatoryDeposit,
+                allowWithdrawal, adjustAdvancePayments, externalId,charges, row.getRowNum(),locale,dateFormat);
+    }
+
+    public Count importEntity(String dateFormat) {
+        Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.RECURRING_DEPOSIT_SHEET_NAME);
+        int successCount=0;
+        int errorCount=0;
+        int progressLevel = 0;
+        Long savingsId=null;
+        String errorMessage="";
+        for (int i = 0; i < savings.size(); i++) {
+            Row row = savingsSheet.getRow(savings.get(i).getRowIndex());
+            Cell statusCell = row.createCell(RecurringDepositConstants.STATUS_COL);
+            Cell errorReportCell = row.createCell(RecurringDepositConstants.FAILURE_REPORT_COL);
+            try {
+                String status = statuses.get(i);
+                progressLevel = getProgressLevel(status);
+
+                if (progressLevel == 0) {
+                    CommandProcessingResult result= importSavings(i,dateFormat);
+                    savingsId = result.getSavingsId();
+                    progressLevel = 1;
+                } else
+                    savingsId = ImportHandlerUtils.readAsLong(RecurringDepositConstants.SAVINGS_ID_COL, savingsSheet.getRow(savings.get(i).getRowIndex()));
+
+                if (progressLevel <= 1) progressLevel = importSavingsApproval(savingsId, i,dateFormat);
+
+                if (progressLevel <= 2) progressLevel = importSavingsActivation(savingsId, i,dateFormat);
+                successCount++;
+                statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
+                statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN));
+            }catch (RuntimeException ex){
+                errorCount++;
+                ex.printStackTrace();
+                errorMessage=ImportHandlerUtils.getErrorMessage(ex);
+                writeRecurringDepositErrorMessage(savingsId,errorMessage,progressLevel,statusCell,errorReportCell,row);
+            }
+        }
+        setReportHeaders(savingsSheet);
+        return Count.instance(successCount,errorCount);
+    }
+
+    private void writeRecurringDepositErrorMessage(Long savingsId,String errorMessage,int progressLevel,Cell statusCell,Cell errorReportCell,Row row){
+        String status = "";
+        if (progressLevel == 0)
+            status = TemplatePopulateImportConstants.STATUS_CREATION_FAILED;
+        else if (progressLevel == 1)
+            status = TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED;
+        else if (progressLevel == 2) status = TemplatePopulateImportConstants.STATUS_ACTIVATION_FAILED;
+        statusCell.setCellValue(status);
+        statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.RED));
+
+        if (progressLevel > 0) row.createCell(RecurringDepositConstants.SAVINGS_ID_COL).setCellValue(savingsId);
+
+        errorReportCell.setCellValue(errorMessage);
+    }
+
+    private void setReportHeaders(Sheet savingsSheet) {
+        savingsSheet.setColumnWidth(RecurringDepositConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE);
+        Row rowHeader = savingsSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX);
+        ImportHandlerUtils.writeString(RecurringDepositConstants.STATUS_COL, rowHeader, "Status");
+        ImportHandlerUtils.writeString(RecurringDepositConstants.SAVINGS_ID_COL, rowHeader, "Savings ID");
+        ImportHandlerUtils.writeString(RecurringDepositConstants.FAILURE_REPORT_COL, rowHeader, "Report");
+    }
+
+    private int importSavingsActivation(Long savingsId, int i,String dateFormat) {
+        if(activationDates.get(i)!=null) {
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
+            String payload = gsonBuilder.create().toJson(activationDates.get(i));
+            final CommandWrapper commandRequest = new CommandWrapperBuilder() //
+                    .recurringDepositAccountActivation(savingsId)//
+                    .withJson(payload) //
+                    .build(); //
+            final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+        }
+        return 3;
+    }
+
+    private int importSavingsApproval(Long savingsId, int i, String dateFormat) {
+        if(approvalDates.get(i)!=null) {
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
+            String payload = gsonBuilder.create().toJson(approvalDates.get(i));
+            final CommandWrapper commandRequest = new CommandWrapperBuilder() //
+                    .approveRecurringDepositAccountApplication(savingsId)//
+                    .withJson(payload) //
+                    .build(); //
+            final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+        }
+        return 2;
+    }
+
+    private CommandProcessingResult importSavings(int i, String dateFormat) {
+        GsonBuilder gsonBuilder = new GsonBuilder();
+        gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
+        gsonBuilder.registerTypeAdapter(EnumOptionData.class,new EnumOptionDataIdSerializer());
+        JsonObject savingsJsonob=gsonBuilder.create().toJsonTree(savings.get(i)).getAsJsonObject();
+        savingsJsonob.remove("withdrawalFeeForTransfers");
+        String payload=savingsJsonob.toString();
+        final CommandWrapper commandRequest = new CommandWrapperBuilder() //
+                .createRecurringDepositAccount() //
+                .withJson(payload) //
+                .build(); //
+        final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
+        return result;
+    }
+
+    private int getProgressLevel(String status) {
+        if (status==null || status.equals(TemplatePopulateImportConstants.STATUS_CREATION_FAILED))
+            return 0;
+        else if (status.equals(TemplatePopulateImportConstants.STATUS_APPROVAL_FAILED))
+            return 1;
+        else if (status.equals(TemplatePopulateImportConstants.STATUS_ACTIVATION_FAILED)) return 2;
+        return 0;
+    }
+
+
+}


Mime
View raw message