BLasan commented on a change in pull request #1890:
URL: https://github.com/apache/fineract/pull/1890#discussion_r727510412
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/chartofaccounts/ChartOfAccountsImportHandler.java
##########
@@ -109,44 +136,137 @@ private GLAccountData readGlAccounts(Row row) {
tagIdCodeValueData = new CodeValueData(tagId);
}
String description =
ImportHandlerUtils.readAsString(ChartOfAcountsConstants.DESCRIPTION_COL, row);
+ if
(ImportHandlerUtils.readAsString(ChartOfAcountsConstants.OFFICE_COL, row) !=
null) {
+ flagForOpBal = 1;
+ } else {
+ flagForOpBal = 0;
+ }
return GLAccountData.importInstance(accountName, parentId, glCode,
manualEntriesAllowed, accountTypeEnum, usageEnum, description,
tagIdCodeValueData, row.getRowNum());
}
- public Count importEntity() {
+ public Count importEntity(String dateFormat) {
Review comment:
Are we reassigning the parameter?
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/GLAccountRepository.java
##########
@@ -18,9 +18,12 @@
*/
package org.apache.fineract.accounting.glaccount.domain;
+import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface GLAccountRepository extends JpaRepository<GLAccount, Long>,
JpaSpecificationExecutor<GLAccount> {
// no added behaviour
+ //adding behaviour to fetch id by glcode for opening balance bulk import
+ Optional<GLAccount> findOneByGlCode(String glCode);
Review comment:
What's the exact use of `Optional` here since we're throwing a
`GLAccountNotFoundException` exception in `findOneByGlCode` ?
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/chartofaccounts/ChartOfAccountsWorkbook.java
##########
@@ -108,38 +129,48 @@ private void setRules(Sheet chartOfAccountsSheet) {
DataValidationConstraint parentConstraint = validationHelper
.createFormulaListConstraint("INDIRECT(CONCATENATE(\"AccountName_\",$A1))");
DataValidationConstraint tagConstraint =
validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Tags_\",$A1))");
+ DataValidationConstraint officeNameConstraint =
validationHelper.createFormulaListConstraint("Office");
+ DataValidationConstraint currencyCodeConstraint =
validationHelper.createExplicitListConstraint(getCurrency());
DataValidation accountTypeValidation =
validationHelper.createValidation(accountTypeConstraint, accountTypeRange);
DataValidation accountUsageValidation =
validationHelper.createValidation(accountUsageConstraint, accountUsageRange);
DataValidation manualEntriesValidation =
validationHelper.createValidation(booleanConstraint, manualEntriesAllowedRange);
DataValidation parentValidation =
validationHelper.createValidation(parentConstraint, parentRange);
DataValidation tagValidation =
validationHelper.createValidation(tagConstraint, tagRange);
+ DataValidation officeNameValidation =
validationHelper.createValidation(officeNameConstraint, officeNameRange);
+ DataValidation currencyCodeValidation =
validationHelper.createValidation(currencyCodeConstraint, currencyCodeRange);
chartOfAccountsSheet.addValidationData(accountTypeValidation);
chartOfAccountsSheet.addValidationData(accountUsageValidation);
chartOfAccountsSheet.addValidationData(manualEntriesValidation);
chartOfAccountsSheet.addValidationData(parentValidation);
chartOfAccountsSheet.addValidationData(tagValidation);
+ chartOfAccountsSheet.addValidationData(officeNameValidation);
+ chartOfAccountsSheet.addValidationData(currencyCodeValidation);
}
- private void setNames(Sheet chartOfAccountsSheet, List<String>
accountTypesNoDuplicatesList) {
+ private void setNames(Sheet chartOfAccountsSheet, List<String>
accountTypesNoDuplicatesList, List<OfficeData> offices) {
Review comment:
Make parameters `final` if not reassigning
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/chartofaccounts/ChartOfAccountsImportHandler.java
##########
@@ -53,24 +63,40 @@
private static final Logger LOG =
LoggerFactory.getLogger(ChartOfAccountsImportHandler.class);
private List<GLAccountData> glAccounts;
private Workbook workbook;
+ private LocalDate transactionDate;
+
+ // for opening bal
+ int flagForOpBal = 0;
+ private List<JournalEntryData> gltransaction;
+ List<CreditDebit> credits = new ArrayList<>();
+ List<CreditDebit> debits = new ArrayList<>();
+ String locale;
private final PortfolioCommandSourceWritePlatformService
commandsSourceWritePlatformService;
+ private final GLAccountRepositoryWrapper glAccountRepository;
@Autowired
- public ChartOfAccountsImportHandler(final
PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
+ public ChartOfAccountsImportHandler(final
PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
+ GLAccountRepositoryWrapper glAccountRepository) {
this.commandsSourceWritePlatformService =
commandsSourceWritePlatformService;
+ this.glAccountRepository = glAccountRepository;
}
@Override
public Count process(Workbook workbook, String locale, String dateFormat) {
Review comment:
`final String dateFormat` ?
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/chartofaccounts/ChartOfAccountsWorkbook.java
##########
@@ -108,38 +129,48 @@ private void setRules(Sheet chartOfAccountsSheet) {
DataValidationConstraint parentConstraint = validationHelper
.createFormulaListConstraint("INDIRECT(CONCATENATE(\"AccountName_\",$A1))");
DataValidationConstraint tagConstraint =
validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Tags_\",$A1))");
+ DataValidationConstraint officeNameConstraint =
validationHelper.createFormulaListConstraint("Office");
+ DataValidationConstraint currencyCodeConstraint =
validationHelper.createExplicitListConstraint(getCurrency());
DataValidation accountTypeValidation =
validationHelper.createValidation(accountTypeConstraint, accountTypeRange);
DataValidation accountUsageValidation =
validationHelper.createValidation(accountUsageConstraint, accountUsageRange);
DataValidation manualEntriesValidation =
validationHelper.createValidation(booleanConstraint, manualEntriesAllowedRange);
DataValidation parentValidation =
validationHelper.createValidation(parentConstraint, parentRange);
DataValidation tagValidation =
validationHelper.createValidation(tagConstraint, tagRange);
+ DataValidation officeNameValidation =
validationHelper.createValidation(officeNameConstraint, officeNameRange);
+ DataValidation currencyCodeValidation =
validationHelper.createValidation(currencyCodeConstraint, currencyCodeRange);
chartOfAccountsSheet.addValidationData(accountTypeValidation);
chartOfAccountsSheet.addValidationData(accountUsageValidation);
chartOfAccountsSheet.addValidationData(manualEntriesValidation);
chartOfAccountsSheet.addValidationData(parentValidation);
chartOfAccountsSheet.addValidationData(tagValidation);
+ chartOfAccountsSheet.addValidationData(officeNameValidation);
+ chartOfAccountsSheet.addValidationData(currencyCodeValidation);
}
- private void setNames(Sheet chartOfAccountsSheet, List<String>
accountTypesNoDuplicatesList) {
+ private void setNames(Sheet chartOfAccountsSheet, List<String>
accountTypesNoDuplicatesList, List<OfficeData> offices) {
Workbook chartOfAccountsWorkbook = chartOfAccountsSheet.getWorkbook();
for (Integer i = 0; i < accountTypesNoDuplicatesList.size(); i++) {
Name tags = chartOfAccountsWorkbook.createName();
Integer[] tagValueBeginEndIndexes =
accountTypeToBeginEndIndexesofAccountNames.get(i);
if (accountTypeToBeginEndIndexesofAccountNames != null) {
setSanitized(tags, "Tags_" +
accountTypesNoDuplicatesList.get(i));
-
tags.setRefersToFormula(TemplatePopulateImportConstants.CHART_OF_ACCOUNTS_SHEET_NAME
+ "!$S$" + tagValueBeginEndIndexes[0]
- + ":$S$" + tagValueBeginEndIndexes[1]);
+
tags.setRefersToFormula(TemplatePopulateImportConstants.CHART_OF_ACCOUNTS_SHEET_NAME
+ "!$V$" + tagValueBeginEndIndexes[0]
+ + ":$V$" + tagValueBeginEndIndexes[1]);
}
Name accountNames = chartOfAccountsWorkbook.createName();
Integer[] accountNamesBeginEndIndexes =
accountTypeToBeginEndIndexesofAccountNames.get(i);
if (accountNamesBeginEndIndexes != null) {
setSanitized(accountNames, "AccountName_" +
accountTypesNoDuplicatesList.get(i));
-
accountNames.setRefersToFormula(TemplatePopulateImportConstants.CHART_OF_ACCOUNTS_SHEET_NAME
+ "!$Q$"
- + accountNamesBeginEndIndexes[0] + ":$Q$" +
accountNamesBeginEndIndexes[1]);
+
accountNames.setRefersToFormula(TemplatePopulateImportConstants.CHART_OF_ACCOUNTS_SHEET_NAME
+ "!$T$"
+ + accountNamesBeginEndIndexes[0] + ":$T$" +
accountNamesBeginEndIndexes[1]);
}
}
+ Name officeGroup = chartOfAccountsWorkbook.createName();
+ officeGroup.setNameName("Office");
+
officeGroup.setRefersToFormula(TemplatePopulateImportConstants.CHART_OF_ACCOUNTS_SHEET_NAME
+ "!$X$2:$X$" + (offices.size() + 1));
+
}
private void setDefaults(Sheet worksheet) {
Review comment:
Same as above
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/chartofaccounts/ChartOfAccountsImportHandler.java
##########
@@ -109,44 +136,137 @@ private GLAccountData readGlAccounts(Row row) {
tagIdCodeValueData = new CodeValueData(tagId);
}
String description =
ImportHandlerUtils.readAsString(ChartOfAcountsConstants.DESCRIPTION_COL, row);
+ if
(ImportHandlerUtils.readAsString(ChartOfAcountsConstants.OFFICE_COL, row) !=
null) {
+ flagForOpBal = 1;
+ } else {
+ flagForOpBal = 0;
+ }
return GLAccountData.importInstance(accountName, parentId, glCode,
manualEntriesAllowed, accountTypeEnum, usageEnum, description,
tagIdCodeValueData, row.getRowNum());
}
- public Count importEntity() {
+ public Count importEntity(String dateFormat) {
Sheet chartOfAccountsSheet =
workbook.getSheet(TemplatePopulateImportConstants.CHART_OF_ACCOUNTS_SHEET_NAME);
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(EnumOptionData.class, new
EnumOptionDataIdSerializer());
gsonBuilder.registerTypeAdapter(CodeValueData.class, new
CodeValueDataIdSerializer());
+ gsonBuilder.registerTypeAdapter(LocalDate.class, new
DateSerializer(dateFormat));
+ gsonBuilder.registerTypeAdapter(CurrencyData.class, new
CurrencyDateCodeSerializer());
int successCount = 0;
int errorCount = 0;
String errorMessage = "";
- for (GLAccountData glAccount : glAccounts) {
- try {
- String payload = gsonBuilder.create().toJson(glAccount);
- final CommandWrapper commandRequest = new
CommandWrapperBuilder() //
- .createGLAccount() //
- .withJson(payload) //
- .build(); //
- final CommandProcessingResult result =
commandsSourceWritePlatformService.logCommandSource(commandRequest);
- successCount++;
- Cell statusCell =
chartOfAccountsSheet.getRow(glAccount.getRowIndex()).createCell(ChartOfAcountsConstants.STATUS_COL);
-
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
-
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook,
IndexedColors.LIGHT_GREEN));
- } catch (RuntimeException ex) {
- errorCount++;
- LOG.error("Problem occurred in importEntity function", ex);
- errorMessage = ImportHandlerUtils.getErrorMessage(ex);
- ImportHandlerUtils.writeErrorMessage(chartOfAccountsSheet,
glAccount.getRowIndex(), errorMessage,
- ChartOfAcountsConstants.STATUS_COL);
+
+ if (glAccounts != null) {
+ for (GLAccountData glAccount : glAccounts) {
+ try {
+ String payload = gsonBuilder.create().toJson(glAccount);
+ final CommandWrapper commandRequest = new
CommandWrapperBuilder() //
+ .createGLAccount() //
+ .withJson(payload) //
+ .build(); //
+ final CommandProcessingResult result =
commandsSourceWritePlatformService.logCommandSource(commandRequest);
+ successCount++;
+ Cell statusCell =
chartOfAccountsSheet.getRow(glAccount.getRowIndex()).createCell(ChartOfAcountsConstants.STATUS_COL);
+
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
+
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook,
IndexedColors.LIGHT_GREEN));
+ } catch (RuntimeException ex) {
+ errorCount++;
+ LOG.error("Problem occurred in importEntity function", ex);
+ errorMessage = ImportHandlerUtils.getErrorMessage(ex);
+ ImportHandlerUtils.writeErrorMessage(chartOfAccountsSheet,
glAccount.getRowIndex(), errorMessage,
+ ChartOfAcountsConstants.STATUS_COL);
+ }
+ }
+ if (flagForOpBal > 0) {
+
+ try {
+ readExcelFileForOpBal(locale, dateFormat);
+ JournalEntryData transaction =
gltransaction.get(gltransaction.size() - 1);
+ String payload = gsonBuilder.create().toJson(transaction);
+
+ final CommandWrapper commandRequest = new
CommandWrapperBuilder().defineOpeningBalanceForJournalEntry()
+ .withJson(payload).build();
+ final CommandProcessingResult result =
commandsSourceWritePlatformService.logCommandSource(commandRequest);
+ successCount++;
+ Cell statusCell =
chartOfAccountsSheet.getRow(1).createCell(ChartOfAcountsConstants.STATUS_COL);
+
statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED);
+
statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook,
IndexedColors.LIGHT_GREEN));
+ } catch (RuntimeException ex) {
+ errorCount++;
+ LOG.error("Problem occurred in importEntity function", ex);
+ errorMessage = ImportHandlerUtils.getErrorMessage(ex);
+ ImportHandlerUtils.writeErrorMessage(chartOfAccountsSheet,
1, errorMessage, ChartOfAcountsConstants.STATUS_COL);
+ }
}
+
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.STATUS_COL,
TemplatePopulateImportConstants.SMALL_COL_SIZE);
+ ImportHandlerUtils.writeString(ChartOfAcountsConstants.STATUS_COL,
+
chartOfAccountsSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX),
+ TemplatePopulateImportConstants.STATUS_COLUMN_HEADER);
+ return Count.instance(successCount, errorCount);
}
+
chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.STATUS_COL,
TemplatePopulateImportConstants.SMALL_COL_SIZE);
ImportHandlerUtils.writeString(ChartOfAcountsConstants.STATUS_COL,
chartOfAccountsSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX),
TemplatePopulateImportConstants.STATUS_COLUMN_HEADER);
return Count.instance(successCount, errorCount);
+
}
+ // for opening balance
+ public void readExcelFileForOpBal(final String locale, final String
dateFormat) {
+
+ 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);
+
+ //
+ JournalEntryData journalEntry = null;
+ journalEntry = readAddJournalEntries(row, locale, dateFormat);
+ gltransaction.add(journalEntry);
+ }
+
+ }
+
+ // for opening balance
+ private JournalEntryData readAddJournalEntries(Row row, String locale,
String dateFormat) {
+ LocalDate transactionDateCheck = LocalDate.now(ZoneId.systemDefault());
+ if (transactionDateCheck != null) {
+ transactionDate = transactionDateCheck;
+ }
+
+ String officeName =
ImportHandlerUtils.readAsString(ChartOfAcountsConstants.OFFICE_COL, row);
+ Long officeId =
ImportHandlerUtils.readAsLong(ChartOfAcountsConstants.OFFICE_COL_ID, row);
+
+ String currencyCode =
ImportHandlerUtils.readAsString(ChartOfAcountsConstants.CURRENCY_CODE, row);
+ String accountToBeDebitedCredited =
ImportHandlerUtils.readAsString(ChartOfAcountsConstants.ACCOUNT_NAME_COL, row);
+ String glCode =
ImportHandlerUtils.readAsString(ChartOfAcountsConstants.GL_CODE_COL, row);
+ GLAccount glAccount =
this.glAccountRepository.findOneByGlCodeWithNotFoundDetection(glCode);
+ Long glAccountIdToDebitedCredited = glAccount.getId();
+ if (glAccountIdToDebitedCredited == null) {
+ throw new RuntimeException("Account does not exist");
+ }
+
+ // String credit =
Review comment:
Is this needed?
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/JournalEntryData.java
##########
@@ -98,6 +140,11 @@ public static JournalEntryData importInstance(Long
officeId, LocalDate transacti
checkNumber, routingCode, receiptNumber, bankNumber, comments,
locale, dateFormat);
}
+ public static JournalEntryData importInstance1(Long officeId, LocalDate
transactionDate, String currencyCode, List<CreditDebit> credits,
Review comment:
Make parameters final
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]