fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From avikganguly01 <...@git.apache.org>
Subject [GitHub] fineract pull request #415: Extend-mifos-data-import-tool-all-modules-popula...
Date Sun, 08 Oct 2017 16:14:32 GMT
Github user avikganguly01 commented on a diff in the pull request:

    https://github.com/apache/fineract/pull/415#discussion_r143358796
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/chartofaccounts/ChartOfAccountsImportHandler.java
---
    @@ -0,0 +1,185 @@
    +/**
    + * 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.chartofaccounts;
    +
    +import com.google.gson.GsonBuilder;
    +import org.apache.fineract.accounting.glaccount.data.GLAccountData;
    +import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
    +import org.apache.fineract.accounting.glaccount.domain.GLAccountUsage;
    +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.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.CodeValueDataIdSerializer;
    +import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.EnumOptionDataIdSerializer;
    +import org.apache.fineract.infrastructure.codes.data.CodeValueData;
    +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.poi.ss.usermodel.*;
    +import org.springframework.beans.factory.annotation.Autowired;
    +import org.springframework.stereotype.Service;
    +
    +import java.util.ArrayList;
    +import java.util.List;
    +@Service
    +public class ChartOfAccountsImportHandler implements ImportHandler {
    +    private  List<GLAccountData> glAccounts;
    +    private  Workbook workbook;
    +
    +    private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
    +
    +    @Autowired
    +    public ChartOfAccountsImportHandler(final PortfolioCommandSourceWritePlatformService
    +            commandsSourceWritePlatformService) {
    +        this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
    +    }
    +
    +    @Override
    +    public Count process(Workbook workbook, String locale, String dateFormat) {
    +        this.glAccounts=new ArrayList<>();
    +        this.workbook=workbook;
    +        readExcelFile();
    +        return importEntity();
    +    }
    +
    +    public void readExcelFile() {
    +
    +        Sheet chartOfAccountsSheet=workbook.getSheet(TemplatePopulateImportConstants.CHART_OF_ACCOUNTS_SHEET_NAME);
    +        Integer noOfEntries= ImportHandlerUtils.getNumberOfRows(chartOfAccountsSheet,TemplatePopulateImportConstants.FIRST_COLUMN_INDEX);
    +        for (int rowIndex=1;rowIndex<=noOfEntries;rowIndex++){
    +            Row row;
    +                row=chartOfAccountsSheet.getRow(rowIndex);
    +                if (ImportHandlerUtils.isNotImported(row, ChartOfAcountsConstants.STATUS_COL)){
    +                    glAccounts.add(readGlAccounts(row));
    +                }
    +        }
    +    }
    +
    +    private GLAccountData readGlAccounts(Row row) {
    +        String accountType=ImportHandlerUtils.readAsString(ChartOfAcountsConstants.ACCOUNT_TYPE_COL,row);
    +        Long accountTypeId=null;
    +        EnumOptionData accountTypeEnum=null;
    +        if (accountType!=null && accountType.equalsIgnoreCase(GLAccountType.ASSET.toString())){
    +            accountTypeId=1L;
    +            accountTypeEnum=new EnumOptionData(accountTypeId,null,null);
    +        }else if(accountType!=null && accountType.equalsIgnoreCase(GLAccountType.LIABILITY.toString())){
    +            accountTypeId=2L;
    +            accountTypeEnum=new EnumOptionData(accountTypeId,null,null);
    +        }else if(accountType!=null && accountType.equalsIgnoreCase(GLAccountType.EQUITY.toString())){
    +            accountTypeId=3L;
    +            accountTypeEnum=new EnumOptionData(accountTypeId,null,null);
    +        }
    +        else if(accountType!=null && accountType.equalsIgnoreCase(GLAccountType.INCOME.toString())){
    +            accountTypeId=4L;
    +            accountTypeEnum=new EnumOptionData(accountTypeId,null,null);
    +        }else if(accountType!=null && accountType.equalsIgnoreCase(GLAccountType.EXPENSE.toString())){
    +            accountTypeId=5L;
    +            accountTypeEnum=new EnumOptionData(accountTypeId,null,null);
    +        }
    --- End diff --
    
    Move this code to GLAccountType new function fromString which will return the accountTypeEnum.


---

Mime
View raw message