From 210647d4158f8bffe49708a22efebd0ab500244e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 6 Dec 2017 18:32:51 +0530 Subject: [PATCH] all modules populate & import --- fineract-provider/dependencies.gradle | 2 +- fineract-provider/dev-dependencies.gradle | 2 +- .../client/ClientEntityImportHandlerTest.java | 147 ++++ .../loan/LoanImportHandlerTest.java | 177 +++++ .../office/OfficeImportHandlerTest.java | 102 +++ .../savings/SavingsImportHandlerTest.java | 156 ++++ .../ClientEntityWorkbookPopulatorTest.java | 83 +++ .../loan/LoanWorkbookPopulatorTest.java | 129 ++++ .../office/OfficeWorkBookPopulatorTest.java | 64 ++ .../savings/SavingsWorkbookPopulateTest.java | 112 +++ .../integrationtests/common/ClientHelper.java | 33 + .../integrationtests/common/OfficeHelper.java | 33 + .../integrationtests/common/Utils.java | 40 +- .../common/loans/LoanTransactionHelper.java | 36 + .../common/savings/SavingsAccountHelper.java | 33 + .../common/savings/SavingsProductHelper.java | 2 +- .../glaccount/api/GLAccountsApiResource.java | 35 +- .../glaccount/data/GLAccountData.java | 50 ++ .../glaccount/domain/GLAccountType.java | 23 + .../GLAccountReadPlatformServiceImpl.java | 12 +- .../api/JournalEntriesApiResource.java | 37 +- .../journalentry/data/CreditDebit.java | 31 + .../journalentry/data/JournalEntryData.java | 87 +++ .../bulkimport/api/BulkImportApiResource.java | 114 +++ .../bulkimport/constants/CenterConstants.java | 51 ++ .../constants/ChartOfAcountsConstants.java | 38 + .../constants/ClientEntityConstants.java | 61 ++ .../constants/ClientPersonConstants.java | 58 ++ .../constants/FixedDepositConstants.java | 55 ++ .../bulkimport/constants/GroupConstants.java | 47 ++ .../constants/GuarantorConstants.java | 45 ++ .../constants/JournalEntryConstants.java | 49 ++ .../bulkimport/constants/LoanConstants.java | 75 ++ .../constants/LoanRepaymentConstants.java | 44 ++ .../bulkimport/constants/OfficeConstants.java | 33 + .../constants/RecurringDepositConstants.java | 60 ++ .../constants/SavingsConstants.java | 57 ++ .../constants/SharedAccountsConstants.java | 45 ++ .../bulkimport/constants/StaffConstants.java | 32 + .../TemplatePopulateImportConstants.java | 143 ++++ .../constants/TransactionConstants.java | 43 ++ .../bulkimport/constants/UserConstants.java | 34 + .../bulkimport/data/BulkImportEvent.java | 71 ++ .../infrastructure/bulkimport/data/Count.java | 45 ++ .../bulkimport/data/GlobalEntityType.java | 118 +++ .../bulkimport/data/ImportData.java | 80 +++ .../bulkimport/data/ImportFormatType.java | 49 ++ .../bulkimport/domain/ImportDocument.java | 124 ++++ .../domain/ImportDocumentRepository.java | 27 + .../ImportTypeNotFoundException.java | 29 + .../importhandler/ImportHandler.java | 27 + .../importhandler/ImportHandlerUtils.java | 355 +++++++++ .../center/CenterImportHandler.java | 259 +++++++ .../ChartOfAccountsImportHandler.java | 143 ++++ .../client/ClientEntityImportHandler.java | 212 ++++++ .../client/ClientPersonImportHandler.java | 197 +++++ .../FixedDepositImportHandler.java | 390 ++++++++++ .../FixedDepositTransactionImportHandler.java | 150 ++++ .../group/GroupImportHandler.java | 257 +++++++ .../guarantor/GuarantorImportHandler.java | 151 ++++ .../helper/ClientIdSerializer.java | 38 + .../helper/CodeValueDataIdSerializer.java | 34 + .../helper/CurrencyDateCodeSerializer.java | 34 + .../importhandler/helper/DateSerializer.java | 41 ++ .../helper/EnumOptionDataIdSerializer.java | 34 + .../helper/EnumOptionDataValueSerializer.java | 34 + .../helper/GroupIdSerializer.java | 37 + ...AccountTransactionEnumValueSerialiser.java | 35 + .../JournalEntriesImportHandler.java | 226 ++++++ .../importhandler/loan/LoanImportHandler.java | 464 ++++++++++++ .../LoanRepaymentImportHandler.java | 134 ++++ .../office/OfficeImportHandler.java | 123 ++++ .../RecurringDepositImportHandler.java | 372 ++++++++++ ...urringDepositTransactionImportHandler.java | 157 ++++ .../savings/SavingsImportHandler.java | 364 ++++++++++ .../SavingsTransactionImportHandler.java | 152 ++++ .../SharedAccountImportHandler.java | 174 +++++ .../staff/StaffImportHandler.java | 124 ++++ .../users/UserImportHandler.java | 137 ++++ .../populator/AbstractWorkbookPopulator.java | 161 +++++ .../populator/CenterSheetPopulator.java | 123 ++++ .../populator/ClientSheetPopulator.java | 144 ++++ .../populator/ExtrasSheetPopulator.java | 116 +++ .../FixedDepositProductSheetPopulator.java | 173 +++++ .../populator/GlAccountSheetPopulator.java | 71 ++ .../populator/GroupSheetPopulator.java | 126 ++++ .../populator/LoanProductSheetPopulator.java | 199 ++++++ .../populator/OfficeSheetPopulator.java | 82 +++ .../populator/PersonnelSheetPopulator.java | 131 ++++ ...RecurringDepositProductSheetPopulator.java | 190 +++++ .../populator/RoleSheetPopulator.java | 67 ++ .../SavingsAccountSheetPopulator.java | 84 +++ .../SavingsProductSheetPopulator.java | 136 ++++ .../SharedProductsSheetPopulator.java | 159 +++++ .../populator/WorkbookPopulator.java | 27 + .../centers/CentersWorkbookPopulator.java | 235 ++++++ .../ChartOfAccountsWorkbook.java | 236 ++++++ .../client/ClientEntityWorkbookPopulator.java | 405 +++++++++++ .../client/ClientPersonWorkbookPopulator.java | 370 ++++++++++ .../LoanComparatorByStatusActive.java | 52 ++ ...edDepositTransactionWorkbookPopulator.java | 235 ++++++ .../FixedDepositWorkbookPopulator.java | 349 +++++++++ .../group/GroupsWorkbookPopulator.java | 254 +++++++ .../guarantor/GuarantorWorkbookPopulator.java | 314 ++++++++ .../JournalEntriesWorkbookPopulator.java | 191 +++++ .../populator/loan/LoanWorkbookPopulator.java | 565 +++++++++++++++ .../LoanRepaymentWorkbookPopulator.java | 277 +++++++ .../office/OfficeWorkbookPopulator.java | 114 +++ ...ngDepositTransactionWorkbookPopulator.java | 242 +++++++ .../RecurringDepositWorkbookPopulator.java | 404 +++++++++++ .../SavingsTransactionsWorkbookPopulator.java | 240 +++++++ .../savings/SavingsWorkbookPopulator.java | 411 +++++++++++ .../SharedAccountWorkBookPopulator.java | 240 +++++++ .../staff/StaffWorkbookPopulator.java | 120 ++++ .../users/UserWorkbookPopulator.java | 133 ++++ .../service/BulkImportEventListener.java | 174 +++++ .../BulkImportWorkbookPopulatorService.java | 26 + ...ulkImportWorkbookPopulatorServiceImpl.java | 674 ++++++++++++++++++ .../service/BulkImportWorkbookService.java | 40 ++ .../BulkImportWorkbookServiceImpl.java | 296 ++++++++ .../codes/data/CodeValueData.java | 9 + .../PaginationParametersDataValidator.java | 35 +- .../service/DocumentWritePlatformService.java | 5 + ...WritePlatformServiceJpaRepositoryImpl.java | 18 +- .../monetary/data/CurrencyData.java | 14 + .../office/api/OfficesApiResource.java | 34 +- .../organisation/office/data/OfficeData.java | 31 + .../OfficeReadPlatformServiceImpl.java | 16 +- .../staff/api/StaffApiResource.java | 36 +- .../organisation/staff/data/StaffData.java | 36 + .../service/StaffReadPlatformServiceImpl.java | 16 +- .../accounts/api/AccountsApiResource.java | 35 +- .../portfolio/address/data/AddressData.java | 32 + .../portfolio/calendar/data/CalendarData.java | 121 +++- .../portfolio/charge/data/ChargeData.java | 12 + .../client/api/ClientApiConstants.java | 1 + .../client/api/ClientsApiResource.java | 33 +- .../portfolio/client/data/ClientData.java | 219 ++++++ .../client/data/ClientNonPersonData.java | 26 + .../ClientReadPlatformServiceImpl.java | 45 +- .../portfolio/fund/data/FundData.java | 8 + .../group/api/CentersApiResource.java | 32 +- .../group/api/GroupsApiResource.java | 36 +- .../portfolio/group/data/CenterData.java | 54 ++ .../group/data/GroupGeneralData.java | 99 +++ .../CenterReadPlatformServiceImpl.java | 107 +-- .../service/GroupReadPlatformServiceImpl.java | 108 +-- .../loanaccount/api/LoansApiResource.java | 53 +- .../loanaccount/data/DisbursementData.java | 33 + .../loanaccount/data/LoanAccountData.java | 392 ++++++++++ .../loanaccount/data/LoanApprovalData.java | 22 + .../loanaccount/data/LoanTransactionData.java | 111 +++ .../guarantor/api/GuarantorsApiResource.java | 34 +- .../guarantor/data/GuarantorData.java | 64 ++ .../service/LoanReadPlatformServiceImpl.java | 66 +- .../loanproduct/data/LoanProductData.java | 24 + .../paymenttype/data/PaymentTypeData.java | 8 + .../api/FixedDepositAccountsApiResource.java | 53 +- .../RecurringDepositAccountsApiResource.java | 54 +- .../api/SavingsAccountsApiResource.java | 53 +- .../data/ClosingOfSavingsAccounts.java | 102 +++ .../savings/data/DepositAccountData.java | 53 ++ .../savings/data/DepositProductData.java | 47 +- .../savings/data/FixedDepositAccountData.java | 64 ++ .../savings/data/FixedDepositProductData.java | 48 ++ .../data/RecurringDepositAccountData.java | 77 ++ .../data/RecurringDepositProductData.java | 59 ++ ...SavingsAccountApplicationTimelineData.java | 4 + .../data/SavingsAccountChargeData.java | 25 + .../savings/data/SavingsAccountData.java | 221 +++++- .../data/SavingsAccountTransactionData.java | 68 ++ .../savings/data/SavingsActivation.java | 60 ++ .../savings/data/SavingsApproval.java | 67 ++ .../savings/data/SavingsProductData.java | 58 +- .../savings/domain/DepositTermDetail.java | 1 + ...SavingsAccountReadPlatformServiceImpl.java | 54 +- .../data/ShareAccountChargeData.java | 21 + .../shareaccounts/data/ShareAccountData.java | 71 ++ .../api/UsersApiResource.java | 58 +- .../useradministration/data/AppUserData.java | 40 ++ .../useradministration/data/RoleData.java | 8 + .../core_db/V336__m_import_document.sql | 39 + 182 files changed, 19662 insertions(+), 262 deletions(-) create mode 100644 fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/client/ClientEntityImportHandlerTest.java create mode 100644 fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/loan/LoanImportHandlerTest.java create mode 100644 fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/office/OfficeImportHandlerTest.java create mode 100644 fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/savings/SavingsImportHandlerTest.java create mode 100644 fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/client/ClientEntityWorkbookPopulatorTest.java create mode 100644 fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/loan/LoanWorkbookPopulatorTest.java create mode 100644 fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/office/OfficeWorkBookPopulatorTest.java create mode 100644 fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/savings/SavingsWorkbookPopulateTest.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/CreditDebit.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/api/BulkImportApiResource.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/CenterConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/ChartOfAcountsConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/ClientEntityConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/ClientPersonConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/FixedDepositConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/GroupConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/GuarantorConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/JournalEntryConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/LoanConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/LoanRepaymentConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/OfficeConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/RecurringDepositConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/SavingsConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/SharedAccountsConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/StaffConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/TemplatePopulateImportConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/TransactionConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/UserConstants.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/BulkImportEvent.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/Count.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/GlobalEntityType.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/ImportData.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/ImportFormatType.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/domain/ImportDocument.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/domain/ImportDocumentRepository.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/exceptions/ImportTypeNotFoundException.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/ImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/ImportHandlerUtils.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/center/CenterImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/chartofaccounts/ChartOfAccountsImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientEntityImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientPersonImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/fixeddeposits/FixedDepositImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/fixeddeposits/FixedDepositTransactionImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/group/GroupImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/guarantor/GuarantorImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/ClientIdSerializer.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CodeValueDataIdSerializer.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CurrencyDateCodeSerializer.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/DateSerializer.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataIdSerializer.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataValueSerializer.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/GroupIdSerializer.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/SavingsAccountTransactionEnumValueSerialiser.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/journalentry/JournalEntriesImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loan/LoanImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/loanrepayment/LoanRepaymentImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/office/OfficeImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/recurringdeposit/RecurringDepositImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/recurringdeposit/RecurringDepositTransactionImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsTransactionImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/sharedaccount/SharedAccountImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/staff/StaffImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/users/UserImportHandler.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/AbstractWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/CenterSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ClientSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ExtrasSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/FixedDepositProductSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/GlAccountSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/GroupSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/LoanProductSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/OfficeSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/PersonnelSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/RecurringDepositProductSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/RoleSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SavingsAccountSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SavingsProductSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SharedProductsSheetPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/WorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/centers/CentersWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/chartofaccounts/ChartOfAccountsWorkbook.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/client/ClientEntityWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/client/ClientPersonWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/comparator/LoanComparatorByStatusActive.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/fixeddeposits/FixedDepositTransactionWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/fixeddeposits/FixedDepositWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/group/GroupsWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/guarantor/GuarantorWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/journalentry/JournalEntriesWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loan/LoanWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loanrepayment/LoanRepaymentWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/office/OfficeWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/recurringdeposit/RecurringDepositTransactionWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/recurringdeposit/RecurringDepositWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/savings/SavingsTransactionsWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/savings/SavingsWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/shareaccount/SharedAccountWorkBookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/staff/StaffWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/users/UserWorkbookPopulator.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportEventListener.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorService.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorServiceImpl.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookService.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookServiceImpl.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/ClosingOfSavingsAccounts.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsActivation.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsApproval.java create mode 100644 fineract-provider/src/main/resources/sql/migrations/core_db/V336__m_import_document.sql diff --git a/fineract-provider/dependencies.gradle b/fineract-provider/dependencies.gradle index 562e76784..27a256c4b 100644 --- a/fineract-provider/dependencies.gradle +++ b/fineract-provider/dependencies.gradle @@ -85,7 +85,7 @@ dependencies { [group: 'net.sf.ehcache', name: 'ehcache', version: '2.7.2'], [group: 'com.github.spullara.mustache.java', name: 'compiler', version: '0.8.12'], [group: 'com.jayway.jsonpath', name: 'json-path', version: '0.9.1'], - + [group: 'org.apache.tika', name: 'tika-core', version :'1.9'], // Although fineract (at the time of writing) doesn't have any compile time dep. on this, // it's useful to have this for the Spring Boot TestRestTemplate http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-rest-templates-test-utility [group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.5'], diff --git a/fineract-provider/dev-dependencies.gradle b/fineract-provider/dev-dependencies.gradle index 80c8f490e..710314d0d 100644 --- a/fineract-provider/dev-dependencies.gradle +++ b/fineract-provider/dev-dependencies.gradle @@ -84,7 +84,7 @@ dependencies { [group: 'net.sf.ehcache', name: 'ehcache', version: '2.7.2'], [group: 'com.github.spullara.mustache.java', name: 'compiler', version: '0.8.12'], [group: 'com.jayway.jsonpath', name: 'json-path', version: '0.9.1'], - + [group: 'org.apache.tika', name: 'tika-core', version :'1.9'], // Although fineract (at the time of writing) doesn't have any compile time dep. on this, // it's useful to have this for the Spring Boot TestRestTemplate http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-rest-templates-test-utility [group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.5'], diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/client/ClientEntityImportHandlerTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/client/ClientEntityImportHandlerTest.java new file mode 100644 index 000000000..b2038e8ae --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/client/ClientEntityImportHandlerTest.java @@ -0,0 +1,147 @@ +/** + * 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.integrationtests.bulkimport.importhandler.client; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.ClientEntityConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; +import org.apache.fineract.integrationtests.common.ClientHelper; +import org.apache.fineract.integrationtests.common.OfficeHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.organisation.StaffHelper; +import org.apache.fineract.integrationtests.common.system.CodeHelper; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.*; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class ClientEntityImportHandlerTest { + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + + @Test + public void testClientImport() throws InterruptedException, IOException, ParseException { + + //in order to populate helper sheets + StaffHelper staffHelper=new StaffHelper(); + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec); + Assert.assertNotNull("Could not create staff",outcome_staff_creation); + + //in order to populate helper sheets + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Integer outcome_office_creation=officeHelper.createOffice("02 May 2000"); + Assert.assertNotNull("Could not create office" ,outcome_office_creation); + + //in order to populate helper columns in client entity sheet + CodeHelper codeHelper=new CodeHelper(); + //create constitution + codeHelper.retrieveOrCreateCodeValue(24,requestSpec,responseSpec); + //create client classification + codeHelper.retrieveOrCreateCodeValue(17,requestSpec,responseSpec); + //create client types + codeHelper.retrieveOrCreateCodeValue(16,requestSpec,responseSpec); + //create Address types + codeHelper.retrieveOrCreateCodeValue(29,requestSpec,responseSpec); + //create State + codeHelper.retrieveOrCreateCodeValue(27,requestSpec,responseSpec); + //create Country + codeHelper.retrieveOrCreateCodeValue(28,requestSpec,responseSpec); + //create Main business line + codeHelper.retrieveOrCreateCodeValue(25,requestSpec,responseSpec); + + ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec); + Workbook workbook=clientHelper.getClientEntityWorkbook(GlobalEntityType.CLIENTS_ENTTTY,"dd MMMM yyyy"); + + //insert dummy data into client entity sheet + Sheet clientEntitySheet = workbook.getSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME); + Row firstClientRow=clientEntitySheet.getRow(1); + firstClientRow.createCell(ClientEntityConstants.NAME_COL).setCellValue(Utils.randomNameGenerator("C_E_",6)); + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME); + firstClientRow.createCell(ClientEntityConstants.OFFICE_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(0).getStringCellValue()); + firstClientRow.createCell(ClientEntityConstants.STAFF_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(1).getStringCellValue()); + SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd MMMM yyyy"); + Date incoporationDate=simpleDateFormat.parse("14 May 2001"); + firstClientRow.createCell(ClientEntityConstants.INCOPORATION_DATE_COL).setCellValue(incoporationDate); + Date validTill=simpleDateFormat.parse("14 May 2019"); + firstClientRow.createCell(ClientEntityConstants.INCOPORATION_VALID_TILL_COL).setCellValue(validTill); + firstClientRow.createCell(ClientEntityConstants.MOBILE_NO_COL).setCellValue(Utils.randomNumberGenerator(7)); + firstClientRow.createCell(ClientEntityConstants.CLIENT_TYPE_COL).setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_CLIENT_TYPES).getStringCellValue()); + firstClientRow.createCell(ClientEntityConstants.CLIENT_CLASSIFICATION_COL).setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_CLIENT_CLASSIFICATION).getStringCellValue()); + firstClientRow.createCell(ClientEntityConstants.INCOPORATION_NUMBER_COL).setCellValue(Utils.randomNumberGenerator(6)); + firstClientRow.createCell(ClientEntityConstants.MAIN_BUSINESS_LINE).setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_MAIN_BUSINESS_LINE).getStringCellValue()); + firstClientRow.createCell(ClientEntityConstants.CONSTITUTION_COL).setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_CONSTITUTION_COL).getStringCellValue()); + firstClientRow.createCell(ClientEntityConstants.ACTIVE_COL).setCellValue("False"); + Date submittedDate=simpleDateFormat.parse("28 September 2017"); + firstClientRow.createCell(ClientEntityConstants.SUBMITTED_ON_COL).setCellValue(submittedDate); + firstClientRow.createCell(ClientEntityConstants.ADDRESS_ENABLED).setCellValue("False"); + + String currentdirectory = new File("").getAbsolutePath(); + File directory=new File(currentdirectory+"\\src\\integrationTest\\" + + "resources\\bulkimport\\importhandler\\client"); + if (!directory.exists()) + directory.mkdirs(); + File file= new File(directory+"\\ClientEntity.xls"); + OutputStream outputStream=new FileOutputStream(file); + workbook.write(outputStream); + outputStream.close(); + + String importDocumentId=clientHelper.importClientEntityTemplate(file); + file.delete(); + Assert.assertNotNull(importDocumentId); + + //Wait for the creation of output excel + Thread.sleep(3000); + + //check status column of output excel + String location=clientHelper.getOutputTemplateLocation(importDocumentId); + FileInputStream fileInputStream = new FileInputStream(location); + Workbook outputWorkbook=new HSSFWorkbook(fileInputStream); + Sheet outputClientEntitySheet = outputWorkbook.getSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME); + Row row= outputClientEntitySheet.getRow(1); + Assert.assertEquals("Imported",row.getCell(ClientEntityConstants.STATUS_COL).getStringCellValue()); + + } +} diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/loan/LoanImportHandlerTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/loan/LoanImportHandlerTest.java new file mode 100644 index 000000000..72ddeb8c0 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/loan/LoanImportHandlerTest.java @@ -0,0 +1,177 @@ +/** + * 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.integrationtests.bulkimport.importhandler.loan; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.ClientEntityConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.LoanConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.integrationtests.common.*; +import org.apache.fineract.integrationtests.common.funds.FundsResourceHandler; +import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder; +import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper; +import org.apache.fineract.integrationtests.common.organisation.StaffHelper; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.*; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class LoanImportHandlerTest { + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + + @Test + public void testLoanImport() throws InterruptedException, IOException, ParseException { + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + //in order to populate helper sheets + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Integer outcome_office_creation=officeHelper.createOffice("02 May 2000"); + Assert.assertNotNull("Could not create office" ,outcome_office_creation); + + //in order to populate helper sheets + ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec); + Integer outcome_client_creation=clientHelper.createClient(requestSpec,responseSpec); + Assert.assertNotNull("Could not create client" ,outcome_client_creation); + + //in order to populate helper sheets + GroupHelper groupHelper=new GroupHelper(requestSpec,responseSpec); + Integer outcome_group_creation=groupHelper.createGroup(requestSpec,responseSpec,true); + Assert.assertNotNull("Could not create group" ,outcome_group_creation); + + //in order to populate helper sheets + StaffHelper staffHelper=new StaffHelper(); + Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec); + Assert.assertNotNull("Could not create staff",outcome_staff_creation); + + LoanTransactionHelper loanTransactionHelper=new LoanTransactionHelper(requestSpec,responseSpec); + LoanProductTestBuilder loanProductTestBuilder=new LoanProductTestBuilder(); + String jsonLoanProduct=loanProductTestBuilder.build(null); + Integer outcome_lp_creaion=loanTransactionHelper.getLoanProductId(jsonLoanProduct); + Assert.assertNotNull("Could not create Loan Product" ,outcome_lp_creaion); + + FundsResourceHandler fundsResourceHandler=new FundsResourceHandler(); + String jsonFund="{\n" + + "\t\"name\": \""+Utils.randomNameGenerator("Fund_Name",9)+"\"\n" + + "}"; + Integer outcome_fund_creation=fundsResourceHandler.createFund(jsonFund,requestSpec,responseSpec); + Assert.assertNotNull("Could not create Fund" ,outcome_fund_creation); + + PaymentTypeHelper paymentTypeHelper=new PaymentTypeHelper(); + String name = PaymentTypeHelper.randomNameGenerator("P_T", 5); + String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15); + Boolean isCashPayment = true; + Integer position = 1; + Integer outcome_payment_creation= paymentTypeHelper.createPaymentType(requestSpec, responseSpec,name,description,isCashPayment,position); + Assert.assertNotNull("Could not create payment type" ,outcome_payment_creation); + + Workbook workbook=loanTransactionHelper.getLoanWorkbook("dd MMMM yyyy"); + + //insert dummy data into loan Sheet + Sheet loanSheet = workbook.getSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME); + Row firstLoanRow=loanSheet.getRow(1); + Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + firstLoanRow.createCell(LoanConstants.OFFICE_NAME_COL).setCellValue(officeSheet.getRow(1).getCell(1).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.LOAN_TYPE_COL).setCellValue("Individual"); + firstLoanRow.createCell(LoanConstants.CLIENT_NAME_COL).setCellValue(loanSheet.getRow(1).getCell(LoanConstants.LOOKUP_CLIENT_NAME_COL).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.CLIENT_EXTERNAL_ID).setCellValue(loanSheet.getRow(1).getCell(LoanConstants.LOOKUP_CLIENT_EXTERNAL_ID).getStringCellValue()); + Sheet loanProductSheet=workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME); + firstLoanRow.createCell(LoanConstants.PRODUCT_COL).setCellValue(loanProductSheet.getRow(1).getCell(1).getStringCellValue()); + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME); + firstLoanRow.createCell(LoanConstants.LOAN_OFFICER_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(1).getStringCellValue()); + SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd MMMM yyyy"); + Date date=simpleDateFormat.parse("13 May 2017"); + firstLoanRow.createCell(LoanConstants.SUBMITTED_ON_DATE_COL).setCellValue(date); + firstLoanRow.createCell(LoanConstants.APPROVED_DATE_COL).setCellValue(date); + firstLoanRow.createCell(LoanConstants.DISBURSED_DATE_COL).setCellValue(date); + Sheet extrasSheet=workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME); + firstLoanRow.createCell(LoanConstants.DISBURSED_PAYMENT_TYPE_COL).setCellValue(extrasSheet.getRow(1).getCell(3).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.FUND_NAME_COL).setCellValue(extrasSheet.getRow(1).getCell(1).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.PRINCIPAL_COL).setCellValue(loanProductSheet.getRow(1).getCell(3).getNumericCellValue()); + firstLoanRow.createCell(LoanConstants.NO_OF_REPAYMENTS_COL).setCellValue(loanProductSheet.getRow(1).getCell(6).getNumericCellValue()); + firstLoanRow.createCell(LoanConstants.REPAID_EVERY_COL).setCellValue(loanProductSheet.getRow(1).getCell(9).getNumericCellValue()); + firstLoanRow.createCell(LoanConstants.REPAID_EVERY_FREQUENCY_COL).setCellValue(loanProductSheet.getRow(1).getCell(10).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.LOAN_TERM_COL).setCellValue(loanProductSheet.getRow(1).getCell(8).getNumericCellValue()); + firstLoanRow.createCell(LoanConstants.LOAN_TERM_FREQUENCY_COL).setCellValue(loanProductSheet.getRow(1).getCell(10).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.NOMINAL_INTEREST_RATE_COL).setCellValue(loanProductSheet.getRow(1).getCell(11).getNumericCellValue()); + firstLoanRow.createCell(LoanConstants.NOMINAL_INTEREST_RATE_FREQUENCY_COL).setCellValue(loanProductSheet.getRow(1).getCell(14).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.AMORTIZATION_COL).setCellValue(loanProductSheet.getRow(1).getCell(15).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.INTEREST_METHOD_COL).setCellValue(loanProductSheet.getRow(1).getCell(16).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.INTEREST_CALCULATION_PERIOD_COL).setCellValue(loanProductSheet.getRow(1).getCell(17).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.ARREARS_TOLERANCE_COL).setCellValue(0); + firstLoanRow.createCell(LoanConstants.REPAYMENT_STRATEGY_COL).setCellValue(loanProductSheet.getRow(1).getCell(19).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.GRACE_ON_PRINCIPAL_PAYMENT_COL).setCellValue(0); + firstLoanRow.createCell(LoanConstants.GRACE_ON_INTEREST_PAYMENT_COL).setCellValue(0); + firstLoanRow.createCell(LoanConstants.GRACE_ON_INTEREST_CHARGED_COL).setCellValue(0); + firstLoanRow.createCell(LoanConstants.FIRST_REPAYMENT_COL).setCellValue(date); + firstLoanRow.createCell(LoanConstants.TOTAL_AMOUNT_REPAID_COL).setCellValue(6000); + firstLoanRow.createCell(LoanConstants.LAST_REPAYMENT_DATE_COL).setCellValue(date); + firstLoanRow.createCell(LoanConstants.REPAYMENT_TYPE_COL).setCellValue(extrasSheet.getRow(1).getCell(3).getStringCellValue()); + + String currentdirectory = new File("").getAbsolutePath(); + File directory=new File(currentdirectory+"\\src\\integrationTest\\" + + "resources\\bulkimport\\importhandler\\loan"); + if (!directory.exists()) + directory.mkdirs(); + File file= new File(directory+"\\Loan.xls"); + OutputStream outputStream=new FileOutputStream(file); + workbook.write(outputStream); + outputStream.close(); + + String importDocumentId=loanTransactionHelper.importLoanTemplate(file); + file.delete(); + Assert.assertNotNull(importDocumentId); + + //Wait for the creation of output excel + Thread.sleep(3000); + + //check status column of output excel + String location=loanTransactionHelper.getOutputTemplateLocation(importDocumentId); + FileInputStream fileInputStream = new FileInputStream(location); + Workbook Outputworkbook=new HSSFWorkbook(fileInputStream); + Sheet outputLoanSheet = Outputworkbook.getSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME); + Row row= outputLoanSheet.getRow(1); + Assert.assertEquals("Imported",row.getCell(LoanConstants.STATUS_COL).getStringCellValue()); + + } +} diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/office/OfficeImportHandlerTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/office/OfficeImportHandlerTest.java new file mode 100644 index 000000000..e4dd0aa83 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/office/OfficeImportHandlerTest.java @@ -0,0 +1,102 @@ +/** + * 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.integrationtests.bulkimport.importhandler.office; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.OfficeConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator; +import org.apache.fineract.integrationtests.common.OfficeHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.organisation.office.domain.Office; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.*; +import java.lang.reflect.Field; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class OfficeImportHandlerTest { + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup(){ + Utils.initializeRESTAssured(); + this.requestSpec=new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + + @Test + public void testOfficeImport() throws IOException, InterruptedException, NoSuchFieldException, ParseException { + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Workbook workbook=officeHelper.getOfficeWorkBook("dd MMMM yyyy"); + + //insert dummy data into excel + Sheet sheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + Row firstOfficeRow= sheet.getRow(1); + firstOfficeRow.createCell(OfficeConstants.OFFICE_NAME_COL).setCellValue(Utils.randomNameGenerator("Test_Off_",6)); + firstOfficeRow.createCell(OfficeConstants.PARENT_OFFICE_NAME_COL).setCellValue(firstOfficeRow.getCell(OfficeConstants.LOOKUP_OFFICE_COL).getStringCellValue()); + firstOfficeRow.createCell(OfficeConstants.PARENT_OFFICE_ID_COL).setCellValue(firstOfficeRow.getCell(OfficeConstants.LOOKUP_OFFICE_ID_COL).getNumericCellValue()); + SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd MMMM yyyy"); + Date date=simpleDateFormat.parse("14 May 2001"); + firstOfficeRow.createCell(OfficeConstants.OPENED_ON_COL).setCellValue(date); + + String currentdirectory = new File("").getAbsolutePath(); + File directory=new File(currentdirectory+"\\src\\integrationTest\\" + + "resources\\bulkimport\\importhandler\\office"); + if (!directory.exists()) + directory.mkdirs(); + File file= new File(directory+"\\Office.xls"); + OutputStream outputStream=new FileOutputStream(file); + workbook.write(outputStream); + outputStream.close(); + + String importDocumentId=officeHelper.importOfficeTemplate(file); + file.delete(); + Assert.assertNotNull(importDocumentId); + + // Wait for the creation of output excel + Thread.sleep(3000); + + //check status column of output excel + String location=officeHelper.getOutputTemplateLocation(importDocumentId); + FileInputStream fileInputStream = new FileInputStream(location); + Workbook outputWorkbook=new HSSFWorkbook(fileInputStream); + Sheet officeSheet = outputWorkbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + Row row= officeSheet.getRow(1); + Assert.assertEquals("Imported",row.getCell(OfficeConstants.STATUS_COL).getStringCellValue()); + + } +} diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/savings/SavingsImportHandlerTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/savings/SavingsImportHandlerTest.java new file mode 100644 index 000000000..c26594da6 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/savings/SavingsImportHandlerTest.java @@ -0,0 +1,156 @@ +/** + * 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.integrationtests.bulkimport.importhandler.savings; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.LoanConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.SavingsConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.integrationtests.common.ClientHelper; +import org.apache.fineract.integrationtests.common.GroupHelper; +import org.apache.fineract.integrationtests.common.OfficeHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper; +import org.apache.fineract.integrationtests.common.organisation.StaffHelper; +import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper; +import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper; +import org.apache.fineract.template.domain.Template; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.*; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class SavingsImportHandlerTest { + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + + @Test + public void testSavingsImport() throws InterruptedException, IOException, ParseException { + + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + //in order to populate helper sheets + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Integer outcome_office_creation=officeHelper.createOffice("02 May 2000"); + Assert.assertNotNull("Could not create office" ,outcome_office_creation); + + //in order to populate helper sheets + ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec); + Integer outcome_client_creation=clientHelper.createClient(requestSpec,responseSpec); + Assert.assertNotNull("Could not create client" ,outcome_client_creation); + + //in order to populate helper sheets + GroupHelper groupHelper=new GroupHelper(requestSpec,responseSpec); + Integer outcome_group_creation=groupHelper.createGroup(requestSpec,responseSpec,true); + Assert.assertNotNull("Could not create group" ,outcome_group_creation); + + //in order to populate helper sheets + StaffHelper staffHelper=new StaffHelper(); + Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec); + Assert.assertNotNull("Could not create staff",outcome_staff_creation); + + SavingsProductHelper savingsProductHelper=new SavingsProductHelper(); + String jsonSavingsProduct=savingsProductHelper.build(); + Integer outcome_sp_creaction=savingsProductHelper.createSavingsProduct(jsonSavingsProduct,requestSpec,responseSpec); + Assert.assertNotNull("Could not create Savings product",outcome_sp_creaction); + + SavingsAccountHelper savingsAccountHelper=new SavingsAccountHelper(requestSpec,responseSpec); + Workbook workbook=savingsAccountHelper.getSavingsWorkbook("dd MMMM yyyy"); + + //insert dummy data into Savings sheet + Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME); + Row firstSavingsRow=savingsSheet.getRow(1); + Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + firstSavingsRow.createCell(SavingsConstants.OFFICE_NAME_COL).setCellValue(officeSheet.getRow(1).getCell(1).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.SAVINGS_TYPE_COL).setCellValue("Individual"); + firstSavingsRow.createCell(SavingsConstants.CLIENT_NAME_COL).setCellValue(savingsSheet.getRow(1).getCell(SavingsConstants.LOOKUP_CLIENT_NAME_COL).getStringCellValue()); + Sheet savingsProductSheet=workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME); + firstSavingsRow.createCell(SavingsConstants.PRODUCT_COL).setCellValue(savingsProductSheet.getRow(1).getCell(1).getStringCellValue()); + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME); + firstSavingsRow.createCell(SavingsConstants.FIELD_OFFICER_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(1).getStringCellValue()); + SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd MMMM yyyy"); + Date date=simpleDateFormat.parse("13 May 2017"); + firstSavingsRow.createCell(SavingsConstants.SUBMITTED_ON_DATE_COL).setCellValue(date); + firstSavingsRow.createCell(SavingsConstants.APPROVED_DATE_COL).setCellValue(date); + firstSavingsRow.createCell(SavingsConstants.ACTIVATION_DATE_COL).setCellValue(date); + firstSavingsRow.createCell(SavingsConstants.CURRENCY_COL).setCellValue(savingsProductSheet.getRow(1).getCell(10).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.DECIMAL_PLACES_COL).setCellValue(savingsProductSheet.getRow(1).getCell(11).getNumericCellValue()); + firstSavingsRow.createCell(SavingsConstants.IN_MULTIPLES_OF_COL).setCellValue(savingsProductSheet.getRow(1).getCell(12).getNumericCellValue()); + firstSavingsRow.createCell(SavingsConstants.NOMINAL_ANNUAL_INTEREST_RATE_COL).setCellValue(savingsProductSheet.getRow(1).getCell(2).getNumericCellValue()); + firstSavingsRow.createCell(SavingsConstants.INTEREST_COMPOUNDING_PERIOD_COL).setCellValue(savingsProductSheet.getRow(1).getCell(3).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.INTEREST_POSTING_PERIOD_COL).setCellValue(savingsProductSheet.getRow(1).getCell(4).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.INTEREST_CALCULATION_COL).setCellValue(savingsProductSheet.getRow(1).getCell(5).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL).setCellValue(savingsProductSheet.getRow(1).getCell(6).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.MIN_OPENING_BALANCE_COL).setCellValue(savingsProductSheet.getRow(1).getCell(7).getNumericCellValue()); + firstSavingsRow.createCell(SavingsConstants.LOCKIN_PERIOD_COL).setCellValue(savingsProductSheet.getRow(1).getCell(8).getNumericCellValue()); + firstSavingsRow.createCell(SavingsConstants.LOCKIN_PERIOD_FREQUENCY_COL).setCellValue(savingsProductSheet.getRow(1).getCell(9).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.APPLY_WITHDRAWAL_FEE_FOR_TRANSFERS).setCellValue("False"); + firstSavingsRow.createCell(SavingsConstants.ALLOW_OVER_DRAFT_COL).setCellValue("False"); + firstSavingsRow.createCell(SavingsConstants.OVER_DRAFT_LIMIT_COL).setCellValue(savingsProductSheet.getRow(1).getCell(15).getNumericCellValue()); + + String currentdirectory = new File("").getAbsolutePath(); + File directory=new File(currentdirectory+"\\src\\integrationTest\\" + + "resources\\bulkimport\\importhandler\\savings"); + if (!directory.exists()) + directory.mkdirs(); + File file= new File(directory+"\\Savings.xls"); + OutputStream outputStream=new FileOutputStream(file); + workbook.write(outputStream); + outputStream.close(); + + String importDocumentId=savingsAccountHelper.importSavingsTemplate(file); + file.delete(); + Assert.assertNotNull(importDocumentId); + + //Wait for the creation of output excel + Thread.sleep(3000); + + //check status column of output excel + String location=savingsAccountHelper.getOutputTemplateLocation(importDocumentId); + FileInputStream fileInputStream = new FileInputStream(location); + Workbook Outputworkbook=new HSSFWorkbook(fileInputStream); + Sheet OutputSavingsSheet = Outputworkbook.getSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME); + Row row= OutputSavingsSheet.getRow(1); + Assert.assertEquals("Imported",row.getCell(SavingsConstants.STATUS_COL).getStringCellValue()); + } +} diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/client/ClientEntityWorkbookPopulatorTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/client/ClientEntityWorkbookPopulatorTest.java new file mode 100644 index 000000000..27e34b75f --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/client/ClientEntityWorkbookPopulatorTest.java @@ -0,0 +1,83 @@ +/** + * 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.integrationtests.bulkimport.populator.client; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; +import org.apache.fineract.integrationtests.common.ClientHelper; +import org.apache.fineract.integrationtests.common.OfficeHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.organisation.StaffHelper; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.IOException; + +public class ClientEntityWorkbookPopulatorTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup(){ + Utils.initializeRESTAssured(); + this.requestSpec=new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + + + } + + @Test + public void testClientEntityWorkbookPopulate() throws IOException { + //in order to populate helper sheets + StaffHelper staffHelper=new StaffHelper(); + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec); + Assert.assertNotNull("Could not create staff",outcome_staff_creation); + + //in order to populate helper sheets + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Integer outcome_office_creation=officeHelper.createOffice("02 May 2000"); + Assert.assertNotNull("Could not create office" ,outcome_office_creation); + + ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec); + Workbook workbook=clientHelper.getClientEntityWorkbook(GlobalEntityType.CLIENTS_ENTTTY,"dd MMMM yyyy"); + Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + Row firstOfficeRow=officeSheet.getRow(1); + Assert.assertNotNull("No offices found for given OfficeId ",firstOfficeRow.getCell(1)); + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME); + Row firstStaffRow=staffSheet.getRow(1); + Assert.assertNotNull("No staff found for given staffId",firstStaffRow.getCell(1)); + } +} diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/loan/LoanWorkbookPopulatorTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/loan/LoanWorkbookPopulatorTest.java new file mode 100644 index 000000000..3ba92a615 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/loan/LoanWorkbookPopulatorTest.java @@ -0,0 +1,129 @@ +/** + * 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.integrationtests.bulkimport.populator.loan; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; +import org.apache.fineract.integrationtests.common.*; +import org.apache.fineract.integrationtests.common.funds.FundsResourceHandler; +import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder; +import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper; +import org.apache.fineract.integrationtests.common.organisation.StaffHelper; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.IOException; + +public class LoanWorkbookPopulatorTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup(){ + Utils.initializeRESTAssured(); + this.requestSpec=new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + @Test + public void testLoanWorkbookPopulate() throws IOException { + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + //in order to populate helper sheets + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Integer outcome_office_creation=officeHelper.createOffice("02 May 2000"); + Assert.assertNotNull("Could not create office" ,outcome_office_creation); + + //in order to populate helper sheets + ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec); + Integer outcome_client_creation=clientHelper.createClient(requestSpec,responseSpec); + Assert.assertNotNull("Could not create client" ,outcome_client_creation); + + //in order to populate helper sheets + GroupHelper groupHelper=new GroupHelper(requestSpec,responseSpec); + Integer outcome_group_creation=groupHelper.createGroup(requestSpec,responseSpec,true); + Assert.assertNotNull("Could not create group" ,outcome_group_creation); + + //in order to populate helper sheets + StaffHelper staffHelper=new StaffHelper(); + Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec); + Assert.assertNotNull("Could not create staff",outcome_staff_creation); + + LoanTransactionHelper loanTransactionHelper=new LoanTransactionHelper(requestSpec,responseSpec); + LoanProductTestBuilder loanProductTestBuilder=new LoanProductTestBuilder(); + String jsonLoanProduct=loanProductTestBuilder.build(null); + Integer outcome_lp_creaion=loanTransactionHelper.getLoanProductId(jsonLoanProduct); + Assert.assertNotNull("Could not create Loan Product" ,outcome_lp_creaion); + + FundsResourceHandler fundsResourceHandler=new FundsResourceHandler(); + String jsonFund="{\n" + + "\t\"name\": \""+Utils.randomNameGenerator("Fund_Name",9)+"\"\n" + + "}"; + Integer outcome_fund_creation=fundsResourceHandler.createFund(jsonFund,requestSpec,responseSpec); + Assert.assertNotNull("Could not create Fund" ,outcome_fund_creation); + + PaymentTypeHelper paymentTypeHelper=new PaymentTypeHelper(); + String name = PaymentTypeHelper.randomNameGenerator("P_T", 5); + String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15); + Boolean isCashPayment = true; + Integer position = 1; + Integer outcome_payment_creation= paymentTypeHelper.createPaymentType(requestSpec, responseSpec,name,description,isCashPayment,position); + Assert.assertNotNull("Could not create payment type" ,outcome_payment_creation); + + Workbook workbook=loanTransactionHelper.getLoanWorkbook("dd MMMM yyyy"); + + Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + Row firstOfficeRow=officeSheet.getRow(1); + Assert.assertNotNull("No offices found ",firstOfficeRow.getCell(1)); + + Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME); + Row firstClientRow=clientSheet.getRow(1); + Assert.assertNotNull("No clients found ",firstClientRow.getCell(1)); + + Sheet groupSheet=workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME); + Row firstGroupRow=groupSheet.getRow(1); + Assert.assertNotNull("No groups found ",firstGroupRow.getCell(1)); + + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME); + Row firstStaffRow=staffSheet.getRow(1); + Assert.assertNotNull("No staff found ",firstStaffRow.getCell(1)); + + Sheet productSheet=workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME); + Row firstProductRow=productSheet.getRow(1); + Assert.assertNotNull("No products found ",firstProductRow.getCell(1)); + + Sheet extrasSheet=workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME); + Row firstExtrasRow=extrasSheet.getRow(1); + Assert.assertNotNull("No Extras found ",firstExtrasRow.getCell(1)); + } +} diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/office/OfficeWorkBookPopulatorTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/office/OfficeWorkBookPopulatorTest.java new file mode 100644 index 000000000..b878b4859 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/office/OfficeWorkBookPopulatorTest.java @@ -0,0 +1,64 @@ +/** + * 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.integrationtests.bulkimport.populator.office; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.OfficeConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.integrationtests.common.OfficeHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; + +public class OfficeWorkBookPopulatorTest { + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup(){ + Utils.initializeRESTAssured(); + this.requestSpec=new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + + @Test + public void testOfficeWorkbookPopulate() throws IOException { + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Workbook workbook=officeHelper.getOfficeWorkBook("dd MMMM yyyy"); + Sheet sheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + Row firstRow= sheet.getRow(1); + Assert.assertNotNull("No parent offices found",firstRow.getCell(OfficeConstants.LOOKUP_OFFICE_COL).getStringCellValue()); + Assert.assertEquals(1,firstRow.getCell(OfficeConstants.LOOKUP_OFFICE_ID_COL).getNumericCellValue(),0.0); + + } +} diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/savings/SavingsWorkbookPopulateTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/savings/SavingsWorkbookPopulateTest.java new file mode 100644 index 000000000..29ea6c4b0 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/savings/SavingsWorkbookPopulateTest.java @@ -0,0 +1,112 @@ +/** + * 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.integrationtests.bulkimport.populator.savings; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.integrationtests.common.ClientHelper; +import org.apache.fineract.integrationtests.common.GroupHelper; +import org.apache.fineract.integrationtests.common.OfficeHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.organisation.StaffHelper; +import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper; +import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.IOException; + +public class SavingsWorkbookPopulateTest { + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup(){ + Utils.initializeRESTAssured(); + this.requestSpec=new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + + @Test + public void testSavingsWorkbookPopulate() throws IOException { + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + //in order to populate helper sheets + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Integer outcome_office_creation=officeHelper.createOffice("02 May 2000"); + Assert.assertNotNull("Could not create office" ,outcome_office_creation); + + //in order to populate helper sheets + ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec); + Integer outcome_client_creation=clientHelper.createClient(requestSpec,responseSpec); + Assert.assertNotNull("Could not create client" ,outcome_client_creation); + + //in order to populate helper sheets + GroupHelper groupHelper=new GroupHelper(requestSpec,responseSpec); + Integer outcome_group_creation=groupHelper.createGroup(requestSpec,responseSpec,true); + Assert.assertNotNull("Could not create group" ,outcome_group_creation); + + //in order to populate helper sheets + StaffHelper staffHelper=new StaffHelper(); + Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec); + Assert.assertNotNull("Could not create staff",outcome_staff_creation); + + SavingsProductHelper savingsProductHelper=new SavingsProductHelper(); + String jsonSavingsProduct=savingsProductHelper.build(); + Integer outcome_sp_creaction=savingsProductHelper.createSavingsProduct(jsonSavingsProduct,requestSpec,responseSpec); + Assert.assertNotNull("Could not create Savings product",outcome_sp_creaction); + + SavingsAccountHelper savingsAccountHelper=new SavingsAccountHelper(requestSpec,responseSpec); + Workbook workbook=savingsAccountHelper.getSavingsWorkbook("dd MMMM yyyy"); + + Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + Row firstOfficeRow=officeSheet.getRow(1); + Assert.assertNotNull("No offices found ",firstOfficeRow.getCell(1)); + + Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME); + Row firstClientRow=clientSheet.getRow(1); + Assert.assertNotNull("No clients found ",firstClientRow.getCell(1)); + + Sheet groupSheet=workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME); + Row firstGroupRow=groupSheet.getRow(1); + Assert.assertNotNull("No groups found ",firstGroupRow.getCell(1)); + + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME); + Row firstStaffRow=staffSheet.getRow(1); + Assert.assertNotNull("No staff found ",firstStaffRow.getCell(1)); + + Sheet productSheet=workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME); + Row firstProductRow=productSheet.getRow(1); + Assert.assertNotNull("No products found ",firstProductRow.getCell(1)); + + } +} diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientHelper.java index e79820b82..1fb2b4d28 100755 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientHelper.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientHelper.java @@ -20,15 +20,25 @@ package org.apache.fineract.integrationtests.common; import static org.junit.Assert.assertEquals; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; import org.apache.fineract.integrationtests.common.system.CodeHelper; import com.google.gson.Gson; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Workbook; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; public class ClientHelper { @@ -591,4 +601,27 @@ public class ClientHelper { return Utils.performServerGet(requestSpec, responseSpec, CHARGES_URL, "reversed"); } + public Workbook getClientEntityWorkbook(GlobalEntityType clientsEntity, String dateFormat) throws IOException { + requestSpec.header(HttpHeaders.CONTENT_TYPE,"application/vnd.ms-excel"); + byte [] byteArray=Utils.performGetBinaryResponse(requestSpec,responseSpec,CLIENT_URL+"/downloadtemplate"+"?"+ + Utils.TENANT_IDENTIFIER+"&legalFormType="+clientsEntity+"&dateFormat="+dateFormat); + InputStream inputStream= new ByteArrayInputStream(byteArray); + Workbook workbook=new HSSFWorkbook(inputStream); + return workbook; + } + + public String getOutputTemplateLocation(final String importDocumentId){ + requestSpec.header(HttpHeaders.CONTENT_TYPE,MediaType.TEXT_PLAIN); + return Utils.performServerOutputTemplateLocationGet(requestSpec,responseSpec,"/fineract-provider/api/v1/imports/getOutputTemplateLocation"+"?" + +Utils.TENANT_IDENTIFIER,importDocumentId); + } + + public String importClientEntityTemplate(File file){ + String locale="en"; + String dateFormat="dd MMMM yyyy"; + String legalFormType=GlobalEntityType.CLIENTS_ENTTTY.toString(); + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA); + return Utils.performServerTemplatePost(requestSpec,responseSpec,CLIENT_URL+"/uploadtemplate"+"?"+Utils.TENANT_IDENTIFIER, + legalFormType,file,locale,dateFormat); + } } \ No newline at end of file diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeHelper.java index 1571735d5..2940576f3 100755 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeHelper.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeHelper.java @@ -18,6 +18,10 @@ */ package org.apache.fineract.integrationtests.common; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.util.HashMap; import com.google.common.reflect.TypeToken; @@ -25,6 +29,12 @@ import com.google.gson.Gson; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Workbook; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; + public class OfficeHelper { private static final String OFFICE_URL = "/fineract-provider/api/v1/offices"; @@ -77,4 +87,27 @@ public class OfficeHelper { System.out.println("map : " + map); return new Gson().toJson(map); } + + public String importOfficeTemplate(File file){ + String locale="en"; + String dateFormat="dd MMMM yyyy"; + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA); + return Utils.performServerTemplatePost(requestSpec,responseSpec,OFFICE_URL+"/uploadtemplate"+"?"+Utils.TENANT_IDENTIFIER, + null,file,locale,dateFormat); + + } + + public String getOutputTemplateLocation(final String importDocumentId){ + requestSpec.header(HttpHeaders.CONTENT_TYPE,MediaType.TEXT_PLAIN); + return Utils.performServerOutputTemplateLocationGet(requestSpec,responseSpec,"/fineract-provider/api/v1/imports/getOutputTemplateLocation"+"?" + +Utils.TENANT_IDENTIFIER,importDocumentId); + } + public Workbook getOfficeWorkBook(final String dateFormat) throws IOException { + requestSpec.header(HttpHeaders.CONTENT_TYPE,"application/vnd.ms-excel"); + byte[] byteArray=Utils.performGetBinaryResponse(requestSpec,responseSpec,OFFICE_URL+"/downloadtemplate"+"?"+ + Utils.TENANT_IDENTIFIER+"&dateFormat="+dateFormat); + InputStream inputStream= new ByteArrayInputStream(byteArray); + Workbook workbook=new HSSFWorkbook(inputStream); + return workbook; + } } diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/Utils.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/Utils.java index 3d173c309..5a7c12743 100644 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/Utils.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/Utils.java @@ -24,13 +24,11 @@ import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; +import java.io.File; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Locale; -import java.util.Random; -import java.util.TimeZone; +import java.util.*; import org.apache.commons.lang.StringUtils; import org.apache.http.conn.HttpHostConnectException; @@ -41,7 +39,6 @@ import com.jayway.restassured.RestAssured; import com.jayway.restassured.path.json.JsonPath; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; - /** * Util for RestAssured tests. This class here in src/integrationTest is * copy/pasted to src/test; please keep them in sync. @@ -145,6 +142,16 @@ public class Utils { public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) { return randomStringGenerator(prefix, lenOfRandomSuffix); } + public static Long randomNumberGenerator(final int expectedLength){ + final String source="1234567890"; + final int lengthofSource=source.length(); + final Random random=new Random(); + StringBuilder stringBuilder=new StringBuilder(expectedLength); + for (int i = 0; i < expectedLength; i++) { + stringBuilder.append(source.charAt(random.nextInt(lengthofSource))); + } + return Long.parseLong(stringBuilder.toString()); + } public static String convertDateToURLFormat(final Calendar dateToBeConvert) { DateFormat dateFormat = new SimpleDateFormat("dd MMMMMM yyyy"); @@ -165,4 +172,27 @@ public class Utils { return TimeZone.getTimeZone(TENANT_TIME_ZONE); } + public static String performServerTemplatePost(final RequestSpecification requestSpec,final ResponseSpecification responseSpec, + final String postURL,final String legalFormType,final File file,final String locale,final String dateFormat) { + + final String importDocumentId=given().spec(requestSpec) + .queryParam("legalFormType",legalFormType) + .multiPart("file",file) + .formParam("locale",locale) + .formParam("dateFormat",dateFormat) + .expect().spec(responseSpec). + log().ifError().when().post(postURL) + .andReturn().asString(); + return importDocumentId; + } + + public static String performServerOutputTemplateLocationGet(final RequestSpecification requestSpec,final ResponseSpecification responseSpec, + final String getURL,final String importDocumentId){ + final String templateLocation=given().spec(requestSpec). + queryParam("importDocumentId",importDocumentId) + .expect().spec(responseSpec) + .log().ifError().when().get(getURL) + .andReturn().asString(); + return templateLocation.substring(1,templateLocation.length()-1); + } } diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java index 57fc3435b..19aa98b32 100755 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java @@ -21,18 +21,28 @@ package org.apache.fineract.integrationtests.common.loans; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; import org.apache.fineract.integrationtests.common.CommonConstants; import org.apache.fineract.integrationtests.common.Utils; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Workbook; import org.joda.time.LocalDate; import com.google.gson.Gson; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; + @SuppressWarnings({ "rawtypes", "unchecked" }) public class LoanTransactionHelper { @@ -41,6 +51,7 @@ public class LoanTransactionHelper { private static final String CREATE_LOAN_PRODUCT_URL = "/fineract-provider/api/v1/loanproducts?" + Utils.TENANT_IDENTIFIER; private static final String APPLY_LOAN_URL = "/fineract-provider/api/v1/loans?" + Utils.TENANT_IDENTIFIER; + private static final String LOAN_ACCOUNT_URL="/fineract-provider/api/v1/loans"; private static final String APPROVE_LOAN_COMMAND = "approve"; private static final String UNDO_APPROVAL_LOAN_COMMAND = "undoApproval"; private static final String DISBURSE_LOAN_COMMAND = "disburse"; @@ -694,4 +705,29 @@ public class LoanTransactionHelper { datatablesListMap.add(datatableMap); return datatablesListMap; } + + public Workbook getLoanWorkbook(String dateFormat) throws IOException { + requestSpec.header(HttpHeaders.CONTENT_TYPE,"application/vnd.ms-excel"); + byte[] byteArray=Utils.performGetBinaryResponse(requestSpec,responseSpec,LOAN_ACCOUNT_URL+"/downloadtemplate"+"?"+ + Utils.TENANT_IDENTIFIER+"&dateFormat="+dateFormat); + InputStream inputStream= new ByteArrayInputStream(byteArray); + Workbook workbook=new HSSFWorkbook(inputStream); + return workbook; + } + + public String importLoanTemplate(File file) { + + String locale="en"; + String dateFormat="dd MMMM yyyy"; + String legalFormType= null; + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA); + return Utils.performServerTemplatePost(requestSpec,responseSpec,LOAN_ACCOUNT_URL+"/uploadtemplate"+"?"+Utils.TENANT_IDENTIFIER, + legalFormType,file,locale,dateFormat); + } + + public String getOutputTemplateLocation(final String importDocumentId){ + requestSpec.header(HttpHeaders.CONTENT_TYPE,MediaType.TEXT_PLAIN); + return Utils.performServerOutputTemplateLocationGet(requestSpec,responseSpec,"/fineract-provider/api/v1/imports/getOutputTemplateLocation"+"?" + +Utils.TENANT_IDENTIFIER,importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/savings/SavingsAccountHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/savings/SavingsAccountHelper.java index d0752a327..95522ebdb 100644 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/savings/SavingsAccountHelper.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/savings/SavingsAccountHelper.java @@ -18,6 +18,10 @@ */ package org.apache.fineract.integrationtests.common.savings; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -27,12 +31,17 @@ import java.util.Locale; import org.apache.fineract.integrationtests.common.CommonConstants; import org.apache.fineract.integrationtests.common.Utils; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Workbook; import org.junit.Assert; import com.google.gson.Gson; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; + @SuppressWarnings({ "rawtypes" }) public class SavingsAccountHelper { @@ -642,4 +651,28 @@ public class SavingsAccountHelper { datatablesListMap.add(datatableMap); return datatablesListMap; } + + public Workbook getSavingsWorkbook(String dateFormat) throws IOException { + requestSpec.header(HttpHeaders.CONTENT_TYPE,"application/vnd.ms-excel"); + byte[] byteArray=Utils.performGetBinaryResponse(requestSpec,responseSpec,SAVINGS_ACCOUNT_URL+"/downloadtemplate"+"?"+ + Utils.TENANT_IDENTIFIER+"&dateFormat="+dateFormat); + InputStream inputStream= new ByteArrayInputStream(byteArray); + Workbook workbook=new HSSFWorkbook(inputStream); + return workbook; + } + + public String importSavingsTemplate(File file) { + String locale="en"; + String dateFormat="dd MMMM yyyy"; + String legalFormType= null; + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA); + return Utils.performServerTemplatePost(requestSpec,responseSpec,SAVINGS_ACCOUNT_URL+"/uploadtemplate"+"?"+Utils.TENANT_IDENTIFIER, + legalFormType,file,locale,dateFormat); + } + + public String getOutputTemplateLocation(final String importDocumentId){ + requestSpec.header(HttpHeaders.CONTENT_TYPE,MediaType.TEXT_PLAIN); + return Utils.performServerOutputTemplateLocationGet(requestSpec,responseSpec,"/fineract-provider/api/v1/imports/getOutputTemplateLocation"+"?" + +Utils.TENANT_IDENTIFIER,importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/savings/SavingsProductHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/savings/SavingsProductHelper.java index 929e49e1b..a9269ef55 100644 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/savings/SavingsProductHelper.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/savings/SavingsProductHelper.java @@ -60,7 +60,7 @@ public class SavingsProductHelper { private String nameOfSavingsProduct = Utils.randomNameGenerator("SAVINGS_PRODUCT_", 6); private String shortName = Utils.randomNameGenerator("", 4); private String description = Utils.randomNameGenerator("", 20); - private String interestCompoundingPeriodType = "2"; + private String interestCompoundingPeriodType = "4"; private String interestPostingPeriodType = "4"; private String interestCalculationType = INTEREST_CALCULATION_USING_DAILY_BALANCE; private String nominalAnnualInterestRate = "10.0"; diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/api/GLAccountsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/api/GLAccountsApiResource.java index 613911448..5e3be9dcd 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/api/GLAccountsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/api/GLAccountsApiResource.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.accounting.glaccount.api; +import java.io.InputStream; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -35,8 +36,11 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; import org.apache.fineract.accounting.common.AccountingConstants; import org.apache.fineract.accounting.common.AccountingDropdownReadPlatformService; import org.apache.fineract.accounting.glaccount.data.GLAccountData; @@ -46,6 +50,9 @@ import org.apache.fineract.accounting.journalentry.data.JournalEntryAssociationP 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.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService; import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; @@ -78,13 +85,19 @@ public class GLAccountsApiResource { private final PlatformSecurityContext context; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final CodeValueReadPlatformService codeValueReadPlatformService; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; + + @Autowired public GLAccountsApiResource(final PlatformSecurityContext context, final GLAccountReadPlatformService glAccountReadPlatformService, final DefaultToApiJsonSerializer toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final AccountingDropdownReadPlatformService dropdownReadPlatformService, - final CodeValueReadPlatformService codeValueReadPlatformService) { + final CodeValueReadPlatformService codeValueReadPlatformService, + final BulkImportWorkbookService bulkImportWorkbookService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) { this.context = context; this.apiRequestParameterHelper = apiRequestParameterHelper; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; @@ -92,6 +105,8 @@ public class GLAccountsApiResource { this.glAccountReadPlatformService = glAccountReadPlatformService; this.dropdownReadPlatformService = dropdownReadPlatformService; this.codeValueReadPlatformService = codeValueReadPlatformService; + this.bulkImportWorkbookService=bulkImportWorkbookService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; } @GET @@ -219,4 +234,22 @@ public class GLAccountsApiResource { } return returnList; } + + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getGlAccountsTemplate(@QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.CHART_OF_ACCOUNTS.toString(),null,null,dateFormat); + } + + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postGlAccountsTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, + @FormDataParam("locale") final String locale, @FormDataParam("dateFormat") final String dateFormat){ + Long importDocumentId= bulkImportWorkbookService.importWorkbook(GlobalEntityType.CHART_OF_ACCOUNTS.toString(), uploadedInputStream,fileDetail, + locale,dateFormat); + return this.apiJsonSerializerService.serialize(importDocumentId); + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/data/GLAccountData.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/data/GLAccountData.java index aec22451e..63acf2a77 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/data/GLAccountData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/data/GLAccountData.java @@ -62,6 +62,55 @@ public class GLAccountData { final Collection allowedIncomeTagOptions; final Collection allowedExpensesTagOptions; + //import fields + private transient Integer rowIndex; + + public static GLAccountData importInstance(String name, Long parentId, String glCode, Boolean manualEntriesAllowed, + EnumOptionData type, EnumOptionData usage, String description, CodeValueData tagId, + Integer rowIndex){ + return new GLAccountData(name,parentId,glCode,manualEntriesAllowed,type, + usage,description,tagId,rowIndex); + } + + private GLAccountData(String name, Long parentId, String glCode, Boolean manualEntriesAllowed, + EnumOptionData type, EnumOptionData usage, String description, CodeValueData tagId, + Integer rowIndex) { + + this.name = name; + this.parentId = parentId; + this.glCode = glCode; + this.manualEntriesAllowed = manualEntriesAllowed; + this.type = type; + this.usage = usage; + this.description = description; + this.tagId = tagId; + this.rowIndex = rowIndex; + this.id = null; + this.disabled = null; + this.nameDecorated = null; + this.organizationRunningBalance = null; + this.accountTypeOptions = null; + this.usageOptions = null; + this.assetHeaderAccountOptions = null; + this.liabilityHeaderAccountOptions = null; + this.equityHeaderAccountOptions = null; + this.incomeHeaderAccountOptions = null; + this.expenseHeaderAccountOptions = null; + this.allowedAssetsTagOptions = null; + this.allowedLiabilitiesTagOptions = null; + this.allowedEquityTagOptions = null; + this.allowedIncomeTagOptions = null; + this.allowedExpensesTagOptions = null; + } + + public Integer getRowIndex() { + return rowIndex; + } + + public CodeValueData getTagId() { + return tagId; + } + public GLAccountData(final Long id, final String name, final Long parentId, final String glCode, final boolean disabled, final boolean manualEntriesAllowed, final EnumOptionData type, final EnumOptionData usage, final String description, final String nameDecorated, final CodeValueData tagId, final Long organizationRunningBalance) { @@ -195,4 +244,5 @@ public class GLAccountData { return null; } + } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/GLAccountType.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/GLAccountType.java index b9cf0024d..438faf61c 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/GLAccountType.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/domain/GLAccountType.java @@ -18,6 +18,8 @@ */ package org.apache.fineract.accounting.glaccount.domain; +import org.apache.fineract.infrastructure.core.data.EnumOptionData; + import java.util.HashMap; import java.util.Map; @@ -60,6 +62,27 @@ public enum GLAccountType { i = i + 1; } } + public static EnumOptionData fromString(String accountType){ + Long accountTypeId=null; + if (accountType!=null && accountType.equalsIgnoreCase(ASSET.toString())){ + accountTypeId=1L; + return new EnumOptionData(accountTypeId,null,null); + }else if(accountType!=null && accountType.equalsIgnoreCase(LIABILITY.toString())) { + accountTypeId = 2L; + return new EnumOptionData(accountTypeId, null, null); + }else if(accountType!=null && accountType.equalsIgnoreCase(EQUITY.toString())){ + accountTypeId=3L; + return new EnumOptionData(accountTypeId,null,null); + }else if(accountType!=null && accountType.equalsIgnoreCase(INCOME.toString())) { + accountTypeId = 4L; + return new EnumOptionData(accountTypeId, null, null); + }else if(accountType!=null && accountType.equalsIgnoreCase(EXPENSE.toString())){ + accountTypeId=5L; + return new EnumOptionData(accountTypeId,null,null); + }else { + return null; + } + } public static GLAccountType fromInt(final int i) { final GLAccountType type = intToEnumMap.get(Integer.valueOf(i)); diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/service/GLAccountReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/service/GLAccountReadPlatformServiceImpl.java index 4c008699f..c8b235c27 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/service/GLAccountReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/service/GLAccountReadPlatformServiceImpl.java @@ -123,11 +123,13 @@ public class GLAccountReadPlatformServiceImpl implements GLAccountReadPlatformSe final GLAccountMapper rm = new GLAccountMapper(associationParametersData); String sql = "select " + rm.schema(); // append SQL statement for fetching account totals - if (associationParametersData.isRunningBalanceRequired()) { - sql = sql + " and gl_j.id in (select t1.id from (select t2.account_id, max(t2.id) as id from " - + "(select id, max(entry_date) as entry_date, account_id from acc_gl_journal_entry where is_running_balance_calculated = 1 " - + "group by account_id desc) t3 inner join acc_gl_journal_entry t2 on t2.account_id = t3.account_id and t2.entry_date = t3.entry_date " - + "group by t2.account_id desc) t1)"; + if (associationParametersData!=null) { + if (associationParametersData.isRunningBalanceRequired()) { + sql = sql + " and gl_j.id in (select t1.id from (select t2.account_id, max(t2.id) as id from " + + "(select id, max(entry_date) as entry_date, account_id from acc_gl_journal_entry where is_running_balance_calculated = 1 " + + "group by account_id desc) t3 inner join acc_gl_journal_entry t2 on t2.account_id = t3.account_id and t2.entry_date = t3.entry_date " + + "group by t2.account_id desc) t1)"; + } } final Object[] paramaterArray = new Object[3]; int arrayPos = 0; diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/api/JournalEntriesApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/api/JournalEntriesApiResource.java index 9e66b0b3f..afc64055a 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/api/JournalEntriesApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/api/JournalEntriesApiResource.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.accounting.journalentry.api; +import java.io.InputStream; import java.util.Arrays; import java.util.Date; import java.util.HashSet; @@ -32,8 +33,11 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; import org.apache.commons.lang.StringUtils; import org.apache.fineract.accounting.journalentry.data.JournalEntryAssociationParametersData; import org.apache.fineract.accounting.journalentry.data.JournalEntryData; @@ -43,6 +47,9 @@ import org.apache.fineract.accounting.producttoaccountmapping.domain.PortfolioPr 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.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.exception.UnrecognizedQueryParamException; @@ -72,17 +79,24 @@ public class JournalEntriesApiResource { private final ApiRequestParameterHelper apiRequestParameterHelper; private final PlatformSecurityContext context; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; + @Autowired public JournalEntriesApiResource(final PlatformSecurityContext context, final JournalEntryReadPlatformService journalEntryReadPlatformService, final DefaultToApiJsonSerializer toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper, - final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) { + final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, + final BulkImportWorkbookService bulkImportWorkbookService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) { this.context = context; this.apiRequestParameterHelper = apiRequestParameterHelper; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.apiJsonSerializerService = toApiJsonSerializer; this.journalEntryReadPlatformService = journalEntryReadPlatformService; + this.bulkImportWorkbookService=bulkImportWorkbookService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; } @GET @@ -208,4 +222,25 @@ public class JournalEntriesApiResource { private boolean is(final String commandParam, final String commandValue) { return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue); } + + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getJournalEntriesTemplate(@QueryParam("officeId") final Long officeId, + @QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.GL_JOURNAL_ENTRIES.toString(), + officeId,null,dateFormat); + } + + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postJournalEntriesTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, + @FormDataParam("locale") final String locale, + @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId =this.bulkImportWorkbookService.importWorkbook(GlobalEntityType.GL_JOURNAL_ENTRIES.toString(), + uploadedInputStream,fileDetail, locale,dateFormat); + return this.apiJsonSerializerService.serialize(importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/CreditDebit.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/CreditDebit.java new file mode 100644 index 000000000..0be9f1a2e --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/CreditDebit.java @@ -0,0 +1,31 @@ +/** + * 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.accounting.journalentry.data; + +import java.math.BigDecimal; + +public class CreditDebit { + private final Long glAccountId; + private final BigDecimal amount; + + public CreditDebit(Long glAccountId, BigDecimal amount) { + this.glAccountId = glAccountId; + this.amount = amount; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/JournalEntryData.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/JournalEntryData.java index b6bb15dda..4c67d9980 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/JournalEntryData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/data/JournalEntryData.java @@ -19,8 +19,10 @@ package org.apache.fineract.accounting.journalentry.data; import java.math.BigDecimal; +import java.util.List; import org.apache.fineract.accounting.glaccount.data.GLAccountData; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.organisation.monetary.data.CurrencyData; import org.joda.time.LocalDate; @@ -78,6 +80,91 @@ public class JournalEntryData { @SuppressWarnings("unused") private final TransactionDetailData transactionDetails; + //import fields + private transient Integer rowIndex; + private String dateFormat; + private String locale; + private List credits; + private List debits; + private Long paymentTypeId; + private String currencyCode; + private String accountNumber; + private String checkNumber; + private String routingCode; + private String receiptNumber; + private String bankNumber; + + public static JournalEntryData importInstance(Long officeId,LocalDate transactionDate,String currencyCode, Long paymentTypeId, + Integer rowIndex,List credits, Listdebits, + String accountNumber,String checkNumber,String routingCode,String receiptNumber,String bankNumber, + String comments,String locale,String dateFormat){ + return new JournalEntryData(officeId, transactionDate, currencyCode, + paymentTypeId, rowIndex, credits, debits,accountNumber,checkNumber,routingCode, + receiptNumber,bankNumber,comments,locale,dateFormat); + } + private JournalEntryData(Long officeId,LocalDate transactionDate,String currencyCode, Long paymentTypeId, + Integer rowIndex,List credits, Listdebits, + String accountNumber,String checkNumber,String routingCode,String receiptNumber, + String bankNumber,String comments,String locale,String dateFormat) { + + this.officeId = officeId; + this.dateFormat= dateFormat; + this.locale= locale; + this.transactionDate = transactionDate; + this.currencyCode=currencyCode; + this.rowIndex = rowIndex; + this.credits = credits; + this.debits = debits; + this.paymentTypeId = paymentTypeId; + this.accountNumber=accountNumber; + this.checkNumber=checkNumber; + this.routingCode=routingCode; + this.receiptNumber=receiptNumber; + this.bankNumber=bankNumber; + this.comments=comments; + this.id = null; + this.officeName = null; + this.glAccountName = null; + this.glAccountId = null; + this.glAccountCode = null; + this.glAccountType = null; + this.entryType = null; + this.amount = null; + this.currency = null; + this.transactionId = null; + this.manualEntry = null; + this.entityType = null; + this.entityId = null; + this.createdByUserId = null; + this.createdDate = null; + this.createdByUserName = null; + this.reversed = null; + this.referenceNumber = null; + this.officeRunningBalance = null; + this.organizationRunningBalance = null; + this.runningBalanceComputed = null; + this.transactionDetails = null; + } + + public Integer getRowIndex() { + return rowIndex; + } + + public LocalDate getTransactionDate() { + return transactionDate; + } + + public void addDebits(CreditDebit debit) { + + this.debits.add(debit); + } + + + + public void addCredits(CreditDebit credit) { + this.credits.add(credit); + } + public JournalEntryData(final Long id, final Long officeId, final String officeName, final String glAccountName, final Long glAccountId, final String glAccountCode, final EnumOptionData glAccountClassification, final LocalDate transactionDate, final EnumOptionData entryType, final BigDecimal amount, final String transactionId, diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/api/BulkImportApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/api/BulkImportApiResource.java new file mode 100644 index 000000000..854ea7988 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/api/BulkImportApiResource.java @@ -0,0 +1,114 @@ +/** + * 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.api; + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collection; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.data.ImportData; +import org.apache.fineract.infrastructure.bulkimport.exceptions.ImportTypeNotFoundException; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; +import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; +import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; +import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer; +import org.apache.fineract.infrastructure.documentmanagement.data.DocumentData; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +@Path("/imports") +@Component +@Scope("singleton") +public class BulkImportApiResource { + + private final String resourceNameForPermissions = "IMPORT"; + + private final PlatformSecurityContext context; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final DefaultToApiJsonSerializer toApiJsonSerializer; + private final ApiRequestParameterHelper apiRequestParameterHelper; + + @Autowired + public BulkImportApiResource(final PlatformSecurityContext context, + final BulkImportWorkbookService bulkImportWorkbookService, + final DefaultToApiJsonSerializer toApiJsonSerializer, + final ApiRequestParameterHelper apiRequestParameterHelper) { + this.context = context; + this.bulkImportWorkbookService = bulkImportWorkbookService; + this.toApiJsonSerializer = toApiJsonSerializer; + this.apiRequestParameterHelper = apiRequestParameterHelper; + } + + + @GET + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String retrieveImportDocuments(@Context final UriInfo uriInfo, + @QueryParam("entityType") final String entityType) { + + this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions); + Collection importData=new ArrayList<>(); + if (entityType.equals(GlobalEntityType.CLIENT.getCode())){ + final Collection importForClientEntity = this.bulkImportWorkbookService.getImports(GlobalEntityType.CLIENTS_ENTTTY); + final Collection importForClientPerson=this.bulkImportWorkbookService.getImports(GlobalEntityType.CLIENTS_PERSON); + if (importForClientEntity!=null) + importData.addAll(importForClientEntity); + if (importForClientPerson!=null) + importData.addAll(importForClientPerson); + }else { + final GlobalEntityType type = GlobalEntityType.fromCode(entityType); + if (type == null) + throw new ImportTypeNotFoundException(entityType); + importData = this.bulkImportWorkbookService.getImports(type); + } + final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); + return this.toApiJsonSerializer.serialize(settings, importData); + } + + @GET + @Path("getOutputTemplateLocation") + public String retriveOutputTemplateLocation(@QueryParam("importDocumentId")final String importDocumentId ){ + this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions); + final DocumentData documentData =this.bulkImportWorkbookService.getOutputTemplateLocation(importDocumentId); + return this.toApiJsonSerializer.serialize(documentData.fileLocation()); + } + + @GET + @Path("downloadOutputTemplate") + @Produces("application/vnd.ms-excel") + public Response getOutputTemplate(@QueryParam("importDocumentId") final String importDocumentId) { + return bulkImportWorkbookService.getOutputTemplate(importDocumentId); + } + + + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/CenterConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/CenterConstants.java new file mode 100644 index 000000000..007222118 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/CenterConstants.java @@ -0,0 +1,51 @@ +/** + * 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.constants; + +public class CenterConstants { + + //Column indices + public static final int CENTER_NAME_COL = 0;//A + public static final int OFFICE_NAME_COL = 1;//B + public static final int STAFF_NAME_COL = 2;//C + public static final int EXTERNAL_ID_COL = 3;//D + public static final int ACTIVE_COL = 4;//E + public static final int ACTIVATION_DATE_COL = 5;//F + public static final int SUBMITTED_ON_DATE_COL=6;//G + public static final int MEETING_START_DATE_COL = 7;//H + public static final int IS_REPEATING_COL = 8;//I + public static final int FREQUENCY_COL = 9;//J + public static final int INTERVAL_COL = 10;//K + public static final int REPEATS_ON_DAY_COL = 11;//L + public static final int STATUS_COL = 12;//M + public static final int CENTER_ID_COL = 13;//N + public static final int FAILURE_COL = 14;//O + public static final int GROUP_NAMES_STARTING_COL = 15;//P + public static final int GROUP_NAMES_ENDING_COL = 250;//IQ + public static final int LOOKUP_OFFICE_NAME_COL = 251; + public static final int LOOKUP_OFFICE_OPENING_DATE_COL = 252; + public static final int LOOKUP_REPEAT_NORMAL_COL = 253; + public static final int LOOKUP_REPEAT_MONTHLY_COL = 254; + public static final int LOOKUP_IF_REPEAT_WEEKLY_COL = 255; + + + + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/ChartOfAcountsConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/ChartOfAcountsConstants.java new file mode 100644 index 000000000..02255c2b1 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/ChartOfAcountsConstants.java @@ -0,0 +1,38 @@ +/** + * 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.constants; + +public class ChartOfAcountsConstants { + public static final int ACCOUNT_TYPE_COL=0;//A + public static final int ACCOUNT_NAME_COL=1;//B + public static final int ACCOUNT_USAGE_COL=2;//C + public static final int MANUAL_ENTRIES_ALLOWED_COL=3;//D + public static final int PARENT_COL=4;//E + public static final int PARENT_ID_COL=5;//F + public static final int GL_CODE_COL=6;//G + public static final int TAG_COL=7;//H + public static final int TAG_ID_COL=8;//I + public static final int DESCRIPTION_COL=9;//J + public static final int LOOKUP_ACCOUNT_TYPE_COL=15;// P + public static final int LOOKUP_ACCOUNT_NAME_COL=16; //Q + public static final int LOOKUP_ACCOUNT_ID_COL=17;//R + public static final int LOOKUP_TAG_COL=18; //S + public static final int LOOKUP_TAG_ID_COL=19; //T + public static final int STATUS_COL=20; +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/ClientEntityConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/ClientEntityConstants.java new file mode 100644 index 000000000..f8ec57387 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/ClientEntityConstants.java @@ -0,0 +1,61 @@ +/** + * 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.constants; + +public class ClientEntityConstants { + + public static final int NAME_COL = 0;//A + public static final int OFFICE_NAME_COL = 1;//B + public static final int STAFF_NAME_COL = 2;//C + public static final int INCOPORATION_DATE_COL = 3;//D + public static final int INCOPORATION_VALID_TILL_COL = 4; //E + public static final int MOBILE_NO_COL=5;//F + public static final int CLIENT_TYPE_COL=6;//G + public static final int CLIENT_CLASSIFICATION_COL=7;//H + public static final int INCOPORATION_NUMBER_COL=8;//I + public static final int MAIN_BUSINESS_LINE=9;//J + public static final int CONSTITUTION_COL=10;//K + public static final int REMARKS_COL=11;//L + public static final int EXTERNAL_ID_COL=12;//M + public static final int ACTIVE_COL = 13;//N + public static final int ACTIVATION_DATE_COL = 14;//O + public static final int SUBMITTED_ON_COL=15; //P + public static final int ADDRESS_ENABLED=16;//Q + public static final int ADDRESS_TYPE_COL=17;//R + public static final int STREET_COL=18;//S + public static final int ADDRESS_LINE_1_COL=19;//T + public static final int ADDRESS_LINE_2_COL=20;//U + public static final int ADDRESS_LINE_3_COL=21;//V + public static final int CITY_COL =22;//W + public static final int STATE_PROVINCE_COL=23;//X + public static final int COUNTRY_COL=24;//Y + public static final int POSTAL_CODE_COL=25;//Z + public static final int IS_ACTIVE_ADDRESS_COL=26;//AA + public static final int WARNING_COL = 26;//AA + public static final int STATUS_COL = 27;//AB + public static final int RELATIONAL_OFFICE_NAME_COL = 35;//AJ + public static final int RELATIONAL_OFFICE_OPENING_DATE_COL = 36;//AK + public static final int LOOKUP_CONSTITUTION_COL = 37;//AL + public static final int LOOKUP_CLIENT_CLASSIFICATION = 38;//AM + public static final int LOOKUP_CLIENT_TYPES = 39;//AN + public static final int LOOKUP_ADDRESS_TYPE = 40;//AO + public static final int LOOKUP_STATE_PROVINCE = 41;//AP + public static final int LOOKUP_COUNTRY = 42;//AQ + public static final int LOOKUP_MAIN_BUSINESS_LINE=43;//AR +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/ClientPersonConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/ClientPersonConstants.java new file mode 100644 index 000000000..5da827019 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/ClientPersonConstants.java @@ -0,0 +1,58 @@ +/** + * 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.constants; + +public class ClientPersonConstants { + public static final int FIRST_NAME_COL = 0;//A + public static final int LAST_NAME_COL = 1;//B + public static final int MIDDLE_NAME_COL = 2;//C + public static final int OFFICE_NAME_COL = 3;//D + public static final int STAFF_NAME_COL = 4;//E + public static final int EXTERNAL_ID_COL = 5;//F + public static final int ACTIVE_COL = 6;//G + public static final int ACTIVATION_DATE_COL = 7;//H + public static final int SUBMITTED_ON_COL=8; //I + public static final int MOBILE_NO_COL=9;//J + public static final int DOB_COL=10;//K + public static final int CLIENT_TYPE_COL=11;//L + public static final int GENDER_COL=12;//M + public static final int CLIENT_CLASSIFICATION_COL=13;//N + public static final int IS_STAFF_COL=14;//O + public static final int ADDRESS_ENABLED_COL=15;// P + public static final int ADDRESS_TYPE_COL=16;//Q + public static final int STREET_COL=17;//R + public static final int ADDRESS_LINE_1_COL=18;//S + public static final int ADDRESS_LINE_2_COL=19;//T + public static final int ADDRESS_LINE_3_COL=20;//U + public static final int CITY_COL=21;//V + public static final int STATE_PROVINCE_COL=22;//W + public static final int COUNTRY_COL=23;//X + public static final int POSTAL_CODE_COL=24;//Y + public static final int IS_ACTIVE_ADDRESS_COL=25;//Z + public static final int WARNING_COL = 26;//AA + public static final int STATUS_COL = 27;//AB + public static final int RELATIONAL_OFFICE_NAME_COL = 35;//AJ + public static final int RELATIONAL_OFFICE_OPENING_DATE_COL = 36;//AK + public static final int LOOKUP_GENDER_COL = 37;//AL + public static final int LOOKUP_CLIENT_CLASSIFICATION_COL = 38;//AM + public static final int LOOKUP_CLIENT_TYPES_COL = 39;//AN + public static final int LOOKUP_ADDRESS_TYPE_COL = 40;//AO + public static final int LOOKUP_STATE_PROVINCE_COL = 41;//AP + public static final int LOOKUP_COUNTRY_COL = 42;//AQ +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/FixedDepositConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/FixedDepositConstants.java new file mode 100644 index 000000000..d617a077b --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/FixedDepositConstants.java @@ -0,0 +1,55 @@ +/** + * 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.constants; + +public class FixedDepositConstants { + + public static final int OFFICE_NAME_COL = 0; + public static final int CLIENT_NAME_COL = 1; + public static final int PRODUCT_COL = 2; + public static final int FIELD_OFFICER_NAME_COL = 3; + public static final int SUBMITTED_ON_DATE_COL = 4; + public static final int APPROVED_DATE_COL = 5; + public static final int ACTIVATION_DATE_COL = 6; + public static final int INTEREST_COMPOUNDING_PERIOD_COL = 7; + public static final int INTEREST_POSTING_PERIOD_COL = 8; + public static final int INTEREST_CALCULATION_COL = 9; + public static final int INTEREST_CALCULATION_DAYS_IN_YEAR_COL = 10; + public static final int LOCKIN_PERIOD_COL = 11; + public static final int LOCKIN_PERIOD_FREQUENCY_COL = 12; + public static final int DEPOSIT_AMOUNT_COL = 13; + public static final int DEPOSIT_PERIOD_COL = 14; + public static final int DEPOSIT_PERIOD_FREQUENCY_COL = 15; + public static final int EXTERNAL_ID_COL = 16; + public static final int CHARGE_ID_1 = 18; + public static final int CHARGE_AMOUNT_1 = 19; + public static final int CHARGE_DUE_DATE_1 = 20; + public static final int CHARGE_ID_2 = 21; + public static final int CHARGE_AMOUNT_2 = 22; + public static final int CHARGE_DUE_DATE_2 = 23; + public static final int CLOSED_ON_DATE = 24; + public static final int ON_ACCOUNT_CLOSURE_ID = 25; + public static final int TO_SAVINGS_ACCOUNT_ID = 26; + public static final int STATUS_COL = 27; + public static final int SAVINGS_ID_COL = 28; + public static final int FAILURE_REPORT_COL = 29; + + public static final int LOOKUP_CLIENT_NAME_COL = 31; + public static final int LOOKUP_ACTIVATION_DATE_COL = 32; +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/GroupConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/GroupConstants.java new file mode 100644 index 000000000..02c03260c --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/GroupConstants.java @@ -0,0 +1,47 @@ +/** + * 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.constants; + +public class GroupConstants { + + public static final int NAME_COL = 0; //A + public static final int OFFICE_NAME_COL = 1; //B + public static final int STAFF_NAME_COL = 2;//C + + public static final int CENTER_NAME_COL = 3;//D + public static final int EXTERNAL_ID_COL = 4;//E + public static final int ACTIVE_COL = 5;//F + public static final int ACTIVATION_DATE_COL = 6;//G + public static final int SUBMITTED_ON_DATE_COL=7;//H + public static final int MEETING_START_DATE_COL = 8;//I + public static final int IS_REPEATING_COL = 9;//J + public static final int FREQUENCY_COL = 10;//K + public static final int INTERVAL_COL = 11;//L + public static final int REPEATS_ON_DAY_COL = 12;//M + public static final int STATUS_COL = 13;//N + public static final int GROUP_ID_COL = 14;//O + public static final int FAILURE_COL = 15;//P + public static final int CLIENT_NAMES_STARTING_COL = 16;//Q + public static final int CLIENT_NAMES_ENDING_COL = 250;//IQ + public static final int LOOKUP_OFFICE_NAME_COL = 251;//IR + public static final int LOOKUP_OFFICE_OPENING_DATE_COL = 252;//IS + public static final int LOOKUP_REPEAT_NORMAL_COL = 253;//IT + public static final int LOOKUP_REPEAT_MONTHLY_COL = 254;//IU + public static final int LOOKUP_IF_REPEAT_WEEKLY_COL = 255;//IV +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/GuarantorConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/GuarantorConstants.java new file mode 100644 index 000000000..b37195bd2 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/GuarantorConstants.java @@ -0,0 +1,45 @@ +/** + * 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.constants; + +public class GuarantorConstants { + + public static final int OFFICE_NAME_COL = 0; + public static final int CLIENT_NAME_COL = 1; + public static final int LOAN_ACCOUNT_NO_COL = 2; + public static final int GUARANTO_TYPE_COL =3; + public static final int CLIENT_RELATIONSHIP_TYPE_COL =4; + public static final int ENTITY_OFFICE_NAME_COL = 5; + public static final int ENTITY_ID_COL = 6; + public static final int FIRST_NAME_COL = 7; + public static final int LAST_NAME_COL = 8; + public static final int ADDRESS_LINE_1_COL= 9; + public static final int ADDRESS_LINE_2_COL = 10; + public static final int CITY_COL = 11; + public static final int DOB_COL = 12; + public static final int ZIP_COL = 13; + public static final int SAVINGS_ID_COL=14; + public static final int AMOUNT=15; + public static final int STATUS_COL = 18; + public static final int LOOKUP_CLIENT_NAME_COL=81; + public static final int LOOKUP_ACCOUNT_NO_COL=82; + public static final int LOOKUP_SAVINGS_CLIENT_NAME_COL=83; + public static final int LOOKUP_SAVINGS_ACCOUNT_NO_COL=84; + public static final int LOOKUP_GUARANTOR_RELATIONSHIPS=85; +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/JournalEntryConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/JournalEntryConstants.java new file mode 100644 index 000000000..e54f19b88 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/JournalEntryConstants.java @@ -0,0 +1,49 @@ +/** + * 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.constants; + +public class JournalEntryConstants { + + public static final int OFFICE_NAME_COL = 0; + + public static final int TRANSACION_ON_DATE_COL = 1; + + public static final int CURRENCY_NAME_COL = 2; + + public static final int PAYMENT_TYPE_ID_COL = 3; + + public static final int TRANSACTION_ID_COL = 4; + + public static final int GL_ACCOUNT_ID_CREDIT_COL = 5; + + public static final int AMOUNT_CREDIT_COL = 6; + + public static final int GL_ACCOUNT_ID_DEBIT_COL = 7; + + public static final int AMOUNT_DEBIT_COL = 8; + + public static final int STATUS_COL = 9; + + public static final int ACCOUNT_NO_COL = 10; + public static final int CHECK_NO_COL = 11; + public static final int ROUTING_CODE_COL = 12; + public static final int RECEIPT_NO_COL = 13; + public static final int BANK_NO_COL = 14; + public static final int COMMENTS_COL=15; +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/LoanConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/LoanConstants.java new file mode 100644 index 000000000..2e5b38fd0 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/LoanConstants.java @@ -0,0 +1,75 @@ +/** + * 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.constants; + +public class LoanConstants { + + public static final int OFFICE_NAME_COL = 0;//A + public static final int LOAN_TYPE_COL = 1;//B + public static final int CLIENT_NAME_COL = 2;//C + public static final int CLIENT_EXTERNAL_ID=3;//D + public static final int PRODUCT_COL = 4;//E + public static final int LOAN_OFFICER_NAME_COL = 5;//F + public static final int SUBMITTED_ON_DATE_COL = 6;//G + public static final int APPROVED_DATE_COL = 7;//H + public static final int DISBURSED_DATE_COL = 8;//I + public static final int DISBURSED_PAYMENT_TYPE_COL = 9;//J + public static final int FUND_NAME_COL = 10;//K + public static final int PRINCIPAL_COL = 11;//L + public static final int NO_OF_REPAYMENTS_COL = 12;//M + public static final int REPAID_EVERY_COL = 13;//N + public static final int REPAID_EVERY_FREQUENCY_COL = 14;//O + public static final int LOAN_TERM_COL = 15;//P + public static final int LOAN_TERM_FREQUENCY_COL = 16;//Q + public static final int NOMINAL_INTEREST_RATE_COL = 17;//R + public static final int NOMINAL_INTEREST_RATE_FREQUENCY_COL = 18;//S + public static final int AMORTIZATION_COL = 19;//T + public static final int INTEREST_METHOD_COL = 20;//U + public static final int INTEREST_CALCULATION_PERIOD_COL = 21;//V + public static final int ARREARS_TOLERANCE_COL = 22;//W + public static final int REPAYMENT_STRATEGY_COL = 23;//X + public static final int GRACE_ON_PRINCIPAL_PAYMENT_COL = 24;//Y + public static final int GRACE_ON_INTEREST_PAYMENT_COL = 25;//Z + public static final int GRACE_ON_INTEREST_CHARGED_COL = 26;//AA + public static final int INTEREST_CHARGED_FROM_COL = 27;//AB + public static final int FIRST_REPAYMENT_COL = 28;//AC + public static final int TOTAL_AMOUNT_REPAID_COL = 29;//AD + public static final int LAST_REPAYMENT_DATE_COL = 30;//AE + public static final int REPAYMENT_TYPE_COL = 31;//AF + public static final int STATUS_COL = 32;//AG + public static final int LOAN_ID_COL = 33;//AH + public static final int FAILURE_REPORT_COL = 34;//AI + public static final int EXTERNAL_ID_COL = 35;//AJ + public static final int CHARGE_ID_1 = 36;//AK + public static final int CHARGE_AMOUNT_1 = 37;//AL + public static final int CHARGE_DUE_DATE_1 = 38;//AM + public static final int CHARGE_ID_2 = 39;//AN + public static final int CHARGE_AMOUNT_2 = 40;//AO + public static final int CHARGE_DUE_DATE_2 = 41;//AP + public static final int GROUP_ID = 42;//AQ + public static final int LOOKUP_CLIENT_NAME_COL = 43;//AR + public static final int LOOKUP_CLIENT_EXTERNAL_ID=44;//AS + public static final int LOOKUP_ACTIVATION_DATE_COL = 45;//AT + public static final int LINK_ACCOUNT_ID = 46;//AU + + public static final String LOAN_TYPE_INDIVIDUAL="Individual"; + public static final String LOAN_TYPE_GROUP="Group"; + public static final String LOAN_TYPE_JLG="JLG" ; + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/LoanRepaymentConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/LoanRepaymentConstants.java new file mode 100644 index 000000000..4a35d9461 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/LoanRepaymentConstants.java @@ -0,0 +1,44 @@ +/** + * 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.constants; + +public class LoanRepaymentConstants { + + public static final int OFFICE_NAME_COL = 0;//A + public static final int CLIENT_NAME_COL = 1;//B + public static final int CLIENT_EXTERNAL_ID=2;//C + public static final int LOAN_ACCOUNT_NO_COL = 3;//D + public static final int PRODUCT_COL = 4;//E + public static final int PRINCIPAL_COL = 5;//F + public static final int AMOUNT_COL = 6;//G + public static final int REPAID_ON_DATE_COL = 7;//H + public static final int REPAYMENT_TYPE_COL = 8;//I + public static final int ACCOUNT_NO_COL = 9;//J + public static final int CHECK_NO_COL = 10;//K + public static final int ROUTING_CODE_COL = 11;//L + public static final int RECEIPT_NO_COL = 12;//M + public static final int BANK_NO_COL = 13;//N + public static final int STATUS_COL = 14;//O + public static final int LOOKUP_CLIENT_NAME_COL = 15;//P + public static final int LOOKUP_CLIENT_EXTERNAL_ID = 16;//Q + public static final int LOOKUP_ACCOUNT_NO_COL = 17;//R + public static final int LOOKUP_PRODUCT_COL = 18;//S + public static final int LOOKUP_PRINCIPAL_COL = 19;//T + public static final int LOOKUP_LOAN_DISBURSEMENT_DATE_COL = 20;//U +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/OfficeConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/OfficeConstants.java new file mode 100644 index 000000000..f1fe3a386 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/OfficeConstants.java @@ -0,0 +1,33 @@ +/** + * 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.constants; + +public class OfficeConstants { + + //Column indices + public static final int OFFICE_NAME_COL = 0; + public static final int PARENT_OFFICE_NAME_COL = 1; + public static final int PARENT_OFFICE_ID_COL=2; + public static final int OPENED_ON_COL = 3; + public static final int EXTERNAL_ID_COL = 4; + public static final int LOOKUP_OFFICE_COL=7; + public static final int LOOKUP_OFFICE_ID_COL=8; + public static final int STATUS_COL=10; + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/RecurringDepositConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/RecurringDepositConstants.java new file mode 100644 index 000000000..0cd58d087 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/RecurringDepositConstants.java @@ -0,0 +1,60 @@ +/** + * 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.constants; + +public class RecurringDepositConstants { + + public static final int OFFICE_NAME_COL = 0; + public static final int CLIENT_NAME_COL = 1; + public static final int PRODUCT_COL = 2; + public static final int FIELD_OFFICER_NAME_COL = 3; + public static final int SUBMITTED_ON_DATE_COL = 4; + public static final int APPROVED_DATE_COL = 5; + public static final int ACTIVATION_DATE_COL = 6; + public static final int INTEREST_COMPOUNDING_PERIOD_COL = 7; + public static final int INTEREST_POSTING_PERIOD_COL = 8; + public static final int INTEREST_CALCULATION_COL = 9; + public static final int INTEREST_CALCULATION_DAYS_IN_YEAR_COL = 10; + public static final int LOCKIN_PERIOD_COL = 11; + public static final int LOCKIN_PERIOD_FREQUENCY_COL = 12; + public static final int RECURRING_DEPOSIT_AMOUNT_COL = 13; + public static final int DEPOSIT_PERIOD_COL = 14; + public static final int DEPOSIT_PERIOD_FREQUENCY_COL = 15; + public static final int DEPOSIT_FREQUENCY_COL = 16; + public static final int DEPOSIT_FREQUENCY_TYPE_COL = 17; + public static final int DEPOSIT_START_DATE_COL = 18; + public static final int IS_MANDATORY_DEPOSIT_COL = 19; + public static final int ALLOW_WITHDRAWAL_COL = 20; + public static final int FREQ_SAME_AS_GROUP_CENTER_COL = 21; + public static final int ADJUST_ADVANCE_PAYMENTS_COL = 22; + public static final int EXTERNAL_ID_COL = 23; + public static final int STATUS_COL = 24; + public static final int SAVINGS_ID_COL = 25; + public static final int FAILURE_REPORT_COL = 26; + public static final int CHARGE_ID_1 = 28; + public static final int CHARGE_AMOUNT_1 = 29; + public static final int CHARGE_DUE_DATE_1 = 30; + public static final int CHARGE_ID_2 = 33; + public static final int CHARGE_AMOUNT_2 = 34; + public static final int CHARGE_DUE_DATE_2 = 35; + + + public static final int LOOKUP_CLIENT_NAME_COL = 31; + public static final int LOOKUP_ACTIVATION_DATE_COL = 32; +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/SavingsConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/SavingsConstants.java new file mode 100644 index 000000000..72b544a81 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/SavingsConstants.java @@ -0,0 +1,57 @@ +/** + * 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.constants; + +public class SavingsConstants { + + public static final int OFFICE_NAME_COL = 0; + public static final int SAVINGS_TYPE_COL = 1; + public static final int CLIENT_NAME_COL = 2; + public static final int PRODUCT_COL = 3; + public static final int FIELD_OFFICER_NAME_COL = 4; + public static final int SUBMITTED_ON_DATE_COL = 5; + public static final int APPROVED_DATE_COL = 6; + public static final int ACTIVATION_DATE_COL = 7; + public static final int CURRENCY_COL = 8; + public static final int DECIMAL_PLACES_COL = 9; + public static final int IN_MULTIPLES_OF_COL = 10; + public static final int NOMINAL_ANNUAL_INTEREST_RATE_COL = 11; + public static final int INTEREST_COMPOUNDING_PERIOD_COL = 12; + public static final int INTEREST_POSTING_PERIOD_COL = 13; + public static final int INTEREST_CALCULATION_COL = 14; + public static final int INTEREST_CALCULATION_DAYS_IN_YEAR_COL = 15; + public static final int MIN_OPENING_BALANCE_COL = 16; + public static final int LOCKIN_PERIOD_COL = 17; + public static final int LOCKIN_PERIOD_FREQUENCY_COL = 18; + public static final int APPLY_WITHDRAWAL_FEE_FOR_TRANSFERS = 19; + public static final int ALLOW_OVER_DRAFT_COL = 20; + public static final int OVER_DRAFT_LIMIT_COL= 21; + public static final int EXTERNAL_ID_COL = 22; + public static final int STATUS_COL = 23; + public static final int SAVINGS_ID_COL = 24; + public static final int FAILURE_REPORT_COL = 25; + public static final int LOOKUP_CLIENT_NAME_COL = 31; + public static final int LOOKUP_ACTIVATION_DATE_COL = 32; + public static final int CHARGE_ID_1 = 34; + public static final int CHARGE_AMOUNT_1 = 35; + public static final int CHARGE_DUE_DATE_1 = 36; + public static final int CHARGE_ID_2 = 37; + public static final int CHARGE_AMOUNT_2 = 38; + public static final int CHARGE_DUE_DATE_2 = 39; +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/SharedAccountsConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/SharedAccountsConstants.java new file mode 100644 index 000000000..c3d8e61a3 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/SharedAccountsConstants.java @@ -0,0 +1,45 @@ +/** + * 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.constants; + +public class SharedAccountsConstants { + + public static final int CLIENT_NAME_COL=0; + public static final int PRODUCT_COL=1; + public static final int SUBMITTED_ON_COL=2; + public static final int EXTERNAL_ID_COL=3; + public static final int CURRENCY_COL=4; + public static final int DECIMAL_PLACES_COL=5; + public static final int TOTAL_NO_SHARES_COL=6; + public static final int TODAYS_PRICE_COL=7; + public static final int CURRENCY_IN_MULTIPLES_COL=8; + public static final int DEFAULT_SAVINGS_AC_COL=9; + public static final int MINIMUM_ACTIVE_PERIOD_IN_DAYS_COL=10; + public static final int LOCK_IN_PERIOD_COL=11; + public static final int LOCK_IN_PERIOD_FREQUENCY_TYPE=12; + public static final int APPLICATION_DATE_COL=13; + public static final int ALLOW_DIVIDEND_CALCULATION_FOR_INACTIVE_CLIENTS_COL=14; + public static final int CHARGES_NAME_1_COL=15; + public static final int CHARGES_AMOUNT_1_COL=16; + public static final int CHARGES_NAME_2_COL=17; + public static final int CHARGES_AMOUNT_2_COL=18; + public static final int CHARGES_NAME_3_COL=19; + public static final int CHARGES_AMOUNT_3_COL=20; + public static final int STATUS_COL=25; +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/StaffConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/StaffConstants.java new file mode 100644 index 000000000..f1d7d6a3a --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/StaffConstants.java @@ -0,0 +1,32 @@ +/** + * 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.constants; + +public class StaffConstants { + + public static final int OFFICE_NAME_COL = 0;//A + public static final int FIRST_NAME_COL = 1;//B + public static final int LAST_NAME_COL = 2;//C + public static final int IS_LOAN_OFFICER = 3;//D + public static final int MOBILE_NO_COL=4;//E + public static final int JOINED_ON_COL =5;//F + public static final int EXTERNAL_ID_COL =6;//G + public static final int IS_ACTIVE_COL =7;//h + public static final int STATUS_COL=8;//H +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/TemplatePopulateImportConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/TemplatePopulateImportConstants.java new file mode 100644 index 000000000..ba7ad96ae --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/TemplatePopulateImportConstants.java @@ -0,0 +1,143 @@ +/** + * 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.constants; + +public class TemplatePopulateImportConstants { + + //columns sizes + public final static int SMALL_COL_SIZE =4000; + public final static int MEDIUM_COL_SIZE =6000; + public final static int LARGE_COL_SIZE=8000; + public final static int EXTRALARGE_COL_SIZE=10000; + + //Sheet names + public static final String OFFICE_SHEET_NAME ="Offices"; + public static final String CENTER_SHEET_NAME="Centers"; + public static final String STAFF_SHEET_NAME="Staff"; + public static final String GROUP_SHEET_NAME="Groups"; + public static final String CHART_OF_ACCOUNTS_SHEET_NAME="ChartOfAccounts"; + public static final String CLIENT_ENTITY_SHEET_NAME="ClientEntity"; + public static final String CLIENT_PERSON_SHEET_NAME="ClientPerson"; + public static final String CLIENT_SHEET_NAME="Clients"; + public static final String FIXED_DEPOSIT_SHEET_NAME="FixedDeposit"; + public static final String FIXED_DEPOSIT_TRANSACTION_SHEET_NAME="FixedDepositTransactions"; + public static final String PRODUCT_SHEET_NAME="Products"; + public static final String GUARANTOR_SHEET_NAME="guarantor"; + public static final String EXTRAS_SHEET_NAME="Extras"; + public static final String GL_ACCOUNTS_SHEET_NAME="GlAccounts"; + public static final String SAVINGS_ACCOUNTS_SHEET_NAME="SavingsAccounts"; + public static final String SHARED_PRODUCTS_SHEET_NAME="SharedProducts"; + public static final String JOURNAL_ENTRY_SHEET_NAME="AddJournalEntries"; + public static final String LOANS_SHEET_NAME="Loans"; + public static final String LOAN_REPAYMENT_SHEET_NAME="LoanRepayment"; + public static final String RECURRING_DEPOSIT_SHEET_NAME="RecurringDeposit"; + public static final String SAVINGS_TRANSACTION_SHEET_NAME="SavingsTransaction"; + public static final String SHARED_ACCOUNTS_SHEET_NAME="SharedAccounts"; + public static final String EMPLOYEE_SHEET_NAME="Employee"; + public static final String ROLES_SHEET_NAME="Roles"; + public static final String USER_SHEET_NAME="Users"; + + public final static int ROWHEADER_INDEX=0; + public final static short ROW_HEADER_HEIGHT =500; + public final static int FIRST_COLUMN_INDEX=0; + + //Status column + public final static String STATUS_CELL_IMPORTED="Imported"; + public final static String STATUS_CREATION_FAILED="Creation failed"; + public final static String STATUS_APPROVAL_FAILED="Approval failed"; + public final static String STATUS_ACTIVATION_FAILED="Activation failed"; + public final static String STATUS_MEETING_FAILED="Meeting failed"; + public final static String STATUS_DISBURSAL_FAILED="Disbursal failed"; + public final static String STATUS_DISBURSAL_REPAYMENT_FAILED="Repayment failed"; + public final static String STATUS_COLUMN_HEADER="Status"; + + //Frequency Calender + public static final String FREQUENCY_DAILY="Daily"; + public static final String FREQUENCY_WEEKLY="Weekly"; + public static final String FREQUENCY_MONTHLY="Monthly"; + public static final String FREQUENCY_YEARLY= "Yearly"; + + //InterestCompoundingPeriod + public static final String INTEREST_COMPOUNDING_PERIOD_DAILY="Daily"; + public static final String INTEREST_COMPOUNDING_PERIOD_MONTHLY="Monthly"; + public static final String INTEREST_COMPOUNDING_PERIOD_QUARTERLY="Quarterly"; + public static final String INTEREST_COMPOUNDING_PERIOD_SEMI_ANNUALLY="Semi-Annual"; + public static final String INTEREST_COMPOUNDING_PERIOD_ANNUALLY="Annually"; + + //InterestPostingPeriod + public static final String INTEREST_POSTING_PERIOD_MONTHLY="Monthly"; + public static final String INTEREST_POSTING_PERIOD_QUARTERLY="Quarterly"; + public static final String INTEREST_POSTING_PERIOD_BIANUALLY="BiAnnual"; + public static final String INTEREST_POSTING_PERIOD_ANNUALLY="Annually"; + + //InterestCalculation + public static final String INTEREST_CAL_DAILY_BALANCE="Daily Balance"; + public static final String INTEREST_CAL_AVG_BALANCE="Average Daily Balance"; + + //InterestCalculation Day in Year + public static final String INTEREST_CAL_DAYS_IN_YEAR_360="360 Days"; + public static final String INTEREST_CAL_DAYS_IN_YEAR_365="365 Days"; + + //Frequency + public static final String FREQUENCY_DAYS="Days"; + public static final String FREQUENCY_WEEKS="Weeks"; + public static final String FREQUENCY_MONTHS="Months"; + public static final String FREQUENCY_YEARS="Years"; + + //Day Of Week + public static final String MONDAY ="Mon"; + public static final String TUESDAY ="Tue"; + public static final String WEDNESDAY ="Wed"; + public static final String THURSDAY ="Thu"; + public static final String FRIDAY ="Fri"; + public static final String SATURDAY ="Sat"; + public static final String SUNDAY ="Sun"; + + //Entity types + public static final String CENTER_ENTITY_TYPE="CENTER"; + public static final String OFFICE_ENTITY_TYPE="OFFICE"; + public static final String STAFF_ENTITY_TYPE="STAFF"; + public static final String USER_ENTITY_TYPE="USER"; + public static final String GROUP_ENTITY_TYPE="GROUP"; + public static final String CLIENT_ENTITY_TYPE="CLIENT"; + public static final String LOAN_PRODUCT_ENTITY_TYPE="LOANPRODUCT"; + public static final String FUNDS_ENTITY_TYPE="FUNDS"; + public static final String PAYMENT_TYPE_ENTITY_TYPE="PAYMENTTYPE"; + public static final String CURRENCY_ENTITY_TYPE="CURRENCY"; + public static final String GL_ACCOUNT_ENTITY_TYPE="GLACCOUNT"; + public static final String SHARED_ACCOUNT_ENTITY_TYPE="SHAREDACCOUNT"; + public static final String SAVINGS_PRODUCT_ENTITY_TYPE="SAVINGSPRODUCT"; + public static final String RECURRING_DEPOSIT_PRODUCT_ENTITY_TYPE="RECURRINGDEPOSITPRODUCT"; + public static final String FIXED_DEPOSIT_PRODUCT_ENTITY_TYPE="FIXEDDEPOSITPRODUCT"; + + //ReportHeader Values + public static final String STATUS_COL_REPORT_HEADER="Status"; + public static final String CENTERID_COL_REPORT_HEADER="Center Id"; + public static final String SAVINGS_ID_COL_REPORT_HEADER="Savings ID"; + public static final String GROUP_ID_COL_REPORT_HEADER="Group ID"; + public static final String FAILURE_COL_REPORT_HEADER="Failure Report"; + + //Guarantor Types + public static final String GUARANTOR_INTERNAL="Internal"; + public static final String GUARANTOR_EXTERNAL="External"; + + //Loan Account/Loan repayment Client External Id + public static final Boolean CONTAINS_CLIENT_EXTERNAL_ID=true; + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/TransactionConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/TransactionConstants.java new file mode 100644 index 000000000..acfa73efd --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/TransactionConstants.java @@ -0,0 +1,43 @@ +/** + * 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.constants; + +public class TransactionConstants { + + public static final int OFFICE_NAME_COL = 0; + public static final int CLIENT_NAME_COL = 1; + public static final int SAVINGS_ACCOUNT_NO_COL = 2; + public static final int PRODUCT_COL = 3; + public static final int OPENING_BALANCE_COL = 4; + public static final int TRANSACTION_TYPE_COL = 5; + public static final int AMOUNT_COL = 6; + public static final int TRANSACTION_DATE_COL = 7; + public static final int PAYMENT_TYPE_COL = 8; + public static final int ACCOUNT_NO_COL = 9; + public static final int CHECK_NO_COL = 10; + public static final int ROUTING_CODE_COL = 11; + public static final int RECEIPT_NO_COL = 12; + public static final int BANK_NO_COL = 13; + public static final int STATUS_COL = 14; + public static final int LOOKUP_CLIENT_NAME_COL = 15; + public static final int LOOKUP_ACCOUNT_NO_COL = 16; + public static final int LOOKUP_PRODUCT_COL = 17; + public static final int LOOKUP_OPENING_BALANCE_COL = 18; + public static final int LOOKUP_SAVINGS_ACTIVATION_DATE_COL = 19; +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/UserConstants.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/UserConstants.java new file mode 100644 index 000000000..b9b6c4c51 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/UserConstants.java @@ -0,0 +1,34 @@ +/** + * 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.constants; + +public class UserConstants { + public static final int OFFICE_NAME_COL=0; + public static final int STAFF_NAME_COL=1; + public static final int USER_NAME_COL=2; + public static final int FIRST_NAME_COL=3; + public static final int LAST_NAME_COL=4; + public static final int EMAIL_COL=5; + public static final int AUTO_GEN_PW_COL=6; + public static final int OVERRIDE_PW_EXPIRY_POLICY_COL=7; + public static final int STATUS_COL=8; + public static final int ROLE_NAME_START_COL=9; + public static final int ROLE_NAME_END_COL=14; + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/BulkImportEvent.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/BulkImportEvent.java new file mode 100644 index 000000000..0a493663d --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/BulkImportEvent.java @@ -0,0 +1,71 @@ +/** + * 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.data; + +import org.apache.poi.ss.usermodel.Workbook; +import org.springframework.context.ApplicationEvent; + +public class BulkImportEvent extends ApplicationEvent { + + private final String tenantIdentifier; + + private final Workbook workbook; + + private final Long importId; + + private final String locale; + + private final String dateFormat; + + private BulkImportEvent(final String tenantIdentifier, final Workbook workbook, + final Long importId, final String locale, final String dateFormat) { + super(BulkImportEvent.class); + this.tenantIdentifier = tenantIdentifier; + this.workbook = workbook; + this.importId = importId; + this.locale = locale; + this.dateFormat = dateFormat; + } + + public static BulkImportEvent instance(final String tenantIdentifier, final Workbook workbook, + final Long importId, final String locale, final String dateFormat) { + return new BulkImportEvent(tenantIdentifier, workbook, importId, locale, dateFormat); + } + + public String getTenantIdentifier() { + return tenantIdentifier; + } + + public Workbook getWorkbook() { + return workbook; + } + + public Long getImportId() { + return importId; + } + + public String getDateFormat() { + return dateFormat; + } + + public String getLocale() { + return locale; + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/Count.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/Count.java new file mode 100644 index 000000000..c4926c19b --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/Count.java @@ -0,0 +1,45 @@ +/** + * 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.data; + +public class Count { + + private Integer successCount; + private Integer errorCount; + + public static Count instance(final Integer successCount, + final Integer errorCount) { + return new Count(successCount, errorCount); + } + + private Count(final Integer successCount, + final Integer errorCount) { + this.successCount = successCount; + this.errorCount = errorCount; + } + + public Integer getSuccessCount() { + return successCount; + } + + public Integer getErrorCount() { + return errorCount; + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/GlobalEntityType.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/GlobalEntityType.java new file mode 100644 index 000000000..bb99a544a --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/GlobalEntityType.java @@ -0,0 +1,118 @@ +/** + * 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.data; + +import java.util.HashMap; +import java.util.Map; + +public enum GlobalEntityType { + + + INVALID(0, "invalid"), + CLIENTS_PERSON(1, "clients.person"), + CLIENTS_ENTTTY(2,"clients.entity"), + GROUPS(3, "groups"), + CENTERS(4, "centers"), + OFFICES(5, "offices"), + STAFF(6, "staff"), + USERS(7, "users"), + SMS(8, "sms"), + DOCUMENTS(9, "documents"), + TEMPLATES(10, "templates"), + NOTES(11, "templates"), + CALENDAR(12, "calendar"), + MEETINGS(13, "meetings"), + HOLIDAYS(14, "holidays"), + LOANS(15, "loans"), + LOAN_PRODUCTS(16,"loancharges"), + LOAN_TRANSACTIONS(18, "loantransactions"), + GUARANTORS(19, "guarantors"), + COLLATERALS(20, "collaterals"), + FUNDS(21, "funds"), + CURRENCY(22, "currencies"), + SAVINGS_ACCOUNT(23, "savingsaccount"), + SAVINGS_CHARGES(24, "savingscharges"), + SAVINGS_TRANSACTIONS(25, "savingstransactions"), + SAVINGS_PRODUCTS(26, "savingsproducts"), + GL_JOURNAL_ENTRIES(27, "gljournalentries"), + CODE_VALUE(28, "codevalue"), + CODE(29, "code"), + CHART_OF_ACCOUNTS(30,"chartofaccounts"), + FIXED_DEPOSIT_ACCOUNTS(31,"fixeddepositaccounts"), + FIXED_DEPOSIT_TRANSACTIONS(32,"fixeddeposittransactions"), + SHARE_ACCOUNTS(33,"shareaccounts"), + RECURRING_DEPOSIT_ACCOUNTS(34,"recurringdeposits"), + RECURRING_DEPOSIT_ACCOUNTS_TRANSACTIONS(35,"recurringdepositstransactions"), + CLIENT(36,"client"); + + private final Integer value; + private final String code; + + private static final Map intToEnumMap = new HashMap<>(); + private static final Map stringToEnumMap = new HashMap<>(); + private static int minValue; + private static int maxValue; + + static { + int i = 0; + for (final GlobalEntityType entityType : GlobalEntityType.values()) { + if (i == 0) { + minValue = entityType.value; + } + intToEnumMap.put(entityType.value, entityType); + stringToEnumMap.put(entityType.code, entityType); + if (minValue >= entityType.value) { + minValue = entityType.value; + } + if (maxValue < entityType.value) { + maxValue = entityType.value; + } + i = i + 1; + } + } + + private GlobalEntityType(final Integer value, final String code) { + this.value = value; + this.code = code; + } + + public Integer getValue() { + return this.value; + } + + public String getCode() { + return this.code; + } + + public static GlobalEntityType fromInt(final int i) { + final GlobalEntityType entityType = intToEnumMap.get(Integer.valueOf(i)); + return entityType; + } + + public static GlobalEntityType fromCode(final String key) { + final GlobalEntityType entityType = stringToEnumMap.get(key); + return entityType; + } + + @Override + public String toString() { + return name().toString(); + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/ImportData.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/ImportData.java new file mode 100644 index 000000000..635a6a94a --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/ImportData.java @@ -0,0 +1,80 @@ +/** + * 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.data; + +import org.joda.time.LocalDate; + +public class ImportData { + + @SuppressWarnings("unused") + private Long importId; + @SuppressWarnings("unused") + private Long documentId; + @SuppressWarnings("unused") + private String name; + @SuppressWarnings("unused") + private LocalDate importTime; + @SuppressWarnings("unused") + private LocalDate endTime; + @SuppressWarnings("unused") + private Boolean completed; + @SuppressWarnings("unused") + private Long createdBy; + @SuppressWarnings("unused") + private Integer totalRecords; + @SuppressWarnings("unused") + private Integer successCount; + @SuppressWarnings("unused") + private Integer failureCount; + + public static ImportData instance(final Long importId, final Long documentId, + final LocalDate importTime, final LocalDate endTime, + final Boolean completed, final String name, + final Long createdBy, final Integer totalRecords, final Integer successCount, + final Integer failureCount) { + return new ImportData(importId, documentId, importTime, endTime, + completed, name, createdBy, totalRecords, successCount, + failureCount); + } + + public static ImportData instance(final Long importId){ + return new ImportData(importId,null,null, + null,null,null,null,null, + null,null); + } + + private ImportData(final Long importId, final Long documentId, + final LocalDate importTime, final LocalDate endTime, + final Boolean completed, final String name, + final Long createdBy, final Integer totalRecords, final Integer successCount, + final Integer failureCount) { + this.importId = importId; + this.documentId = documentId; + this.name = name; + this.importTime = importTime; + this.endTime = endTime; + this.completed = completed; + this.createdBy = createdBy; + this.totalRecords = totalRecords; + this.successCount = successCount; + this.failureCount = failureCount; + } + + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/ImportFormatType.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/ImportFormatType.java new file mode 100644 index 000000000..29bbe61a9 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/ImportFormatType.java @@ -0,0 +1,49 @@ +/** + * 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.data; + +import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; + +public enum ImportFormatType { + + XLSX ("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"), + XLS ("application/vnd.ms-excel"), + ODS ("application/vnd.oasis.opendocument.spreadsheet"); + + + private final String format; + + private ImportFormatType(String format) { + this.format= format; + } + + public String getFormat() { + return format; + } + + public static ImportFormatType of(String name) { + for(ImportFormatType type : ImportFormatType.values()) { + if(type.name().equalsIgnoreCase(name)) { + return type; + } + } + throw new GeneralPlatformDomainRuleException("error.msg.invalid.file.extension", + "Uploaded file extension is not recognized."); + } +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/domain/ImportDocument.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/domain/ImportDocument.java new file mode 100644 index 000000000..5e65be248 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/domain/ImportDocument.java @@ -0,0 +1,124 @@ +/** + * 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.domain; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; +import org.apache.fineract.infrastructure.documentmanagement.domain.Document; +import org.apache.fineract.useradministration.domain.AppUser; +import org.joda.time.LocalDate; +import org.joda.time.LocalDateTime; + +@Entity +@Table(name = "m_import_document") +public class ImportDocument extends AbstractPersistableCustom{ + + @OneToOne + @JoinColumn(name = "document_id") + private Document document; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "import_time") + private Date importTime; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "end_time") + private Date endTime; + + @Column(name = "completed", nullable = false) + private Boolean completed; + + @Column(name = "entity_type") + private Integer entity_type; + + @ManyToOne + @JoinColumn(name = "createdby_id") + private AppUser createdBy; + + @Column(name = "total_records", nullable = true) + private Integer totalRecords; + + @Column(name = "success_count", nullable = true) + private Integer successCount; + + @Column(name = "failure_count", nullable = true) + private Integer failureCount; + + protected ImportDocument() { + + } + + public static ImportDocument instance(final Document document, final LocalDateTime importTime, + final Integer entity_type, final AppUser createdBy, final Integer totalRecords) { + + final Boolean completed = Boolean.FALSE; + final Integer successCount = 0; + final Integer failureCount = 0; + final LocalDateTime endTime = LocalDateTime.now(); + + return new ImportDocument(document, importTime, endTime, completed, entity_type, + createdBy, totalRecords, successCount, failureCount); + } + + private ImportDocument(final Document document, final LocalDateTime importTime, + final LocalDateTime endTime, Boolean completed, final Integer entity_type, + final AppUser createdBy, final Integer totalRecords, final Integer successCount, + final Integer failureCount) { + this.document = document; + this.importTime = importTime.toDate(); + this.endTime = endTime.toDate(); + this.completed = completed; + this.entity_type = entity_type; + this.createdBy = createdBy; + this.totalRecords = totalRecords; + this.successCount = successCount; + this.failureCount = failureCount; + + } + + public void update(final LocalDateTime endTime, final Integer successCount, + final Integer errorCount) { + this.endTime = endTime.toDate(); + this.completed = Boolean.TRUE; + this.successCount = successCount; + this.failureCount = errorCount; + } + + public Document getDocument() { + return this.document; + } + + public Integer getEntityType() { + return this.entity_type; + } + + + + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/domain/ImportDocumentRepository.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/domain/ImportDocumentRepository.java new file mode 100644 index 000000000..18e0d3d73 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/domain/ImportDocumentRepository.java @@ -0,0 +1,27 @@ +/** + * 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.domain; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +public interface ImportDocumentRepository + extends JpaRepository, JpaSpecificationExecutor { + // no added behaviour +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/exceptions/ImportTypeNotFoundException.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/exceptions/ImportTypeNotFoundException.java new file mode 100644 index 000000000..2754c2ac7 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/exceptions/ImportTypeNotFoundException.java @@ -0,0 +1,29 @@ +/** + * 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.exceptions; + +import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException; + +public class ImportTypeNotFoundException extends AbstractPlatformResourceNotFoundException { + + public ImportTypeNotFoundException(final String entityType) { + super("error.msg.entity.type.invalid", "Entity type " + entityType + " does not exist", entityType); + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/ImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/ImportHandler.java new file mode 100644 index 000000000..e185d3888 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/ImportHandler.java @@ -0,0 +1,27 @@ +/** + * 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; + +import org.apache.fineract.infrastructure.bulkimport.data.Count; +import org.apache.poi.ss.usermodel.Workbook; + +public interface ImportHandler { + public Count process(Workbook workbook, String locale, String dateFormat); +} + diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/ImportHandlerUtils.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/ImportHandlerUtils.java new file mode 100644 index 000000000..36bd1d896 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/ImportHandlerUtils.java @@ -0,0 +1,355 @@ +/** + * 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 from 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; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.core.data.ApiParameterError; +import org.apache.fineract.infrastructure.core.exception.*; +import org.apache.poi.ss.usermodel.*; +import org.joda.time.LocalDate; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +public class ImportHandlerUtils { + + public static Integer getNumberOfRows(Sheet sheet, int primaryColumn) { + Integer noOfEntries = 0; + // getLastRowNum and getPhysicalNumberOfRows showing false values + // sometimes + while (sheet.getRow(noOfEntries+1) !=null && sheet.getRow(noOfEntries+1).getCell(primaryColumn) != null) { + noOfEntries++; + } + + return noOfEntries; + } + + public static boolean isNotImported(Row row, int statusColumn) { + if (readAsString(statusColumn,row)!=null) { + return !readAsString(statusColumn, row).equals(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED); + }else { + return true; + } + } + + public static Long readAsLong(int colIndex, Row row) { + Cell c = row.getCell(colIndex); + if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) + return null; + FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); + if(c.getCellType() == Cell.CELL_TYPE_FORMULA) { + if(eval!=null) { + CellValue val = eval.evaluate(c); + return ((Double) val.getNumberValue()).longValue(); + } + } + else if (c.getCellType()==Cell.CELL_TYPE_NUMERIC){ + return ((Double) c.getNumericCellValue()).longValue(); + } + else { + return Long.parseLong(row.getCell(colIndex).getStringCellValue()); + } + return null; + } + + + public static String readAsString(int colIndex, Row row) { + + Cell c = row.getCell(colIndex); + if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) + return null; + FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); + if(c.getCellType() == Cell.CELL_TYPE_FORMULA) { + if (eval!=null) { + CellValue val = eval.evaluate(c); + String res = trimEmptyDecimalPortion(val.getStringValue()); + if (res!=null) { + if (!res.equals("")) { + return res.trim(); + } else { + return null; + } + }else { + return null; + } + }else { + return null; + } + }else if(c.getCellType()==Cell.CELL_TYPE_STRING) { + String res = trimEmptyDecimalPortion(c.getStringCellValue().trim()); + return res.trim(); + + }else if(c.getCellType()==Cell.CELL_TYPE_NUMERIC) { + return ((Double) row.getCell(colIndex).getNumericCellValue()).intValue() + ""; + }else if (c.getCellType()==Cell.CELL_TYPE_BOOLEAN){ + return c.getBooleanCellValue()+""; + }else { + return null; + } + } + + + public static String trimEmptyDecimalPortion(String result) { + if(result != null && result.endsWith(".0")) + return result.split("\\.")[0]; + else + return result; + } + + public static LocalDate readAsDate(int colIndex, Row row) { + Cell c = row.getCell(colIndex); + if(c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) + return null; + + LocalDate localDate=new LocalDate(c.getDateCellValue()); + return localDate; + } + + public static Boolean readAsBoolean(int colIndex, Row row) { + Cell c = row.getCell(colIndex); + if(c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) + return false; + FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); + if(c.getCellType() == Cell.CELL_TYPE_FORMULA) { + if(eval!=null) { + CellValue val = eval.evaluate(c); + return val.getBooleanValue(); + } + return false; + }else if(c.getCellType()==Cell.CELL_TYPE_BOOLEAN) + return c.getBooleanCellValue(); + else { + String booleanString = row.getCell(colIndex).getStringCellValue().trim(); + if (booleanString.equalsIgnoreCase("TRUE")) + return true; + else + return false; + } + } + + public static Integer readAsInt(int colIndex, Row row) { + Cell c = row.getCell(colIndex); + if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) + return null; + FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); + if(c.getCellType() == Cell.CELL_TYPE_FORMULA) { + if(eval!=null) { + CellValue val = eval.evaluate(c); + return ((Double) val.getNumberValue()).intValue(); + } + return null; + }else if (c.getCellType()==Cell.CELL_TYPE_NUMERIC) { + return ((Double) c.getNumericCellValue()).intValue(); + }else { + return Integer.parseInt(row.getCell(colIndex).getStringCellValue()); + } + } + + public static Double readAsDouble(int colIndex, Row row) { + Cell c = row.getCell(colIndex); + if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) + return 0.0; + FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); + if(c.getCellType() == Cell.CELL_TYPE_FORMULA) { + if (eval!=null) { + CellValue val = eval.evaluate(c); + return val.getNumberValue(); + }else { + return 0.0; + } + } else if (c.getCellType()==Cell.CELL_TYPE_NUMERIC) { + return row.getCell(colIndex).getNumericCellValue(); + }else { + return Double.parseDouble(row.getCell(colIndex).getStringCellValue()); + } + } + + public static void writeString(int colIndex, Row row, String value) { + if(value!=null) + row.createCell(colIndex).setCellValue(value); + } + + public static CellStyle getCellStyle(Workbook workbook, IndexedColors color) { + CellStyle style = workbook.createCellStyle(); + style.setFillForegroundColor(color.getIndex()); + style.setFillPattern(CellStyle.SOLID_FOREGROUND); + return style; + } + + public static String getDefaultUserMessages(List ApiParameterErrorList){ + StringBuffer defaultUserMessages=new StringBuffer(); + for (ApiParameterError error:ApiParameterErrorList) { + defaultUserMessages=defaultUserMessages.append(error.getDefaultUserMessage()+'\t'); + } + return defaultUserMessages.toString(); + } + public static String getErrorList(List errorList){ + StringBuffer errors=new StringBuffer(); + for (String error: errorList) { + errors=errors.append(error); + } + return errors.toString(); + } + + public static void writeErrorMessage(Sheet sheet,Integer rowIndex,String errorMessage,int statusColumn){ + Cell statusCell = sheet.getRow(rowIndex).createCell(statusColumn); + statusCell.setCellValue(errorMessage); + statusCell.setCellStyle(getCellStyle(sheet.getWorkbook(), IndexedColors.RED)); + } + + public static String getErrorMessage(RuntimeException re) { + if (re instanceof AbstractPlatformDomainRuleException){ + AbstractPlatformDomainRuleException abstractPlatformDomainRuleException= (AbstractPlatformDomainRuleException) re; + return abstractPlatformDomainRuleException.getDefaultUserMessage(); + }else if (re instanceof AbstractPlatformResourceNotFoundException){ + AbstractPlatformResourceNotFoundException abstractPlatformResourceNotFoundException= (AbstractPlatformResourceNotFoundException) re; + return abstractPlatformResourceNotFoundException.getDefaultUserMessage(); + }else if (re instanceof AbstractPlatformServiceUnavailableException) { + AbstractPlatformServiceUnavailableException abstractPlatformServiceUnavailableException = (AbstractPlatformServiceUnavailableException) re; + return abstractPlatformServiceUnavailableException.getDefaultUserMessage(); + }else if (re instanceof PlatformDataIntegrityException){ + PlatformDataIntegrityException platformDataIntegrityException= (PlatformDataIntegrityException) re; + return platformDataIntegrityException.getDefaultUserMessage(); + }else if (re instanceof PlatformApiDataValidationException){ + PlatformApiDataValidationException platformApiDataValidationException=(PlatformApiDataValidationException) re; + return getDefaultUserMessages(platformApiDataValidationException.getErrors()); + }else if (re instanceof UnsupportedParameterException ){ + UnsupportedParameterException unsupportedParameterException= (UnsupportedParameterException) re; + return getErrorList(unsupportedParameterException.getUnsupportedParameters()); + }else { + if (re.getMessage()!=null) { + return re.getMessage(); + }else { + return re.getClass().getCanonicalName(); + } + } + } + + public static Long getIdByName (Sheet sheet, String name) { + String sheetName = sheet.getSheetName(); + if(!sheetName.equals(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME)) { + for (Row row : sheet) { + for (Cell cell : row) { + if(name!=null) { + if (cell.getCellType() == Cell.CELL_TYPE_STRING && cell.getRichStringCellValue().getString().trim().equals(name)) { + if (sheetName.equals(TemplatePopulateImportConstants.OFFICE_SHEET_NAME) || + sheetName.equals(TemplatePopulateImportConstants.GL_ACCOUNTS_SHEET_NAME) || + sheetName.equals(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME) || + sheetName.equals(TemplatePopulateImportConstants.SHARED_PRODUCTS_SHEET_NAME)|| + sheetName.equals(TemplatePopulateImportConstants.ROLES_SHEET_NAME)) { + if (row.getCell(cell.getColumnIndex() - 1).getCellType() == Cell.CELL_TYPE_NUMERIC) + return ((Double) row.getCell(cell.getColumnIndex() - 1).getNumericCellValue()).longValue(); + return 0L; + } else if (sheetName.equals(TemplatePopulateImportConstants.CLIENT_SHEET_NAME) || + sheetName.equals(TemplatePopulateImportConstants.CENTER_SHEET_NAME) || + sheetName.equals(TemplatePopulateImportConstants.GROUP_SHEET_NAME) || + sheetName.equals(TemplatePopulateImportConstants.STAFF_SHEET_NAME)) + if (row.getCell(cell.getColumnIndex() + 1).getCellType() == Cell.CELL_TYPE_NUMERIC) + return ((Double) row.getCell(cell.getColumnIndex() + 1).getNumericCellValue()).longValue(); + return 0L; + } + }else { + return 0L; + } + } + } + } else if (sheetName.equals(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME)) { + for(Row row : sheet) { + for(int i = 0; i < 2; i++) { + if (name != null) { + Cell cell = row.getCell(i); + if (cell.getCellType() == Cell.CELL_TYPE_STRING && cell.getRichStringCellValue().getString().trim().equals(name)) { + return ((Double) row.getCell(cell.getColumnIndex() - 1).getNumericCellValue()).longValue(); + } + }else { + return 0L; + } + } + } + } + return 0L; + } + public static String getCodeByName(Sheet sheet, String name) { + String sheetName = sheet.getSheetName(); + sheetName.equals(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME); + { + for (Row row : sheet) { + for (Cell cell : row) { + if (name!=null) { + if (cell.getCellType() == Cell.CELL_TYPE_STRING + && cell.getRichStringCellValue().getString().trim() + .equals(name)) { + return row.getCell(cell.getColumnIndex() - 1) + .getStringCellValue().toString(); + + } + } + } + } + } + return ""; + } + + public static String getFrequencyId(String frequency) { + if (frequency!=null) { + if (frequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_DAILY)) + frequency = "1"; + else if (frequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_WEEKLY)) + frequency = "2"; + else if (frequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_MONTHLY)) + frequency = "3"; + else if (frequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_YEARLY)) + frequency = "4"; + return frequency; + }else { + return null; + } + } + + public static String getRepeatsOnDayId(String repeatsOnDay) { + if (repeatsOnDay!=null) { + if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.MONDAY)) + repeatsOnDay = "1"; + else if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.TUESDAY)) + repeatsOnDay = "2"; + else if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.WEDNESDAY)) + repeatsOnDay = "3"; + else if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.THURSDAY)) + repeatsOnDay = "4"; + else if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.FRIDAY)) + repeatsOnDay = "5"; + + else if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.SATURDAY)) + repeatsOnDay = "6"; + else if (repeatsOnDay.equalsIgnoreCase(TemplatePopulateImportConstants.SUNDAY)) + repeatsOnDay = "7"; + return repeatsOnDay; + }else { + return null; + } + } +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/center/CenterImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/center/CenterImportHandler.java new file mode 100644 index 000000000..958f1ddd1 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/center/CenterImportHandler.java @@ -0,0 +1,259 @@ +/** + * 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.center; + +import com.google.common.reflect.TypeToken; +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.CenterConstants; +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.bulkimport.importhandler.helper.GroupIdSerializer; +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.calendar.data.CalendarData; +import org.apache.fineract.portfolio.group.data.CenterData; +import org.apache.fineract.portfolio.group.data.GroupGeneralData; +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.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +@Service +public class CenterImportHandler implements ImportHandler { + + + private List centers; + private List meetings; + private Liststatuses; + private Workbook workbook; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + + @Autowired + public CenterImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.centers=new ArrayList<>(); + this.meetings=new ArrayList<>(); + this.statuses=new ArrayList<>(); + this.workbook=workbook; + readExcelFile(locale, dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(final String locale, final String dateFormat) { + + Sheet centersSheet = workbook.getSheet(TemplatePopulateImportConstants.CENTER_SHEET_NAME); + Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(centersSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX); + for (int rowIndex = 1; rowIndex <=noOfEntries; rowIndex++) { + Row row; + row = centersSheet.getRow(rowIndex); + if(ImportHandlerUtils.isNotImported(row, CenterConstants.STATUS_COL)) { + centers.add(readCenter(row,locale,dateFormat)); + meetings.add(readMeeting(row,locale,dateFormat)); + } + } + } + + private CalendarData readMeeting(Row row,final String locale, final String dateFormat) { + LocalDate meetingStartDate = ImportHandlerUtils.readAsDate(CenterConstants.MEETING_START_DATE_COL, row); + Boolean isRepeating = ImportHandlerUtils.readAsBoolean(CenterConstants.IS_REPEATING_COL, row); + String frequency = ImportHandlerUtils.readAsString(CenterConstants.FREQUENCY_COL, row); + EnumOptionData frequencyEnum=new EnumOptionData(null,null,ImportHandlerUtils.getFrequencyId(frequency)); + Integer interval = ImportHandlerUtils.readAsInt(CenterConstants.INTERVAL_COL, row); + String repeatsOnDay = ImportHandlerUtils.readAsString(CenterConstants.REPEATS_ON_DAY_COL, row); + EnumOptionData repeatsOnDayEnum=new EnumOptionData(null,null,ImportHandlerUtils.getRepeatsOnDayId(repeatsOnDay)); + if(meetingStartDate==null) + return null; + else { + if(repeatsOnDay==null) + return CalendarData.importInstanceNoRepeatsOnDay(meetingStartDate, isRepeating, + frequencyEnum, interval, row.getRowNum(),locale,dateFormat); + else + return CalendarData.importInstanceWithRepeatsOnDay(meetingStartDate, isRepeating, + frequencyEnum, interval, repeatsOnDayEnum, row.getRowNum(),locale,dateFormat); + } + } + + private CenterData readCenter(Row row,final String locale, final String dateFormat) { + String status = ImportHandlerUtils.readAsString(CenterConstants.STATUS_COL, row); + String officeName = ImportHandlerUtils.readAsString(CenterConstants.OFFICE_NAME_COL, row); + Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName); + String staffName = ImportHandlerUtils.readAsString(CenterConstants.STAFF_NAME_COL, row); + Long staffId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), staffName); + + String externalId = ImportHandlerUtils.readAsString(CenterConstants.EXTERNAL_ID_COL, row); + Boolean active = ImportHandlerUtils.readAsBoolean(CenterConstants.ACTIVE_COL, row); + LocalDate submittedOn=ImportHandlerUtils.readAsDate(CenterConstants.SUBMITTED_ON_DATE_COL,row); + LocalDate activationDate = null; + if (active){ + activationDate=ImportHandlerUtils.readAsDate(CenterConstants.ACTIVATION_DATE_COL, row); + }else { + activationDate=submittedOn; + } + String centerName = ImportHandlerUtils.readAsString(CenterConstants.CENTER_NAME_COL, row); + if(centerName==null||centerName.equals("")) { + throw new IllegalArgumentException("Name is blank"); + } + List groupMembers = new ArrayList(); + for (int cellNo =CenterConstants. GROUP_NAMES_STARTING_COL; cellNo < CenterConstants.GROUP_NAMES_ENDING_COL; cellNo++) { + String groupName = ImportHandlerUtils.readAsString(cellNo, row); + if (groupName==null||groupName.equals("")) + break; + Long groupId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME), groupName); + GroupGeneralData group = new GroupGeneralData(groupId); + if (!containsGroupId(groupMembers,groupId)) { + groupMembers.add(group); + } + } + + statuses.add(status); + return CenterData.importInstance(centerName,groupMembers,activationDate, active,submittedOn, externalId, + officeId, staffId, row.getRowNum(),dateFormat,locale); + } + + private boolean containsGroupId(List groupMembers,Long groupId){ + for (GroupGeneralData group: groupMembers) { + if (group.getId()==groupId){ + return true; + } + } + return false; + } + + public Count importEntity(String dateFormat) { + Sheet centerSheet = workbook.getSheet(TemplatePopulateImportConstants.CENTER_SHEET_NAME); + int progressLevel = 0; + String centerId = ""; + int successCount = 0; + int errorCount = 0; + String errorMessage = ""; + for (int i = 0; i < centers.size(); i++) { + Row row = centerSheet.getRow(centers.get(i).getRowIndex()); + Cell errorReportCell = row.createCell(CenterConstants.FAILURE_COL); + Cell statusCell = row.createCell(CenterConstants.STATUS_COL); + CommandProcessingResult result = null; + try { + String status = statuses.get(i); + progressLevel = getProgressLevel(status); + + if (progressLevel == 0) { + result = importCenter(i, dateFormat); + centerId = result.getGroupId().toString(); + progressLevel = 1; + } else + centerId = ImportHandlerUtils.readAsInt(CenterConstants.CENTER_ID_COL, centerSheet.getRow(centers.get(i).getRowIndex())).toString(); + + if (meetings.get(i) != null) + progressLevel = importCenterMeeting(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); + writeCenterErrorMessage(centerId,errorMessage,progressLevel,statusCell,errorReportCell,row); + } + } + setReportHeaders(centerSheet); + return Count.instance(successCount, errorCount); + } + + private void writeCenterErrorMessage(String centerId,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_MEETING_FAILED; + statusCell.setCellValue(status); + statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.RED)); + + if (progressLevel > 0) + row.createCell(CenterConstants.CENTER_ID_COL).setCellValue(Integer.parseInt(centerId)); + errorReportCell.setCellValue(errorMessage); + } + + private int getProgressLevel(String status) { + + if(status==null || status.equals(TemplatePopulateImportConstants.STATUS_CREATION_FAILED)) + return 0; + else if(status.equals(TemplatePopulateImportConstants.STATUS_MEETING_FAILED)) + return 1; + return 0; + } + private CommandProcessingResult importCenter(int rowIndex,String dateFormat) { + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + Type groupCollectionType = new TypeToken>() {}.getType(); + gsonBuilder.registerTypeAdapter(groupCollectionType,new GroupIdSerializer()); + String payload= gsonBuilder.create().toJson(centers.get(rowIndex));; + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createCenter() // + .withJson(payload) // + .build(); // + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + return result; + } + + private void setReportHeaders(Sheet sheet) { + ImportHandlerUtils.writeString(CenterConstants.STATUS_COL, sheet.getRow(0), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER); + ImportHandlerUtils.writeString(CenterConstants.CENTER_ID_COL, sheet.getRow(0), TemplatePopulateImportConstants.CENTERID_COL_REPORT_HEADER); + ImportHandlerUtils.writeString(CenterConstants.FAILURE_COL, sheet.getRow(0), TemplatePopulateImportConstants.FAILURE_COL_REPORT_HEADER); + } + + private Integer importCenterMeeting(CommandProcessingResult result, int rowIndex,String dateFormat) { + CalendarData calendarData=meetings.get(rowIndex); + calendarData.setTitle("centers_" + result.getGroupId().toString() + "_CollectionMeeting"); + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + gsonBuilder.registerTypeAdapter(EnumOptionData.class,new EnumOptionDataValueSerializer()); + + String payload = gsonBuilder.create().toJson(calendarData); + CommandWrapper commandWrapper=new CommandWrapper(result.getOfficeId(),result.getGroupId(),result.getClientId(), + result.getLoanId(),result.getSavingsId(),null,null,null,null, + null,payload,result.getTransactionId(),result.getProductId(),null,null, + null); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createCalendar(commandWrapper,TemplatePopulateImportConstants.CENTER_ENTITY_TYPE,result.getGroupId()) // + .withJson(payload) // + .build(); // + final CommandProcessingResult meetingresult = commandsSourceWritePlatformService.logCommandSource(commandRequest); + return 2; + } + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/chartofaccounts/ChartOfAccountsImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/chartofaccounts/ChartOfAccountsImportHandler.java new file mode 100644 index 000000000..c31099ad9 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/chartofaccounts/ChartOfAccountsImportHandler.java @@ -0,0 +1,143 @@ +/** + * 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 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); + EnumOptionData accountTypeEnum=GLAccountType.fromString(accountType); + String accountName=ImportHandlerUtils.readAsString(ChartOfAcountsConstants.ACCOUNT_NAME_COL,row); + String usage=ImportHandlerUtils.readAsString(ChartOfAcountsConstants.ACCOUNT_USAGE_COL,row); + Long usageId=null; + EnumOptionData usageEnum=null; + if (usage!=null&& usage.equals(GLAccountUsage.DETAIL.toString())){ + usageId=1L; + usageEnum=new EnumOptionData(usageId,null,null); + }else if (usage!=null&&usage.equals(GLAccountUsage.HEADER.toString())){ + usageId=2L; + usageEnum=new EnumOptionData(usageId,null,null); + } + Boolean manualEntriesAllowed=ImportHandlerUtils.readAsBoolean(ChartOfAcountsConstants.MANUAL_ENTRIES_ALLOWED_COL,row); + Long parentId=null; + if (ImportHandlerUtils.readAsString(ChartOfAcountsConstants.PARENT_ID_COL,row)!=null) { + parentId = Long.parseLong(ImportHandlerUtils.readAsString(ChartOfAcountsConstants.PARENT_ID_COL,row)); + } + String glCode=ImportHandlerUtils.readAsString(ChartOfAcountsConstants.GL_CODE_COL,row); + Long tagId=null; + if(ImportHandlerUtils.readAsString(ChartOfAcountsConstants.TAG_ID_COL,row)!=null) + tagId=Long.parseLong(ImportHandlerUtils.readAsString(ChartOfAcountsConstants.TAG_ID_COL,row)); + CodeValueData tagIdCodeValueData=new CodeValueData(tagId); + String description=ImportHandlerUtils.readAsString(ChartOfAcountsConstants.DESCRIPTION_COL,row); + return GLAccountData.importInstance(accountName,parentId,glCode,manualEntriesAllowed,accountTypeEnum, + usageEnum,description,tagIdCodeValueData,row.getRowNum()); + } + + public Count importEntity() { + 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()); + 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++; + ex.printStackTrace(); + errorMessage=ImportHandlerUtils.getErrorMessage(ex); + ImportHandlerUtils.writeErrorMessage(chartOfAccountsSheet,glAccount.getRowIndex(),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); + } + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientEntityImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientEntityImportHandler.java new file mode 100644 index 000000000..36fb4cdb8 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientEntityImportHandler.java @@ -0,0 +1,212 @@ +/** + * 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.client; + +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.ClientEntityConstants; +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.address.data.AddressData; +import org.apache.fineract.portfolio.client.data.ClientData; +import org.apache.fineract.portfolio.client.data.ClientNonPersonData; +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 ClientEntityImportHandler implements ImportHandler { + + private Workbook workbook; + private List clients; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + + @Autowired + public ClientEntityImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook = workbook; + this.clients=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(final String locale, final String dateFormat) { + Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME); + Integer noOfEntries= ImportHandlerUtils.getNumberOfRows(clientSheet,0); + for (int rowIndex=1;rowIndex<=noOfEntries;rowIndex++){ + Row row; + row=clientSheet.getRow(rowIndex); + if (ImportHandlerUtils.isNotImported(row, ClientEntityConstants.STATUS_COL)){ + clients.add(readClient(row,locale,dateFormat)); + } + } + } + + private ClientData readClient(Row row,final String locale, final String dateFormat) { + Long legalFormId=2L; + String name = ImportHandlerUtils.readAsString(ClientEntityConstants.NAME_COL, row); + String officeName = ImportHandlerUtils.readAsString(ClientEntityConstants.OFFICE_NAME_COL, row); + Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName); + String staffName = ImportHandlerUtils.readAsString(ClientEntityConstants.STAFF_NAME_COL, row); + Long staffId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), staffName); + LocalDate incorportionDate=ImportHandlerUtils.readAsDate(ClientEntityConstants.INCOPORATION_DATE_COL,row); + LocalDate incorporationTill=ImportHandlerUtils.readAsDate(ClientEntityConstants.INCOPORATION_VALID_TILL_COL,row); + String mobileNo=null; + if (ImportHandlerUtils.readAsLong(ClientEntityConstants.MOBILE_NO_COL, row)!=null) + mobileNo = ImportHandlerUtils.readAsLong(ClientEntityConstants.MOBILE_NO_COL, row).toString(); + + String clientType=ImportHandlerUtils.readAsString(ClientEntityConstants.CLIENT_TYPE_COL, row); + Long clientTypeId = null; + if (clientType!=null) { + String clientTypeAr[] =clientType .split("-"); + if (clientTypeAr[1] != null) { + clientTypeId = Long.parseLong(clientTypeAr[1]); + } + } + String clientClassification= ImportHandlerUtils.readAsString(ClientEntityConstants.CLIENT_CLASSIFICATION_COL, row); + Long clientClassicationId = null; + if (clientClassification!=null) { + String clientClassificationAr[] =clientClassification.split("-"); + if (clientClassificationAr[1] != null) + clientClassicationId = Long.parseLong(clientClassificationAr[1]); + } + String incorporationNo=ImportHandlerUtils.readAsString(ClientEntityConstants.INCOPORATION_NUMBER_COL,row); + + String mainBusinessLine=ImportHandlerUtils.readAsString(ClientEntityConstants.MAIN_BUSINESS_LINE,row); + Long mainBusinessId = null; + if (mainBusinessLine!=null) { + String mainBusinessLineAr[] = ImportHandlerUtils.readAsString(ClientEntityConstants.MAIN_BUSINESS_LINE, row).split("-"); + if (mainBusinessLineAr[1] != null) + mainBusinessId = Long.parseLong(mainBusinessLineAr[1]); + } + String constitution= ImportHandlerUtils.readAsString(ClientEntityConstants.CONSTITUTION_COL,row); + Long constitutionId = null; + if (constitution!=null) { + String constitutionAr[] = constitution.split("-"); + if (constitutionAr[1] != null) + constitutionId = Long.parseLong(constitutionAr[1]); + } + String remarks = ImportHandlerUtils.readAsString(ClientEntityConstants.REMARKS_COL, row); + + ClientNonPersonData clientNonPersonData= ClientNonPersonData.importInstance(incorporationNo,incorporationTill,remarks, + mainBusinessId,constitutionId,locale,dateFormat); + + String externalId= ImportHandlerUtils.readAsString(ClientEntityConstants.EXTERNAL_ID_COL, row); + + Boolean active = ImportHandlerUtils.readAsBoolean(ClientEntityConstants.ACTIVE_COL, row); + + LocalDate submittedOn=ImportHandlerUtils.readAsDate(ClientEntityConstants.SUBMITTED_ON_COL,row); + + LocalDate activationDate = ImportHandlerUtils.readAsDate(ClientEntityConstants.ACTIVATION_DATE_COL, row); + if (!active){ + activationDate=submittedOn; + } + AddressData addressDataObj=null; + if (ImportHandlerUtils.readAsBoolean(ClientEntityConstants.ADDRESS_ENABLED,row)) { + String addressType = ImportHandlerUtils.readAsString(ClientEntityConstants.ADDRESS_TYPE_COL, row); + Long addressTypeId = null; + if (addressType!=null) { + String addressTypeAr[] = addressType.split("-"); + if (addressTypeAr[1] != null) + addressTypeId = Long.parseLong(addressTypeAr[1]); + } + String street = ImportHandlerUtils.readAsString(ClientEntityConstants.STREET_COL, row); + String addressLine1 = ImportHandlerUtils.readAsString(ClientEntityConstants.ADDRESS_LINE_1_COL, row); + String addressLine2 = ImportHandlerUtils.readAsString(ClientEntityConstants.ADDRESS_LINE_2_COL, row); + String addressLine3 = ImportHandlerUtils.readAsString(ClientEntityConstants.ADDRESS_LINE_3_COL, row); + String city = ImportHandlerUtils.readAsString(ClientEntityConstants.CITY_COL, row); + + String postalCode = ImportHandlerUtils.readAsString(ClientEntityConstants.POSTAL_CODE_COL, row); + Boolean isActiveAddress = ImportHandlerUtils.readAsBoolean(ClientEntityConstants.IS_ACTIVE_ADDRESS_COL, row); + + String stateProvince=ImportHandlerUtils.readAsString(ClientEntityConstants.STATE_PROVINCE_COL, row); + Long stateProvinceId = null; + if (stateProvince!=null) { + String stateProvinceAr[] = stateProvince.split("-"); + if (stateProvinceAr[1] != null) + stateProvinceId = Long.parseLong(stateProvinceAr[1]); + } + String country= ImportHandlerUtils.readAsString(ClientEntityConstants.COUNTRY_COL, row); + Long countryId = null; + if (country!=null) { + String countryAr[] = country.split("-"); + if (countryAr[1] != null) + countryId = Long.parseLong(countryAr[1]); + } + addressDataObj = new AddressData(addressTypeId, street, addressLine1, addressLine2, addressLine3, + city, postalCode, isActiveAddress, stateProvinceId, countryId); + } + return ClientData.importClientEntityInstance(legalFormId,row.getRowNum(),name,officeId,clientTypeId,clientClassicationId, + staffId,active,activationDate,submittedOn, externalId,incorportionDate,mobileNo,clientNonPersonData,addressDataObj,locale,dateFormat); + } + + public Count importEntity(String dateFormat) { + Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME); + + int successCount = 0; + int errorCount = 0; + String errorMessage = ""; + + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + + for (ClientData client: clients) { + try { + String payload=gsonBuilder.create().toJson(client); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createClient() // + .withJson(payload) // + .build(); // + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + successCount++; + Cell statusCell = clientSheet.getRow(client.getRowIndex()).createCell(ClientEntityConstants.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(clientSheet,client.getRowIndex(),errorMessage,ClientEntityConstants.STATUS_COL); + } + } + clientSheet.setColumnWidth(ClientEntityConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + ImportHandlerUtils.writeString(ClientEntityConstants.STATUS_COL, clientSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), + TemplatePopulateImportConstants.STATUS_COLUMN_HEADER); + + return Count.instance(successCount,errorCount); + } + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientPersonImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientPersonImportHandler.java new file mode 100644 index 000000000..34e0fae47 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientPersonImportHandler.java @@ -0,0 +1,197 @@ +/** + * 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.client; + +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.ClientPersonConstants; +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.address.data.AddressData; +import org.apache.fineract.portfolio.client.data.ClientData; +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 ClientPersonImportHandler implements ImportHandler { + + private Workbook workbook; + private List clients; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + + @Autowired + public ClientPersonImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook = workbook; + this.clients=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(final String locale, final String dateFormat) { + Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME); + Integer noOfEntries= ImportHandlerUtils.getNumberOfRows(clientSheet,0); + for (int rowIndex=1;rowIndex<=noOfEntries;rowIndex++){ + Row row; + row=clientSheet.getRow(rowIndex); + if (ImportHandlerUtils.isNotImported(row, ClientPersonConstants.STATUS_COL)){ + clients.add(readClient(row,locale,dateFormat)); + } + } + } + + private ClientData readClient(Row row,final String locale, final String dateFormat) { + Long legalFormId=1L; + String firstName = ImportHandlerUtils.readAsString(ClientPersonConstants.FIRST_NAME_COL, row); + String lastName = ImportHandlerUtils.readAsString(ClientPersonConstants.LAST_NAME_COL, row); + String middleName = ImportHandlerUtils.readAsString(ClientPersonConstants.MIDDLE_NAME_COL, row); + String officeName = ImportHandlerUtils.readAsString(ClientPersonConstants.OFFICE_NAME_COL, row); + Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName); + String staffName = ImportHandlerUtils.readAsString(ClientPersonConstants.STAFF_NAME_COL, row); + Long staffId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), staffName); + String externalId = ImportHandlerUtils.readAsString(ClientPersonConstants.EXTERNAL_ID_COL, row); + LocalDate submittedOn=ImportHandlerUtils.readAsDate(ClientPersonConstants.SUBMITTED_ON_COL,row); + LocalDate activationDate = ImportHandlerUtils.readAsDate(ClientPersonConstants.ACTIVATION_DATE_COL, row); + Boolean active = ImportHandlerUtils.readAsBoolean(ClientPersonConstants.ACTIVE_COL, row); + if (!active){ + activationDate=submittedOn; + } + String mobileNo=null; + if (ImportHandlerUtils.readAsLong(ClientPersonConstants.MOBILE_NO_COL, row)!=null) + mobileNo = ImportHandlerUtils.readAsLong(ClientPersonConstants.MOBILE_NO_COL, row).toString(); + LocalDate dob = ImportHandlerUtils.readAsDate(ClientPersonConstants.DOB_COL, row); + + String clientType=ImportHandlerUtils.readAsString(ClientPersonConstants.CLIENT_TYPE_COL, row); + Long clientTypeId = null; + if (clientType!=null) { + String clientTypeAr[] = clientType.split("-"); + if (clientTypeAr[1] != null) { + clientTypeId = Long.parseLong(clientTypeAr[1]); + } + } + String gender=ImportHandlerUtils.readAsString(ClientPersonConstants.GENDER_COL, row); + Long genderId = null; + if (gender!=null) { + String genderAr[] = gender.split("-"); + if (genderAr[1] != null) + genderId = Long.parseLong(genderAr[1]); + } + String clientClassification= ImportHandlerUtils.readAsString(ClientPersonConstants.CLIENT_CLASSIFICATION_COL, row); + Long clientClassicationId = null; + if (clientClassification!=null) { + String clientClassificationAr[] = clientClassification.split("-"); + if (clientClassificationAr[1] != null) + clientClassicationId = Long.parseLong(clientClassificationAr[1]); + } + Boolean isStaff = ImportHandlerUtils.readAsBoolean(ClientPersonConstants.IS_STAFF_COL, row); + + AddressData addressDataObj=null; + if (ImportHandlerUtils.readAsBoolean(ClientPersonConstants.ADDRESS_ENABLED_COL,row)) { + String addressType=ImportHandlerUtils.readAsString(ClientPersonConstants.ADDRESS_TYPE_COL, row); + Long addressTypeId = null; + if (addressType!=null) { + String addressTypeAr[] = addressType.split("-"); + + if (addressTypeAr[1] != null) + addressTypeId = Long.parseLong(addressTypeAr[1]); + } + String street = ImportHandlerUtils.readAsString(ClientPersonConstants.STREET_COL, row); + String addressLine1 = ImportHandlerUtils.readAsString(ClientPersonConstants.ADDRESS_LINE_1_COL, row); + String addressLine2 = ImportHandlerUtils.readAsString(ClientPersonConstants.ADDRESS_LINE_2_COL, row); + String addressLine3 = ImportHandlerUtils.readAsString(ClientPersonConstants.ADDRESS_LINE_3_COL, row); + String city = ImportHandlerUtils.readAsString(ClientPersonConstants.CITY_COL, row); + + String postalCode = ImportHandlerUtils.readAsString(ClientPersonConstants.POSTAL_CODE_COL, row); + Boolean isActiveAddress = ImportHandlerUtils.readAsBoolean(ClientPersonConstants.IS_ACTIVE_ADDRESS_COL, row); + + String stateProvince=ImportHandlerUtils.readAsString(ClientPersonConstants.STATE_PROVINCE_COL, row); + Long stateProvinceId = null; + if (stateProvince!=null) { + String stateProvinceAr[] = stateProvince.split("-"); + if (stateProvinceAr[1] != null) + stateProvinceId = Long.parseLong(stateProvinceAr[1]); + } + String country=ImportHandlerUtils.readAsString(ClientPersonConstants.COUNTRY_COL, row); + Long countryId=null; + if (country!=null) { + String countryAr[] = country.split("-"); + if (countryAr[1] != null) + countryId = Long.parseLong(countryAr[1]); + } + addressDataObj = new AddressData(addressTypeId, street, addressLine1, addressLine2, addressLine3, + city, postalCode, isActiveAddress, stateProvinceId, countryId); + } + return ClientData.importClientPersonInstance(legalFormId,row.getRowNum(),firstName,lastName,middleName,submittedOn,activationDate,active,externalId, + officeId,staffId,mobileNo,dob,clientTypeId,genderId,clientClassicationId,isStaff,addressDataObj,locale,dateFormat); + + } + + public Count importEntity(String dateFormat) { + Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME); + int successCount=0; + int errorCount=0; + String errorMessage=""; + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + for (ClientData client: clients) { + try { + String payload=gsonBuilder.create().toJson(client); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createClient() // + .withJson(payload) // + .build(); // + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + successCount++; + Cell statusCell = clientSheet.getRow(client.getRowIndex()).createCell(ClientPersonConstants.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(clientSheet,client.getRowIndex(),errorMessage,ClientPersonConstants.STATUS_COL); + } + } + clientSheet.setColumnWidth(ClientPersonConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + ImportHandlerUtils.writeString(ClientPersonConstants.STATUS_COL, clientSheet. + getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), TemplatePopulateImportConstants.STATUS_COLUMN_HEADER); + + return Count.instance(successCount,errorCount); + } + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/fixeddeposits/FixedDepositImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/fixeddeposits/FixedDepositImportHandler.java new file mode 100644 index 000000000..10118a5b2 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/fixeddeposits/FixedDepositImportHandler.java @@ -0,0 +1,390 @@ +/** + * 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.fixeddeposits; + +import com.google.gson.*; +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.FixedDepositConstants; +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.*; +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 FixedDepositImportHandler implements ImportHandler { + + private Workbook workbook; + + private List savings; + private List approvalDates; + private List activationDates; + private List closedOnDate; + private List statuses; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + + @Autowired + public FixedDepositImportHandler(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<>(); + closedOnDate=new ArrayList<>(); + statuses=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(final String locale, final String dateFormat) { + Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_SHEET_NAME); + Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX); + for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) { + Row row; + row = savingsSheet.getRow(rowIndex); + if (ImportHandlerUtils.isNotImported(row, FixedDepositConstants.STATUS_COL)) { + savings.add(readSavings(row,locale,dateFormat)); + approvalDates.add(readSavingsApproval(row,locale,dateFormat)); + activationDates.add(readSavingsActivation(row,locale,dateFormat)); + closedOnDate.add(readSavingsClosed(row,locale,dateFormat)); + } + } + + } + + private ClosingOfSavingsAccounts readSavingsClosed(Row row,String locale,String dateFormat) { + LocalDate closedOnDate = ImportHandlerUtils.readAsDate(FixedDepositConstants.CLOSED_ON_DATE, row); + Long onAccountClosureId = ImportHandlerUtils.readAsLong(FixedDepositConstants.ON_ACCOUNT_CLOSURE_ID, row); + Long toSavingsAccountId = ImportHandlerUtils.readAsLong(FixedDepositConstants.TO_SAVINGS_ACCOUNT_ID, row); + if (closedOnDate!=null) + return ClosingOfSavingsAccounts.importInstance(null, closedOnDate,onAccountClosureId,toSavingsAccountId, null, + row.getRowNum(),locale,dateFormat); + else + return null; + } + + private SavingsActivation readSavingsActivation(Row row,String locale,String dateFormat) { + LocalDate activationDate = ImportHandlerUtils.readAsDate(FixedDepositConstants.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(FixedDepositConstants.APPROVED_DATE_COL, row); + if (approvalDate!=null) + return SavingsApproval.importInstance(approvalDate, row.getRowNum(),locale,dateFormat); + else + return null; + } + + private FixedDepositAccountData readSavings(Row row,String locale,String dateFormat) { + + String productName = ImportHandlerUtils.readAsString(FixedDepositConstants.PRODUCT_COL, row); + Long productId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME), productName); + String fieldOfficerName = ImportHandlerUtils.readAsString(FixedDepositConstants.FIELD_OFFICER_NAME_COL, row); + Long fieldOfficerId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), fieldOfficerName); + LocalDate submittedOnDate = ImportHandlerUtils.readAsDate(FixedDepositConstants.SUBMITTED_ON_DATE_COL, row); + String interestCompoundingPeriodType = ImportHandlerUtils.readAsString(FixedDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL, row); + Long interestCompoundingPeriodTypeId = null; + EnumOptionData interestCompoundingPeriodTypeEnum=null; + if (interestCompoundingPeriodType!=null) { + if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_DAILY)) + interestCompoundingPeriodTypeId = 1L; + else if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_MONTHLY)) + interestCompoundingPeriodTypeId = 4L; + else if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_QUARTERLY)) + interestCompoundingPeriodTypeId = 5L; + else if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_SEMI_ANNUALLY)) + interestCompoundingPeriodTypeId = 6L; + else if (interestCompoundingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_ANNUALLY)) + interestCompoundingPeriodTypeId = 7L; + interestCompoundingPeriodTypeEnum = new EnumOptionData(interestCompoundingPeriodTypeId, null, null); + } + String interestPostingPeriodType = ImportHandlerUtils.readAsString(FixedDepositConstants.INTEREST_POSTING_PERIOD_COL, row); + Long interestPostingPeriodTypeId = null; + + EnumOptionData interestPostingPeriodTypeEnum=null; + if (interestCompoundingPeriodType!=null) { + if (interestPostingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_MONTHLY)) + interestPostingPeriodTypeId = 4L; + else if (interestPostingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_QUARTERLY)) + interestPostingPeriodTypeId = 5L; + else if (interestPostingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_ANNUALLY)) + interestPostingPeriodTypeId = 7L; + else if (interestPostingPeriodType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_BIANUALLY)) + interestPostingPeriodTypeId = 6L; + interestPostingPeriodTypeEnum = new EnumOptionData(interestPostingPeriodTypeId, null, null); + } + String interestCalculationType = ImportHandlerUtils.readAsString(FixedDepositConstants.INTEREST_CALCULATION_COL, row); + EnumOptionData interestCalculationTypeEnum=null; + if (interestCalculationType!=null) { + Long interestCalculationTypeId = null; + if (interestCalculationType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_CAL_DAILY_BALANCE)) + interestCalculationTypeId = 1L; + else if (interestCalculationType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_CAL_AVG_BALANCE)) + interestCalculationTypeId = 2L; + interestCalculationTypeEnum = new EnumOptionData(interestCalculationTypeId, null, null); + } + String interestCalculationDaysInYearType = ImportHandlerUtils.readAsString(FixedDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row); + Long interestCalculationDaysInYearTypeId = null; + EnumOptionData interestCalculationDaysInYearTypeEnum=null; + if (interestCalculationDaysInYearType!=null) { + if (interestCalculationDaysInYearType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_CAL_DAYS_IN_YEAR_360)) + interestCalculationDaysInYearTypeId = 360L; + else if (interestCalculationDaysInYearType.equalsIgnoreCase(TemplatePopulateImportConstants.INTEREST_CAL_DAYS_IN_YEAR_365)) + interestCalculationDaysInYearTypeId = 365L; + interestCalculationDaysInYearTypeEnum = new EnumOptionData(interestCalculationDaysInYearTypeId, null, null); + } + Integer lockinPeriodFrequency = ImportHandlerUtils.readAsInt(FixedDepositConstants.LOCKIN_PERIOD_COL, row); + String lockinPeriodFrequencyType = ImportHandlerUtils.readAsString(FixedDepositConstants.LOCKIN_PERIOD_FREQUENCY_COL, row); + + Long lockinPeriodFrequencyTypeId =null; + EnumOptionData lockinPeriodFrequencyTypeEnum=null; + if (lockinPeriodFrequencyType!=null) { + if (lockinPeriodFrequencyType.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_DAYS)) + lockinPeriodFrequencyTypeId = 0L; + else if (lockinPeriodFrequencyType.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_WEEKS)) + lockinPeriodFrequencyTypeId = 1L; + else if (lockinPeriodFrequencyType.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_MONTHS)) + lockinPeriodFrequencyTypeId = 2L; + else if (lockinPeriodFrequencyType.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_YEARS)) + lockinPeriodFrequencyTypeId = 3L; + lockinPeriodFrequencyTypeEnum = new EnumOptionData(lockinPeriodFrequencyTypeId, null, null); + } + BigDecimal depositAmount=null; + if (ImportHandlerUtils.readAsDouble(FixedDepositConstants.DEPOSIT_AMOUNT_COL, row)!=null) { + depositAmount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(FixedDepositConstants.DEPOSIT_AMOUNT_COL, row)); + } + Integer depositPeriod = ImportHandlerUtils.readAsInt(FixedDepositConstants.DEPOSIT_PERIOD_COL, row); + + String depositPeriodFrequency = ImportHandlerUtils.readAsString(FixedDepositConstants.DEPOSIT_PERIOD_FREQUENCY_COL, row); + Long depositPeriodFrequencyId = null; + if (depositPeriodFrequency!=null) { + if (depositPeriodFrequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_DAYS)) + depositPeriodFrequencyId = 0L; + else if (depositPeriodFrequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_WEEKS)) + depositPeriodFrequencyId = 1L; + else if (depositPeriodFrequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_MONTHS)) + depositPeriodFrequencyId = 2L; + else if (depositPeriodFrequency.equalsIgnoreCase(TemplatePopulateImportConstants.FREQUENCY_YEARS)) + depositPeriodFrequencyId = 3L; + } + String externalId = ImportHandlerUtils.readAsString(FixedDepositConstants.EXTERNAL_ID_COL, row); + String clientName = ImportHandlerUtils.readAsString(FixedDepositConstants.CLIENT_NAME_COL, row); + + List charges = new ArrayList(); + + String charge1 = ImportHandlerUtils.readAsString(FixedDepositConstants.CHARGE_ID_1, row); + String charge2 = ImportHandlerUtils.readAsString(FixedDepositConstants.CHARGE_ID_2, row); + + if (charge1!=null) { + if (ImportHandlerUtils.readAsDouble(FixedDepositConstants.CHARGE_AMOUNT_1, row)!=null) + charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(FixedDepositConstants.CHARGE_ID_1, row), + BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(FixedDepositConstants.CHARGE_AMOUNT_1, row)), + ImportHandlerUtils.readAsDate(FixedDepositConstants.CHARGE_DUE_DATE_1, row))); + }else { + charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(FixedDepositConstants.CHARGE_ID_1, row), + null, + ImportHandlerUtils.readAsDate(FixedDepositConstants.CHARGE_DUE_DATE_1, row))); + } + + if (charge2!=null) { + if (ImportHandlerUtils.readAsDouble(FixedDepositConstants.CHARGE_AMOUNT_2, row)!=null) { + charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(FixedDepositConstants.CHARGE_ID_2, row), + BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(FixedDepositConstants.CHARGE_AMOUNT_2, row)), + ImportHandlerUtils.readAsDate(FixedDepositConstants.CHARGE_DUE_DATE_2, row))); + }else { + charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(FixedDepositConstants.CHARGE_ID_2, row), + null, + ImportHandlerUtils.readAsDate(FixedDepositConstants.CHARGE_DUE_DATE_2, row))); + } + } + String status = ImportHandlerUtils.readAsString(FixedDepositConstants.STATUS_COL, row); + statuses.add(status); + Long clientId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientName); + return FixedDepositAccountData.importInstance (clientId, productId, fieldOfficerId, submittedOnDate, + interestCompoundingPeriodTypeEnum, interestPostingPeriodTypeEnum, interestCalculationTypeEnum, + interestCalculationDaysInYearTypeEnum, lockinPeriodFrequency, lockinPeriodFrequencyTypeEnum, + depositAmount, depositPeriod, depositPeriodFrequencyId, externalId, charges,row.getRowNum(),locale,dateFormat); + } + + public Count importEntity(String dateFormat) { + Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_SHEET_NAME); + int successCount=0; + int errorCount=0; + String errorMessage=""; + int progressLevel = 0; + Long savingsId=null; + for (int i = 0; i < savings.size(); i++) { + Row row = savingsSheet.getRow(savings.get(i).getRowIndex()); + Cell statusCell = row.createCell(FixedDepositConstants.STATUS_COL); + Cell errorReportCell = row.createCell(FixedDepositConstants.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(FixedDepositConstants.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); + + if (progressLevel <= 3) progressLevel = importSavingsClosing(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); + writeFixedDepositErrorMessage(savingsId,errorMessage,progressLevel,statusCell,errorReportCell,row); + } + + } + setReportHeaders(savingsSheet); + return Count.instance(successCount,errorCount); + } + private void writeFixedDepositErrorMessage(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(FixedDepositConstants.SAVINGS_ID_COL).setCellValue(savingsId); + errorReportCell.setCellValue(errorMessage); + } + + private int importSavingsClosing(Long savingsId, int i,String dateFormat) { + if(closedOnDate.get(i)!=null) { + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + String payload = gsonBuilder.create().toJson(closedOnDate.get(i)); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .closeFixedDepositAccount(savingsId)// + .withJson(payload) // + .build(); // + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + } + return 4; + } + + 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"); + JsonArray chargesJsonAr=savingsJsonob.getAsJsonArray("charges"); + for (int j=0;j savingsTransactions; + private String savingsAccountId = ""; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + @Autowired + public FixedDepositTransactionImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook=workbook; + this.savingsTransactions=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(final String locale, final String dateFormat) { + Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_TRANSACTION_SHEET_NAME); + Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsTransactionSheet, TransactionConstants.AMOUNT_COL); + for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) { + Row row; + row = savingsTransactionSheet.getRow(rowIndex); + if(ImportHandlerUtils.isNotImported(row, TransactionConstants.STATUS_COL)) + savingsTransactions.add(readSavingsTransaction(row,locale,dateFormat)); + } + } + + private SavingsAccountTransactionData readSavingsTransaction(Row row,String locale,String dateFormat) { + String savingsAccountIdCheck=null; + if (ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row)!=null) + savingsAccountIdCheck = ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row).toString(); + if(savingsAccountIdCheck!=null) + savingsAccountId = savingsAccountIdCheck; + String transactionType = ImportHandlerUtils.readAsString(TransactionConstants.TRANSACTION_TYPE_COL, row); + SavingsAccountTransactionEnumData savingsAccountTransactionEnumData=new SavingsAccountTransactionEnumData(null,null,transactionType); + + BigDecimal amount=null; + if (ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row)!=null) + amount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row)); + + LocalDate transactionDate = ImportHandlerUtils.readAsDate(TransactionConstants.TRANSACTION_DATE_COL, row); + String paymentType = ImportHandlerUtils.readAsString(TransactionConstants.PAYMENT_TYPE_COL, row); + Long paymentTypeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME), paymentType); + String accountNumber = ImportHandlerUtils.readAsString(TransactionConstants.ACCOUNT_NO_COL, row); + String checkNumber = ImportHandlerUtils.readAsString(TransactionConstants.CHECK_NO_COL, row); + String routingCode = ImportHandlerUtils.readAsString(TransactionConstants.ROUTING_CODE_COL, row); + String receiptNumber = ImportHandlerUtils.readAsString(TransactionConstants.RECEIPT_NO_COL, row); + String bankNumber = ImportHandlerUtils.readAsString(TransactionConstants.BANK_NO_COL, row); + return SavingsAccountTransactionData.importInstance(amount, transactionDate, paymentTypeId, accountNumber, + checkNumber, routingCode, receiptNumber, bankNumber, Long.parseLong(savingsAccountId), savingsAccountTransactionEnumData, row.getRowNum(),locale,dateFormat); + + } + + public Count importEntity(String dateFormat) { + Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_TRANSACTION_SHEET_NAME); + int successCount=0; + int errorCount=0; + String errorMessage=""; + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + gsonBuilder.registerTypeAdapter(SavingsAccountTransactionEnumData.class + ,new SavingsAccountTransactionEnumValueSerialiser()); + + for (SavingsAccountTransactionData transaction : savingsTransactions) { + try { + JsonObject savingsTransactionJsonob=gsonBuilder.create().toJsonTree(transaction).getAsJsonObject(); + savingsTransactionJsonob.remove("transactionType"); + savingsTransactionJsonob.remove("reversed"); + savingsTransactionJsonob.remove("interestedPostedAsOn"); + String payload= savingsTransactionJsonob.toString(); + CommandWrapper commandRequest=null; + if (transaction.getTransactionType().getValue().equals("Withdrawal")) { + commandRequest = new CommandWrapperBuilder() // + .fixedDepositAccountWithdrawal(transaction.getSavingsAccountId()) // + .withJson(payload) // + .build(); // + + }else if (transaction.getTransactionType().getValue().equals("Deposit")){ + commandRequest = new CommandWrapperBuilder() // + .fixedDepositAccountDeposit(transaction.getSavingsAccountId()) // + .withJson(payload) // + .build(); + } + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + successCount++; + Cell statusCell = savingsTransactionSheet.getRow(transaction.getRowIndex()).createCell(TransactionConstants.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(savingsTransactionSheet,transaction.getRowIndex(),errorMessage,TransactionConstants.STATUS_COL); + } + } + savingsTransactionSheet.setColumnWidth(TransactionConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + ImportHandlerUtils.writeString(TransactionConstants.STATUS_COL, savingsTransactionSheet.getRow(TransactionConstants.STATUS_COL), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER); + return Count.instance(successCount,errorCount); + } + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/group/GroupImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/group/GroupImportHandler.java new file mode 100644 index 000000000..9fc91b494 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/group/GroupImportHandler.java @@ -0,0 +1,257 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE multipartFile + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this multipartFile + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this multipartFile 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.group; + +import com.google.common.reflect.TypeToken; +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.GroupConstants; +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.ClientIdSerializer; +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.calendar.data.CalendarData; +import org.apache.fineract.portfolio.client.data.ClientData; +import org.apache.fineract.portfolio.group.data.GroupGeneralData; +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.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +@Service +public class GroupImportHandler implements ImportHandler { + private List groups; + private List meetings; + private Workbook workbook; + private Liststatuses; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + + @Autowired + public GroupImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook=workbook; + groups=new ArrayList<>(); + meetings=new ArrayList<>(); + statuses=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(String locale, String dateFormat) { + Sheet groupsSheet = workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME); + Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(groupsSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX); + for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) { + Row row; + row = groupsSheet.getRow(rowIndex); + if(ImportHandlerUtils.isNotImported(row, GroupConstants.STATUS_COL)) { + groups.add(readGroup(row,locale,dateFormat)); + meetings.add(readMeeting(row,locale,dateFormat)); + } + } + } + + private CalendarData readMeeting(Row row,String locale,String dateFormat) { + LocalDate meetingStartDate = ImportHandlerUtils.readAsDate(GroupConstants.MEETING_START_DATE_COL, row); + Boolean isRepeating = ImportHandlerUtils.readAsBoolean(GroupConstants.IS_REPEATING_COL, row); + String frequency = ImportHandlerUtils.readAsString(GroupConstants.FREQUENCY_COL, row); + EnumOptionData frequencyEnum=new EnumOptionData(null,null,ImportHandlerUtils.getFrequencyId(frequency)); + Integer interval = ImportHandlerUtils.readAsInt(GroupConstants.INTERVAL_COL, row); + String repeatsOnDay = ImportHandlerUtils.readAsString(GroupConstants.REPEATS_ON_DAY_COL, row); + EnumOptionData repeatsOnDayEnum=new EnumOptionData(null,null,ImportHandlerUtils.getRepeatsOnDayId(repeatsOnDay)); + if(meetingStartDate==null) + return null; + else { + if(repeatsOnDay==null) + return CalendarData.importInstanceNoRepeatsOnDay(meetingStartDate, isRepeating, frequencyEnum, interval, row.getRowNum(),locale,dateFormat); + else + return CalendarData.importInstanceWithRepeatsOnDay(meetingStartDate, isRepeating, frequencyEnum, interval, repeatsOnDayEnum, row.getRowNum(),locale,dateFormat); + } + } + private GroupGeneralData readGroup(Row row,String locale,String dateFormat) { + String status = ImportHandlerUtils.readAsString(GroupConstants.STATUS_COL, row); + String officeName = ImportHandlerUtils.readAsString(GroupConstants.OFFICE_NAME_COL, row); + Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName); + String staffName = ImportHandlerUtils.readAsString(GroupConstants.STAFF_NAME_COL, row); + Long staffId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), staffName); + String centerName = ImportHandlerUtils.readAsString(GroupConstants.CENTER_NAME_COL, row); + Long centerId=null; + if(centerName!=null) + centerId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CENTER_SHEET_NAME), centerName); + String externalId = ImportHandlerUtils.readAsString(GroupConstants.EXTERNAL_ID_COL, row); + Boolean active = ImportHandlerUtils.readAsBoolean(GroupConstants.ACTIVE_COL, row); + LocalDate submittedOnDate=ImportHandlerUtils.readAsDate(GroupConstants.SUBMITTED_ON_DATE_COL,row); + LocalDate activationDate=null; + if(active) { + activationDate = ImportHandlerUtils.readAsDate(GroupConstants.ACTIVATION_DATE_COL, row); + }else { + activationDate=submittedOnDate; + } + String groupName = ImportHandlerUtils.readAsString(GroupConstants.NAME_COL, row); + if (groupName == null || groupName.equals("")) { + throw new IllegalArgumentException("Name is blank"); + } + List clientMembers = new ArrayList<>(); + for (int cellNo = GroupConstants.CLIENT_NAMES_STARTING_COL; cellNo clientMembers,Long clientId){ + for (ClientData client: clientMembers) { + if (client.getId()==clientId){ + return true; + } + } + return false; + } + + public Count importEntity(String dateFormat) { + Sheet groupSheet = workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME); + int successCount=0; + int errorCount=0; + int progressLevel = 0; + String groupId = ""; + String errorMessage=""; + for (int i = 0; i < groups.size(); i++) { + Row row = groupSheet.getRow(groups.get(i).getRowIndex()); + Cell errorReportCell = row.createCell(GroupConstants.FAILURE_COL); + Cell statusCell = row.createCell(GroupConstants.STATUS_COL); + CommandProcessingResult result=null; + try { + String status = statuses.get(i); + progressLevel = getProgressLevel(status); + + if(progressLevel == 0) + { + result = importGroup(i,dateFormat); + groupId = result.getGroupId().toString(); + progressLevel = 1; + } else + groupId = ImportHandlerUtils.readAsInt(GroupConstants.GROUP_ID_COL, groupSheet.getRow(groups.get(i).getRowIndex())).toString(); + + if(meetings.get(i) != null && groups.get(i).getCenterId() == null) + progressLevel = importGroupMeeting(result, i,dateFormat); + + statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED); + statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN)); + }catch (RuntimeException ex){ + errorCount++; + ex.printStackTrace(); + errorMessage=ImportHandlerUtils.getErrorMessage(ex); + writeGroupErrorMessage(groupId,errorMessage,progressLevel,statusCell,errorReportCell,row); + } + } + setReportHeaders(groupSheet); + return Count.instance(successCount,errorCount); + } + private void writeGroupErrorMessage(String groupId,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_MEETING_FAILED ; + statusCell.setCellValue(status); + statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.RED)); + + if(progressLevel>0) + row.createCell(GroupConstants.GROUP_ID_COL).setCellValue(Integer.parseInt(groupId)); + errorReportCell.setCellValue(errorMessage); + } + private void setReportHeaders(Sheet groupSheet) { + ImportHandlerUtils.writeString(GroupConstants.STATUS_COL, groupSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), + TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER); + ImportHandlerUtils.writeString(GroupConstants.GROUP_ID_COL, groupSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), + TemplatePopulateImportConstants.GROUP_ID_COL_REPORT_HEADER); + ImportHandlerUtils.writeString(GroupConstants.FAILURE_COL, groupSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), + TemplatePopulateImportConstants.FAILURE_COL_REPORT_HEADER); + } + + private Integer importGroupMeeting(CommandProcessingResult result, int rowIndex, String dateFormat) { + CalendarData calendarData=meetings.get(rowIndex); + calendarData.setTitle("group_" + result.getGroupId().toString() + "_CollectionMeeting"); + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + gsonBuilder.registerTypeAdapter(EnumOptionData.class,new EnumOptionDataValueSerializer()); + + String payload = gsonBuilder.create().toJson(calendarData); + CommandWrapper commandWrapper=new CommandWrapper(result.getOfficeId(),result.getGroupId(), + result.getClientId(),result.getLoanId(),result.getSavingsId(),null, + null,null,null,null,payload,result.getTransactionId(), + result.getProductId(),null,null,null); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createCalendar(commandWrapper,TemplatePopulateImportConstants.CENTER_ENTITY_TYPE,result.getGroupId()) // + .withJson(payload) // + .build(); // + final CommandProcessingResult meetingresult = commandsSourceWritePlatformService.logCommandSource(commandRequest); + return 2; + } + + private CommandProcessingResult importGroup(int rowIndex, String dateFormat) { + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + Type clientCollectionType = new TypeToken>() {}.getType(); + gsonBuilder.registerTypeAdapter(clientCollectionType,new ClientIdSerializer()); + String payload= gsonBuilder.create().toJson(groups.get(rowIndex));; + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createGroup() // + .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_MEETING_FAILED)) + return 1; + return 0; + } + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/guarantor/GuarantorImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/guarantor/GuarantorImportHandler.java new file mode 100644 index 000000000..e97443f0e --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/guarantor/GuarantorImportHandler.java @@ -0,0 +1,151 @@ +/** + * 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.guarantor; + +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.GuarantorConstants; +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.guarantor.data.GuarantorData; +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 GuarantorImportHandler implements ImportHandler { + private Workbook workbook; + private List guarantors; + private Long loanAccountId ; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + +@Autowired + public GuarantorImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook=workbook; + this.guarantors=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(final String locale, final String dateFormat) { + Sheet addGuarantorSheet = workbook.getSheet(TemplatePopulateImportConstants.GUARANTOR_SHEET_NAME); + Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(addGuarantorSheet, GuarantorConstants.LOAN_ACCOUNT_NO_COL); + for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) { + Row row; + row = addGuarantorSheet.getRow(rowIndex); + if (ImportHandlerUtils.isNotImported(row, GuarantorConstants.STATUS_COL)) + guarantors.add(ReadGuarantor(row,locale,dateFormat)); + + } + } + + private GuarantorData ReadGuarantor(Row row,String locale,String dateFormat) { + String loanaccountInfo=ImportHandlerUtils.readAsString(GuarantorConstants.LOAN_ACCOUNT_NO_COL, row); + if (loanaccountInfo!=null){ + String loanAccountAr[]=loanaccountInfo.split("-"); + loanAccountId=Long.parseLong(loanAccountAr[0]); + } + String guarantorType = ImportHandlerUtils.readAsString(GuarantorConstants.GUARANTO_TYPE_COL, row); + + Integer guarantorTypeId = null; + if (guarantorType!=null) { + if (guarantorType.equalsIgnoreCase(TemplatePopulateImportConstants.GUARANTOR_INTERNAL)) + guarantorTypeId = 1; + else if (guarantorType.equalsIgnoreCase(TemplatePopulateImportConstants.GUARANTOR_EXTERNAL)) + guarantorTypeId = 3; + } + String clientName = ImportHandlerUtils.readAsString(GuarantorConstants.ENTITY_ID_COL, row); + Long entityId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientName); + String clientRelationshipTypeInfo=ImportHandlerUtils.readAsString(GuarantorConstants.CLIENT_RELATIONSHIP_TYPE_COL, row); + Integer clientRelationshipTypeId=null; + if (clientRelationshipTypeInfo!=null){ + String clientRelationshipTypeAr[]=clientRelationshipTypeInfo.split("-"); + clientRelationshipTypeId=Integer.parseInt(clientRelationshipTypeAr[1]); + } + String firstname = ImportHandlerUtils.readAsString(GuarantorConstants.FIRST_NAME_COL, row); + String lastname = ImportHandlerUtils.readAsString(GuarantorConstants.LAST_NAME_COL, row); + String addressLine1 = ImportHandlerUtils.readAsString(GuarantorConstants.ADDRESS_LINE_1_COL, row); + String addressLine2 = ImportHandlerUtils.readAsString(GuarantorConstants.ADDRESS_LINE_2_COL, row); + String city = ImportHandlerUtils.readAsString(GuarantorConstants.CITY_COL, row); + LocalDate dob = ImportHandlerUtils.readAsDate(GuarantorConstants.DOB_COL, row); + String zip = ImportHandlerUtils.readAsString(GuarantorConstants.ZIP_COL, row); + Integer savingsId = ImportHandlerUtils.readAsInt(GuarantorConstants.SAVINGS_ID_COL, row); + BigDecimal amount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(GuarantorConstants.AMOUNT, row)); + + return GuarantorData.importInstance(guarantorTypeId,clientRelationshipTypeId,entityId,firstname, + lastname,addressLine1, addressLine2,city,dob,zip,savingsId,amount, row.getRowNum(), loanAccountId,locale,dateFormat); + } + + public Count importEntity(String dateFormat) { + Sheet addGuarantorSheet = workbook.getSheet(TemplatePopulateImportConstants.GUARANTOR_SHEET_NAME); + int successCount=0; + int errorCount=0; + String errorMessage=""; + GsonBuilder gsonBuilder=new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + for (GuarantorData guarantor : guarantors) { + try { + JsonObject guarantorJsonob=gsonBuilder.create().toJsonTree(guarantor).getAsJsonObject(); + guarantorJsonob.remove("status"); + String payload = guarantorJsonob.toString(); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createGuarantor(guarantor.getAccountId()) // + .withJson(payload) // + .build(); // + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + successCount++; + Cell statusCell = addGuarantorSheet.getRow(guarantor.getRowIndex()).createCell(GuarantorConstants.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(addGuarantorSheet,guarantor.getRowIndex(),errorMessage,GuarantorConstants.STATUS_COL); + } + + } + addGuarantorSheet.setColumnWidth(GuarantorConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + ImportHandlerUtils.writeString(GuarantorConstants.STATUS_COL, addGuarantorSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX), + TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER); + return Count.instance(successCount,errorCount); + } + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/ClientIdSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/ClientIdSerializer.java new file mode 100644 index 000000000..0dbe28ca9 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/ClientIdSerializer.java @@ -0,0 +1,38 @@ +/** + * 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.helper; + +import com.google.gson.*; +import org.apache.fineract.portfolio.client.data.ClientData; + +import java.lang.reflect.Type; +import java.util.Collection; + +public class ClientIdSerializer implements JsonSerializer> { + + @Override + public JsonElement serialize(Collection src, Type typeOfSrc, JsonSerializationContext context) { + JsonArray clientIdJsonArray=new JsonArray(); + for (ClientData client:src) { + JsonElement clientIdElment=new JsonPrimitive(client.id().toString()); + clientIdJsonArray.add(clientIdElment); + } + return clientIdJsonArray; + } +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CodeValueDataIdSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CodeValueDataIdSerializer.java new file mode 100644 index 000000000..d5f4ef0f5 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CodeValueDataIdSerializer.java @@ -0,0 +1,34 @@ +/** + * 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.helper; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.apache.fineract.infrastructure.codes.data.CodeValueData; + +import java.lang.reflect.Type; + +public class CodeValueDataIdSerializer implements JsonSerializer { + @Override + public JsonElement serialize(CodeValueData src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.getId()); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CurrencyDateCodeSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CurrencyDateCodeSerializer.java new file mode 100644 index 000000000..c784bae95 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/CurrencyDateCodeSerializer.java @@ -0,0 +1,34 @@ +/** + * 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.helper; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.apache.fineract.organisation.monetary.data.CurrencyData; + +import java.lang.reflect.Type; + +public class CurrencyDateCodeSerializer implements JsonSerializer{ + @Override + public JsonElement serialize(CurrencyData src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.code()); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/DateSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/DateSerializer.java new file mode 100644 index 000000000..c7b7bc593 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/DateSerializer.java @@ -0,0 +1,41 @@ +/** + * 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.helper; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.joda.time.LocalDate; + +import java.lang.reflect.Type; + +public class DateSerializer implements JsonSerializer { + + private final String dateFormat; + + public DateSerializer(String dateFormat) { + this.dateFormat = dateFormat; + } + + @Override + public JsonElement serialize(LocalDate src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toString(dateFormat)); + } +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataIdSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataIdSerializer.java new file mode 100644 index 000000000..e95e2cb55 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataIdSerializer.java @@ -0,0 +1,34 @@ +/** + * 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.helper; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.apache.fineract.infrastructure.core.data.EnumOptionData; + +import java.lang.reflect.Type; + +public class EnumOptionDataIdSerializer implements JsonSerializer { + @Override + public JsonElement serialize(EnumOptionData src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.getId()); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataValueSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataValueSerializer.java new file mode 100644 index 000000000..41b6ce31c --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/EnumOptionDataValueSerializer.java @@ -0,0 +1,34 @@ +/** + * 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.helper; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.apache.fineract.infrastructure.core.data.EnumOptionData; + +import java.lang.reflect.Type; + +public class EnumOptionDataValueSerializer implements JsonSerializer { + @Override + public JsonElement serialize(EnumOptionData src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.getValue()); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/GroupIdSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/GroupIdSerializer.java new file mode 100644 index 000000000..071a112c4 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/GroupIdSerializer.java @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE multipartFile + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this multipartFile + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this multipartFile 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.helper; + +import com.google.gson.*; +import org.apache.fineract.portfolio.group.data.GroupGeneralData; + +import java.lang.reflect.Type; +import java.util.Collection; + +public class GroupIdSerializer implements JsonSerializer> { + @Override + public JsonElement serialize(Collection src, Type typeOfSrc, JsonSerializationContext context) { + JsonArray groupIdJsonArray=new JsonArray(); + for (GroupGeneralData group:src) { + JsonElement groupIdElement=new JsonPrimitive(group.getId().toString()); + groupIdJsonArray.add(groupIdElement); + } + return groupIdJsonArray; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/SavingsAccountTransactionEnumValueSerialiser.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/SavingsAccountTransactionEnumValueSerialiser.java new file mode 100644 index 000000000..4942d2daf --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/helper/SavingsAccountTransactionEnumValueSerialiser.java @@ -0,0 +1,35 @@ +/** + * 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.helper; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionEnumData; + +import java.lang.reflect.Type; + +public class SavingsAccountTransactionEnumValueSerialiser implements JsonSerializer { + + @Override + public JsonElement serialize(SavingsAccountTransactionEnumData src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.getValue()); + } +} 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 000000000..ad7b8a91d --- /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 gltransaction; + private LocalDate transactionDate; + + List credits = new ArrayList<>(); + List 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); + } + + +} 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 000000000..1cfe4018a --- /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 loans; + private List approvalDates; + private List loanRepayments; + private List disbursalDates; + private List 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 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; + } + + +} 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 000000000..8134bc666 --- /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 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); + } + + +} 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 000000000..7a3aa009e --- /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 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 getOffices() { + return offices; + } +} + + 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 000000000..0c2cb827b --- /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 savings; + private List approvalDates; + private List activationDates; + private List 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 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; + } + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/recurringdeposit/RecurringDepositTransactionImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/recurringdeposit/RecurringDepositTransactionImportHandler.java new file mode 100644 index 000000000..3715dbd25 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/recurringdeposit/RecurringDepositTransactionImportHandler.java @@ -0,0 +1,157 @@ +/** + * 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.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TransactionConstants; +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.SavingsAccountTransactionEnumValueSerialiser; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.exception.*; +import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionData; +import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionEnumData; +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 RecurringDepositTransactionImportHandler implements ImportHandler { + + private Workbook workbook; + private List savingsTransactions; + private String savingsAccountId = ""; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + @Autowired + public RecurringDepositTransactionImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook=workbook; + this.savingsTransactions=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(String locale, String dateFormat) { + Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_TRANSACTION_SHEET_NAME); + Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsTransactionSheet, TransactionConstants.AMOUNT_COL); + for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) { + Row row; + row = savingsTransactionSheet.getRow(rowIndex); + if(ImportHandlerUtils.isNotImported(row, TransactionConstants.STATUS_COL)) + savingsTransactions.add(readSavingsTransaction(row,locale,dateFormat)); + } + } + + private SavingsAccountTransactionData readSavingsTransaction(Row row,String locale, String dateFormat) { + String savingsAccountIdCheck=null; + if (ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row)!=null) + savingsAccountIdCheck = ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row).toString(); + if(savingsAccountIdCheck!=null) + savingsAccountId = savingsAccountIdCheck; + String transactionType = ImportHandlerUtils.readAsString(TransactionConstants.TRANSACTION_TYPE_COL, row); + SavingsAccountTransactionEnumData savingsAccountTransactionEnumData=new SavingsAccountTransactionEnumData(null,null,transactionType); + + BigDecimal amount=null; + if (ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row)!=null) + amount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row)); + + LocalDate transactionDate = ImportHandlerUtils.readAsDate(TransactionConstants.TRANSACTION_DATE_COL, row); + String paymentType = ImportHandlerUtils.readAsString(TransactionConstants.PAYMENT_TYPE_COL, row); + Long paymentTypeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME), paymentType); + String accountNumber = ImportHandlerUtils.readAsString(TransactionConstants.ACCOUNT_NO_COL, row); + String checkNumber = ImportHandlerUtils.readAsString(TransactionConstants.CHECK_NO_COL, row); + String routingCode = ImportHandlerUtils.readAsString(TransactionConstants.ROUTING_CODE_COL, row); + String receiptNumber = ImportHandlerUtils.readAsString(TransactionConstants.RECEIPT_NO_COL, row); + String bankNumber = ImportHandlerUtils.readAsString(TransactionConstants.BANK_NO_COL, row); + return SavingsAccountTransactionData.importInstance(amount, transactionDate, paymentTypeId, accountNumber, + checkNumber, routingCode, receiptNumber, bankNumber, Long.parseLong(savingsAccountId), savingsAccountTransactionEnumData, row.getRowNum(),locale,dateFormat); + + } + + public Count importEntity(String dateFormat) { + Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_TRANSACTION_SHEET_NAME); + int successCount=0; + int errorCount=0; + String errorMessage=""; + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + gsonBuilder.registerTypeAdapter(SavingsAccountTransactionEnumData.class + ,new SavingsAccountTransactionEnumValueSerialiser()); + + for (SavingsAccountTransactionData transaction : savingsTransactions) { + try { + JsonObject savingsTransactionJsonob=gsonBuilder.create().toJsonTree(transaction).getAsJsonObject(); + savingsTransactionJsonob.remove("transactionType"); + savingsTransactionJsonob.remove("reversed"); + savingsTransactionJsonob.remove("interestedPostedAsOn"); + String payload= savingsTransactionJsonob.toString(); + CommandWrapper commandRequest=null; + if (transaction.getTransactionType().getValue().equals("Withdrawal")) { + commandRequest = new CommandWrapperBuilder() // + .recurringAccountWithdrawal(transaction.getSavingsAccountId()) // + .withJson(payload) // + .build(); // + + }else if (transaction.getTransactionType().getValue().equals("Deposit")){ + commandRequest = new CommandWrapperBuilder() // + .recurringAccountDeposit(transaction.getSavingsAccountId()) // + .withJson(payload) // + .build(); + } + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + successCount++; + Cell statusCell = savingsTransactionSheet.getRow(transaction.getRowIndex()).createCell(TransactionConstants.STATUS_COL); + statusCell.setCellValue(TemplatePopulateImportConstants.STATUS_CELL_IMPORTED); + statusCell.setCellStyle(ImportHandlerUtils.getCellStyle(workbook, IndexedColors.LIGHT_GREEN)); + } catch (AbstractPlatformDomainRuleException e) { + errorCount++; + e.printStackTrace(); + errorMessage = e.getDefaultUserMessage(); + ImportHandlerUtils.writeErrorMessage(savingsTransactionSheet,transaction.getRowIndex(),errorMessage,TransactionConstants.STATUS_COL); + }catch (RuntimeException ex){ + errorCount++; + ex.printStackTrace(); + errorMessage=ImportHandlerUtils.getErrorMessage(ex); + ImportHandlerUtils.writeErrorMessage(savingsTransactionSheet,transaction.getRowIndex(),errorMessage,TransactionConstants.STATUS_COL); + } + } + savingsTransactionSheet.setColumnWidth(TransactionConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + ImportHandlerUtils.writeString(TransactionConstants.STATUS_COL, savingsTransactionSheet.getRow(TransactionConstants.STATUS_COL), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER); + return Count.instance(successCount,errorCount); + } + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsImportHandler.java new file mode 100644 index 000000000..13c0f54dc --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsImportHandler.java @@ -0,0 +1,364 @@ +/** + * 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.savings; + +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.SavingsConstants; +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.SavingsAccountChargeData; +import org.apache.fineract.portfolio.savings.data.SavingsAccountData; +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; +import java.util.Locale; +@Service +public class SavingsImportHandler implements ImportHandler { + + private Workbook workbook; + private List savings; + private List approvalDates; + private List activationDates; + private Liststatuses; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + + @Autowired + public SavingsImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook=workbook; + this.savings=new ArrayList<>(); + this.approvalDates=new ArrayList<>(); + this.activationDates=new ArrayList<>(); + this.statuses=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + public void readExcelFile(String locale, String dateFormat) { + Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME); + Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX); + for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) { + Row row; + row = savingsSheet.getRow(rowIndex); + if (ImportHandlerUtils.isNotImported(row, SavingsConstants.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( SavingsConstants.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( SavingsConstants.APPROVED_DATE_COL, row); + if (approvalDate!=null) + return SavingsApproval.importInstance(approvalDate, row.getRowNum(),locale,dateFormat); + else + return null; + } + + private SavingsAccountData readSavings(Row row,String locale, String dateFormat) { + String productName = ImportHandlerUtils.readAsString( SavingsConstants.PRODUCT_COL, row); + Long productId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME), productName); + String fieldOfficerName = ImportHandlerUtils.readAsString(SavingsConstants.FIELD_OFFICER_NAME_COL, row); + Long fieldOfficerId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), fieldOfficerName); + LocalDate submittedOnDate = ImportHandlerUtils.readAsDate(SavingsConstants.SUBMITTED_ON_DATE_COL, row); + + BigDecimal nominalAnnualInterestRate=null; + if (ImportHandlerUtils.readAsDouble(SavingsConstants.NOMINAL_ANNUAL_INTEREST_RATE_COL, row)!=null) { + nominalAnnualInterestRate = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(SavingsConstants.NOMINAL_ANNUAL_INTEREST_RATE_COL, row)); + } + String interestCompoundingPeriodType = ImportHandlerUtils.readAsString(SavingsConstants.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(SavingsConstants.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(SavingsConstants.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(SavingsConstants.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); + } + BigDecimal minRequiredOpeningBalance=null; + if (ImportHandlerUtils.readAsDouble(SavingsConstants.MIN_OPENING_BALANCE_COL, row)!=null) { + minRequiredOpeningBalance = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(SavingsConstants.MIN_OPENING_BALANCE_COL, row)); + } + Integer lockinPeriodFrequency = ImportHandlerUtils.readAsInt(SavingsConstants.LOCKIN_PERIOD_COL, row); + String lockinPeriodFrequencyType = ImportHandlerUtils.readAsString(SavingsConstants.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); + } + Boolean applyWithdrawalFeeForTransfers = ImportHandlerUtils.readAsBoolean(SavingsConstants.APPLY_WITHDRAWAL_FEE_FOR_TRANSFERS, row); + + String savingsType=null; + if (ImportHandlerUtils.readAsString(SavingsConstants.SAVINGS_TYPE_COL, row)!=null) + savingsType = ImportHandlerUtils.readAsString(SavingsConstants.SAVINGS_TYPE_COL, row).toLowerCase(Locale.ENGLISH); + + String clientOrGroupName = ImportHandlerUtils.readAsString(SavingsConstants.CLIENT_NAME_COL, row); + + String externalId = ImportHandlerUtils.readAsString(SavingsConstants.EXTERNAL_ID_COL, row); + List charges = new ArrayList<>(); + + + Boolean allowOverdraft = ImportHandlerUtils.readAsBoolean(SavingsConstants.ALLOW_OVER_DRAFT_COL, row); + BigDecimal overdraftLimit = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(SavingsConstants.OVER_DRAFT_LIMIT_COL, row)); + + String charge1 = ImportHandlerUtils.readAsString(SavingsConstants.CHARGE_ID_1, row); + String charge2 = ImportHandlerUtils.readAsString(SavingsConstants.CHARGE_ID_2, row); + + if (charge1!=null) { + if (ImportHandlerUtils.readAsDouble(SavingsConstants.CHARGE_AMOUNT_1, row)!=null) { + charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(SavingsConstants.CHARGE_ID_1, row), + BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(SavingsConstants.CHARGE_AMOUNT_1, row)), + ImportHandlerUtils.readAsDate(SavingsConstants.CHARGE_DUE_DATE_1, row))); + }else { + charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(SavingsConstants.CHARGE_ID_1, row), + null, + ImportHandlerUtils.readAsDate(SavingsConstants.CHARGE_DUE_DATE_1, row))); + } + } + + if (charge2!=null) { + if (ImportHandlerUtils.readAsDouble(SavingsConstants.CHARGE_AMOUNT_2, row)!=null) { + charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(SavingsConstants.CHARGE_ID_2, row), + BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(SavingsConstants.CHARGE_AMOUNT_2, row)), + ImportHandlerUtils.readAsDate(SavingsConstants.CHARGE_DUE_DATE_2, row))); + }else { + charges.add(new SavingsAccountChargeData(ImportHandlerUtils.readAsLong(SavingsConstants.CHARGE_ID_2, row), + null, + ImportHandlerUtils.readAsDate(SavingsConstants.CHARGE_DUE_DATE_2, row))); + } + } + String status = ImportHandlerUtils.readAsString(SavingsConstants.STATUS_COL, row); + statuses.add(status); + if (savingsType!=null) { + if (savingsType.equals("individual")) { + Long clientId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientOrGroupName); + return SavingsAccountData.importInstanceIndividual(clientId, productId, fieldOfficerId, submittedOnDate, nominalAnnualInterestRate, + interestCompoundingPeriodTypeEnum, interestPostingPeriodTypeEnum, interestCalculationTypeEnum, + interestCalculationDaysInYearTypeEnum, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyTypeEnum, + applyWithdrawalFeeForTransfers, row.getRowNum(), externalId, charges, allowOverdraft, overdraftLimit,locale,dateFormat); + } + Long groupId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME), clientOrGroupName); + return SavingsAccountData.importInstanceGroup(groupId, productId, fieldOfficerId, submittedOnDate, nominalAnnualInterestRate, + interestCompoundingPeriodTypeEnum, interestPostingPeriodTypeEnum, interestCalculationTypeEnum, + interestCalculationDaysInYearTypeEnum, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyTypeEnum, + applyWithdrawalFeeForTransfers, row.getRowNum(), externalId, charges, allowOverdraft, overdraftLimit,locale,dateFormat); + }else { + return null; + } + + } + + public Count importEntity(String dateFormat) { + Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME); + int successCount=0; + int errorCount=0; + int progressLevel = 0; + String errorMessage=""; + Long savingsId=null; + for (int i = 0; i < savings.size(); i++) { + Row row = savingsSheet.getRow(savings.get(i).getRowIndex()); + Cell statusCell = row.createCell(SavingsConstants.STATUS_COL); + Cell errorReportCell = row.createCell(SavingsConstants.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(SavingsConstants.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); + writeSavingsErrorMessage(savingsId,errorMessage,progressLevel,statusCell,errorReportCell,row); + } + } + setReportHeaders(savingsSheet); + return Count.instance(successCount,errorCount); + } + + private void writeSavingsErrorMessage(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(SavingsConstants.SAVINGS_ID_COL).setCellValue(savingsId); + + errorReportCell.setCellValue(errorMessage); + } + private void setReportHeaders(Sheet savingsSheet) { + savingsSheet.setColumnWidth(SavingsConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + Row rowHeader = savingsSheet.getRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + ImportHandlerUtils.writeString(SavingsConstants.STATUS_COL, rowHeader, TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER); + ImportHandlerUtils.writeString(SavingsConstants.SAVINGS_ID_COL, rowHeader, TemplatePopulateImportConstants.SAVINGS_ID_COL_REPORT_HEADER); + ImportHandlerUtils.writeString(SavingsConstants.FAILURE_REPORT_COL, rowHeader, TemplatePopulateImportConstants.FAILURE_COL_REPORT_HEADER); + } + + 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() // + .savingsAccountActivation(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() // + .approveSavingsAccountApplication(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("isDormancyTrackingActive"); + String payload= savingsJsonob.toString(); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createSavingsAccount() // + .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; + } + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsTransactionImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsTransactionImportHandler.java new file mode 100644 index 000000000..dfd562f9e --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/savings/SavingsTransactionImportHandler.java @@ -0,0 +1,152 @@ +/** + * 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.savings; + +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.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TransactionConstants; +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.SavingsAccountTransactionEnumValueSerialiser; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.exception.*; +import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionData; +import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionEnumData; +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 SavingsTransactionImportHandler implements ImportHandler { + private Workbook workbook; + private List savingsTransactions; + private String savingsAccountId = ""; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + + @Autowired + public SavingsTransactionImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook=workbook; + this.savingsTransactions=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + + public void readExcelFile(String locale, String dateFormat) { + Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_TRANSACTION_SHEET_NAME); + Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(savingsTransactionSheet, TransactionConstants.AMOUNT_COL); + for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) { + Row row; + row = savingsTransactionSheet.getRow(rowIndex); + if(ImportHandlerUtils.isNotImported(row, TransactionConstants.STATUS_COL)) + savingsTransactions.add(readSavingsTransaction(row,locale,dateFormat)); + } + } + + private SavingsAccountTransactionData readSavingsTransaction(Row row,String locale, String dateFormat) { + String savingsAccountIdCheck=null; + if (ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row)!=null) + savingsAccountIdCheck = ImportHandlerUtils.readAsLong(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, row).toString(); + if(savingsAccountIdCheck!=null) + savingsAccountId = savingsAccountIdCheck; + String transactionType = ImportHandlerUtils.readAsString(TransactionConstants.TRANSACTION_TYPE_COL, row); + SavingsAccountTransactionEnumData savingsAccountTransactionEnumData=new SavingsAccountTransactionEnumData(null,null,transactionType); + + BigDecimal amount=null; + if (ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row)!=null) + amount = BigDecimal.valueOf(ImportHandlerUtils.readAsDouble(TransactionConstants.AMOUNT_COL, row)); + + LocalDate transactionDate = ImportHandlerUtils.readAsDate(TransactionConstants.TRANSACTION_DATE_COL, row); + String paymentType = ImportHandlerUtils.readAsString(TransactionConstants.PAYMENT_TYPE_COL, row); + Long paymentTypeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME), paymentType); + String accountNumber = ImportHandlerUtils.readAsString(TransactionConstants.ACCOUNT_NO_COL, row); + String checkNumber = ImportHandlerUtils.readAsString(TransactionConstants.CHECK_NO_COL, row); + String routingCode = ImportHandlerUtils.readAsString(TransactionConstants.ROUTING_CODE_COL, row); + String receiptNumber = ImportHandlerUtils.readAsString(TransactionConstants.RECEIPT_NO_COL, row); + String bankNumber = ImportHandlerUtils.readAsString(TransactionConstants.BANK_NO_COL, row); + return SavingsAccountTransactionData.importInstance(amount, transactionDate, paymentTypeId, accountNumber, + checkNumber, routingCode, receiptNumber, bankNumber, Long.parseLong(savingsAccountId), savingsAccountTransactionEnumData, row.getRowNum(),locale,dateFormat); + + } + + public Count importEntity(String dateFormat) { + Sheet savingsTransactionSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_TRANSACTION_SHEET_NAME); + int successCount=0; + int errorCount=0; + String errorMessage=""; + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + gsonBuilder.registerTypeAdapter(SavingsAccountTransactionEnumData.class + ,new SavingsAccountTransactionEnumValueSerialiser()); + + for (SavingsAccountTransactionData transaction : savingsTransactions) { + try { + JsonObject savingsTransactionJsonob=gsonBuilder.create().toJsonTree(transaction).getAsJsonObject(); + savingsTransactionJsonob.remove("transactionType"); + savingsTransactionJsonob.remove("reversed"); + savingsTransactionJsonob.remove("interestedPostedAsOn"); + String payload= savingsTransactionJsonob.toString(); + CommandWrapper commandRequest=null; + if (transaction.getTransactionType().getValue().equals("Withdrawal")) { + commandRequest = new CommandWrapperBuilder() // + .savingsAccountWithdrawal(transaction.getSavingsAccountId()) // + .withJson(payload) // + .build(); // + + }else if (transaction.getTransactionType().getValue().equals("Deposit")){ + commandRequest = new CommandWrapperBuilder() // + .savingsAccountDeposit(transaction.getSavingsAccountId()) // + .withJson(payload) // + .build(); + } + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + successCount++; + Cell statusCell = savingsTransactionSheet.getRow(transaction.getRowIndex()).createCell(TransactionConstants.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(savingsTransactionSheet,transaction.getRowIndex(),errorMessage,TransactionConstants.STATUS_COL); + } + } + savingsTransactionSheet.setColumnWidth(TransactionConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + ImportHandlerUtils.writeString(TransactionConstants.STATUS_COL, savingsTransactionSheet.getRow(TransactionConstants.STATUS_COL), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER); + return Count.instance(successCount,errorCount); + } + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/sharedaccount/SharedAccountImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/sharedaccount/SharedAccountImportHandler.java new file mode 100644 index 000000000..63ce1c292 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/sharedaccount/SharedAccountImportHandler.java @@ -0,0 +1,174 @@ +/** + * 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.sharedaccount; + +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.SharedAccountsConstants; +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.shareaccounts.data.ShareAccountChargeData; +import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountData; +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 SharedAccountImportHandler implements ImportHandler { + private Workbook workbook; + private List shareAccountDataList; + private Liststatuses; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + + @Autowired + public SharedAccountImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook=workbook; + this.shareAccountDataList=new ArrayList<>(); + statuses=new ArrayList(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + public void readExcelFile(String locale, String dateFormat) { + Sheet sharedAccountsSheet=workbook.getSheet(TemplatePopulateImportConstants.SHARED_ACCOUNTS_SHEET_NAME); + Integer noOfEntries= ImportHandlerUtils.getNumberOfRows(sharedAccountsSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX); + for (int rowIndex=1;rowIndex<=noOfEntries;rowIndex++){ + Row row; + row=sharedAccountsSheet.getRow(rowIndex); + if (ImportHandlerUtils.isNotImported(row, SharedAccountsConstants.STATUS_COL)){ + shareAccountDataList.add(readSharedAccount(row,locale,dateFormat)); + } + } + } + + private ShareAccountData readSharedAccount(Row row,String locale, String dateFormat) { + String clientName = ImportHandlerUtils.readAsString(SharedAccountsConstants.CLIENT_NAME_COL, row); + Long clientId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME), clientName); + + String productName = ImportHandlerUtils.readAsString(SharedAccountsConstants.PRODUCT_COL, row); + Long productId=ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.SHARED_PRODUCTS_SHEET_NAME),productName); + + LocalDate submittedOnDate=ImportHandlerUtils.readAsDate(SharedAccountsConstants.SUBMITTED_ON_COL,row); + + String externalId = ImportHandlerUtils.readAsString(SharedAccountsConstants.EXTERNAL_ID_COL, row); + + Integer totNoOfShares=ImportHandlerUtils.readAsInt(SharedAccountsConstants.TOTAL_NO_SHARES_COL,row); + + Long defaultSavingsAccountId=ImportHandlerUtils.readAsLong(SharedAccountsConstants.DEFAULT_SAVINGS_AC_COL,row); + + Integer minimumActivePeriodDays=ImportHandlerUtils.readAsInt(SharedAccountsConstants.MINIMUM_ACTIVE_PERIOD_IN_DAYS_COL,row); + Integer minimumActivePeriodFrequencyType=0; + + Integer lockInPeriod=ImportHandlerUtils.readAsInt(SharedAccountsConstants.LOCK_IN_PERIOD_COL,row); + + Integer lockPeriodFrequencyType=null; + + if (ImportHandlerUtils.readAsString(SharedAccountsConstants.LOCK_IN_PERIOD_FREQUENCY_TYPE,row)!=null) { + if (ImportHandlerUtils.readAsString(SharedAccountsConstants.LOCK_IN_PERIOD_FREQUENCY_TYPE, row) + .equals(TemplatePopulateImportConstants.FREQUENCY_DAYS)) { + lockPeriodFrequencyType = 0; + } else if (ImportHandlerUtils.readAsString(SharedAccountsConstants.LOCK_IN_PERIOD_FREQUENCY_TYPE, row) + .equals(TemplatePopulateImportConstants.FREQUENCY_WEEKS)) { + lockPeriodFrequencyType = 1; + } else if (ImportHandlerUtils.readAsString(SharedAccountsConstants.LOCK_IN_PERIOD_FREQUENCY_TYPE, row) + .equals(TemplatePopulateImportConstants.FREQUENCY_MONTHS)) { + lockPeriodFrequencyType = 2; + } else if (ImportHandlerUtils.readAsString(SharedAccountsConstants.LOCK_IN_PERIOD_FREQUENCY_TYPE, row) + .equals(TemplatePopulateImportConstants.FREQUENCY_YEARS)) { + lockPeriodFrequencyType = 3; + } + } + LocalDate applicationDate=ImportHandlerUtils.readAsDate(SharedAccountsConstants.APPLICATION_DATE_COL,row); + Boolean allowDividendCalc=ImportHandlerUtils.readAsBoolean(SharedAccountsConstants.ALLOW_DIVIDEND_CALCULATION_FOR_INACTIVE_CLIENTS_COL,row); + + List charges=new ArrayList<>(); + for (int cellNo=SharedAccountsConstants.CHARGES_NAME_1_COL;cellNo staffList; + private Workbook workbook; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + + @Autowired + public StaffImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook=workbook; + this.staffList=new ArrayList<>(); + readExcelFile(locale,dateFormat); + return importEntity(dateFormat); + } + public void readExcelFile(String locale, String dateFormat) { + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.EMPLOYEE_SHEET_NAME); + Integer noOfEntries= ImportHandlerUtils.getNumberOfRows(staffSheet,TemplatePopulateImportConstants.FIRST_COLUMN_INDEX); + for (int rowIndex=1;rowIndex<=noOfEntries;rowIndex++){ + Row row; + row=staffSheet.getRow(rowIndex); + if ( ImportHandlerUtils.isNotImported(row, StaffConstants.STATUS_COL)){ + staffList.add(readStaff(row,locale,dateFormat)); + } + + } + } + + private StaffData readStaff(Row row,String locale, String dateFormat) { + String officeName = ImportHandlerUtils.readAsString( StaffConstants.OFFICE_NAME_COL, row); + Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName); + String firstName = ImportHandlerUtils.readAsString(StaffConstants.FIRST_NAME_COL, row); + String lastName = ImportHandlerUtils.readAsString(StaffConstants.LAST_NAME_COL, row); + Boolean isLoanOfficer=ImportHandlerUtils.readAsBoolean(StaffConstants.IS_LOAN_OFFICER,row); + String mobileNo=null; + if (ImportHandlerUtils.readAsLong(StaffConstants.MOBILE_NO_COL,row)!=null) + mobileNo=ImportHandlerUtils.readAsLong(StaffConstants.MOBILE_NO_COL,row).toString(); + LocalDate joinedOnDate=ImportHandlerUtils.readAsDate(StaffConstants.JOINED_ON_COL,row); + String externalId=ImportHandlerUtils.readAsString(StaffConstants.EXTERNAL_ID_COL,row); + Boolean isActive=ImportHandlerUtils.readAsBoolean(StaffConstants.IS_ACTIVE_COL,row); + + return StaffData.importInstance(externalId,firstName,lastName,mobileNo,officeId,isLoanOfficer,isActive, + joinedOnDate,row.getRowNum(),locale,dateFormat); + } + + public Count importEntity(String dateFormat) { + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.EMPLOYEE_SHEET_NAME); + int successCount=0; + int errorCount=0; + String errorMessage=""; + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat)); + for (StaffData staff: staffList) { + try { + String payload=gsonBuilder.create().toJson(staff); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createStaff()// + .withJson(payload) // + .build(); // + final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest); + successCount++; + Cell statusCell = staffSheet.getRow(staff.getRowIndex()).createCell(StaffConstants.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(staffSheet,staff.getRowIndex(),errorMessage,StaffConstants.STATUS_COL); + } + } + staffSheet.setColumnWidth(StaffConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + ImportHandlerUtils.writeString(StaffConstants.STATUS_COL, staffSheet.getRow(0), TemplatePopulateImportConstants.STATUS_COL_REPORT_HEADER); + return Count.instance(successCount,errorCount); + } + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/users/UserImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/users/UserImportHandler.java new file mode 100644 index 000000000..c1ec6396b --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/users/UserImportHandler.java @@ -0,0 +1,137 @@ +/** + * 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.users; + +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.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.UserConstants; +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.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.exception.*; +import org.apache.fineract.useradministration.data.AppUserData; +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 UserImportHandler implements ImportHandler{ + private Workbook workbook; + private List users; + private List statuses; + + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + + @Autowired + public UserImportHandler(final PortfolioCommandSourceWritePlatformService + commandsSourceWritePlatformService) { + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + } + + @Override + public Count process(Workbook workbook, String locale, String dateFormat) { + this.workbook=workbook; + users=new ArrayList<>(); + statuses=new ArrayList<>(); + readExcelFile(); + return importEntity(dateFormat); + } + + public void readExcelFile() { + Sheet usersSheet = workbook.getSheet(TemplatePopulateImportConstants.USER_SHEET_NAME); + Integer noOfEntries = ImportHandlerUtils.getNumberOfRows(usersSheet, TemplatePopulateImportConstants.FIRST_COLUMN_INDEX); + for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) { + Row row; + row = usersSheet.getRow(rowIndex); + if(ImportHandlerUtils.isNotImported(row, UserConstants.STATUS_COL)) { + users.add(readUsers(row)); + } + } + } + + private AppUserData readUsers(Row row) { + String officeName = ImportHandlerUtils.readAsString(UserConstants.OFFICE_NAME_COL, row); + Long officeId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME), officeName); + String staffName = ImportHandlerUtils.readAsString(UserConstants.STAFF_NAME_COL, row); + Long staffId = ImportHandlerUtils.getIdByName(workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME), staffName); + String userName=ImportHandlerUtils.readAsString(UserConstants.USER_NAME_COL,row); + String firstName=ImportHandlerUtils.readAsString(UserConstants.FIRST_NAME_COL,row); + String lastName=ImportHandlerUtils.readAsString(UserConstants.LAST_NAME_COL,row); + String email=ImportHandlerUtils.readAsString(UserConstants.EMAIL_COL,row); + Boolean autoGenPw=ImportHandlerUtils.readAsBoolean(UserConstants.AUTO_GEN_PW_COL,row); + Boolean overridepw=ImportHandlerUtils.readAsBoolean(UserConstants.OVERRIDE_PW_EXPIRY_POLICY_COL,row); + String status=ImportHandlerUtils.readAsString(UserConstants.STATUS_COL,row); + statuses.add(status); + + List rolesIds=new ArrayList<>(); + for (int cellNo=UserConstants.ROLE_NAME_START_COL;cellNo offices, int officeNameCol, + int activationDateCol,String dateFormat) { + if(offices!=null){ + Workbook workbook = sheet.getWorkbook(); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + int rowIndex = 0; + for (OfficeData office : offices) { + Row row = sheet.createRow(++rowIndex); + writeString(officeNameCol, row, office.name().trim().replaceAll("[ )(]", "_")); + writeDate(activationDateCol, row, + "" + office.getOpeningDate().getDayOfMonth() + "/" + + office.getOpeningDate().getMonthOfYear() + "/" + office.getOpeningDate().getYear(), + dateCellStyle,dateFormat); + + } + } + } + + protected void setClientAndGroupDateLookupTable(Sheet sheet, List clients, + List groups, int nameCol, int activationDateCol,boolean containsClientExtId, + String dateFormat) { + Workbook workbook = sheet.getWorkbook(); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + int rowIndex = 0; + SimpleDateFormat outputFormat = new SimpleDateFormat(dateFormat); + SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date date = null; + try { + if (clients != null){ + for (ClientData client : clients) { + Row row = sheet.getRow(++rowIndex); + if (row == null) + row = sheet.createRow(rowIndex); + writeString(nameCol, row, client.displayName().replaceAll("[ )(] ", "_") + "(" + client.id() + ")"); + + if (client.getActivationDate() != null) { + date = inputFormat.parse(client.getActivationDate().toString()); + writeDate(activationDateCol, row, outputFormat.format(date), dateCellStyle,dateFormat); + } + if (containsClientExtId){ + if (client.getExternalId()!=null){ + writeString(nameCol+1,row,client.getExternalId()); + } + } + + } + } + if (groups!=null){ + for (GroupGeneralData group : groups) { + Row row = sheet.getRow(++rowIndex); + if (row == null) + row = sheet.createRow(rowIndex); + writeString(nameCol, row, group.getName().replaceAll("[ )(] ", "_")); + + date = inputFormat.parse(group.getActivationDate().toString()); + writeDate(activationDateCol, row, outputFormat.format(date), dateCellStyle,dateFormat); + } + } + } catch (ParseException e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/CenterSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/CenterSheetPopulator.java new file mode 100644 index 000000000..bf828b403 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/CenterSheetPopulator.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.populator; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.organisation.office.data.OfficeData; +import org.apache.fineract.portfolio.group.data.CenterData; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CenterSheetPopulator extends AbstractWorkbookPopulator { + private List allCenters; + private List offices; + + private Map> officeToCenters; + private Map officeNameToBeginEndIndexesOfCenters; + private Map centerNameToCenterId; + + private static final int OFFICE_NAME_COL = 0; + private static final int CENTER_NAME_COL = 1; + private static final int CENTER_ID_COL = 2; + + public CenterSheetPopulator(List centers, List offices) { + this.allCenters = centers; + this.offices = offices; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet centerSheet = workbook.createSheet(TemplatePopulateImportConstants.CENTER_SHEET_NAME); + setLayout(centerSheet); + setOfficeToCentersMap(); + centerNameToCenterIdMap(); + populateCentersByOfficeName(centerSheet); + centerSheet.protectSheet(""); + } + + private void centerNameToCenterIdMap() { + centerNameToCenterId = new HashMap(); + for (CenterData centerData : allCenters) { + centerNameToCenterId.put(centerData.getName(), centerData.getId()); + } + } + + private void populateCentersByOfficeName(Sheet centerSheet) { + int rowIndex = 1, officeIndex = 0, startIndex = 1; + officeNameToBeginEndIndexesOfCenters = new HashMap(); + Row row = centerSheet.createRow(rowIndex); + for (OfficeData office : offices) { + startIndex = rowIndex + 1; + writeString(OFFICE_NAME_COL, row, office.name()); + ArrayList centersList = new ArrayList(); + + if (officeToCenters.containsKey(office.name().trim().replaceAll("[ )(]", "_"))){ + centersList = officeToCenters.get(office.name().trim().replaceAll("[ )(]", "_")); + if (!centersList.isEmpty()) { + for (String centerName : centersList) { + writeString(CENTER_NAME_COL, row, centerName); + writeLong(CENTER_ID_COL, row, centerNameToCenterId.get(centerName)); + row = centerSheet.createRow(++rowIndex); + } + officeNameToBeginEndIndexesOfCenters.put(officeIndex++, new Integer[] { startIndex, rowIndex }); + } else { + officeNameToBeginEndIndexesOfCenters.put(officeIndex++, new Integer[] { startIndex, rowIndex + 1 }); + } + } + } + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + for (int colIndex = 0; colIndex <= 10; colIndex++) + worksheet.setColumnWidth(colIndex, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + writeString(OFFICE_NAME_COL, rowHeader, "Office Names"); + writeString(CENTER_NAME_COL, rowHeader, "Center Names"); + writeString(CENTER_ID_COL, rowHeader, "Center ID"); + } + + private void setOfficeToCentersMap() { + officeToCenters = new HashMap<>(); + for (CenterData center : allCenters) { + add(center.getOfficeName().trim().replaceAll("[ )(]", "_"), center.getName().trim()); + } + } + + // Guava Multi-map can reduce this. + private void add(String key, String value) { + ArrayList values = officeToCenters.get(key); + if (values == null) { + values = new ArrayList<>(); + } + values.add(value); + officeToCenters.put(key, values); + } + + public Map getOfficeNameToBeginEndIndexesOfCenters() { + return officeNameToBeginEndIndexesOfCenters; + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ClientSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ClientSheetPopulator.java new file mode 100644 index 000000000..69c4ba4d8 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ClientSheetPopulator.java @@ -0,0 +1,144 @@ +/** + * 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.populator; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.organisation.office.data.OfficeData; +import org.apache.fineract.portfolio.client.data.ClientData; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ClientSheetPopulator extends AbstractWorkbookPopulator { + private List allClients; + private List officesDataList; + + private Map> officeToClients; + private Map officeNameToBeginEndIndexesOfClients; + private Map clientNameToClientId; + private Map clientNameToSavingsAccountIds; + + private static final int OFFICE_NAME_COL = 0; + private static final int CLIENT_NAME_COL = 1; + private static final int CLIENT_ID_COL = 2; + + public ClientSheetPopulator(final List clients, final List Offices) { + this.allClients = clients; + this.officesDataList = Offices; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet clientSheet = workbook.createSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME); + setLayout(clientSheet); + setOfficeToClientsMap(); + setClientNameToClientIdMap(); + populateClientsByOfficeName(clientSheet); + clientSheet.protectSheet(""); + setClientNameToSavingsAccountsIdsMap(); + } + + private void setClientNameToClientIdMap() { + clientNameToClientId = new HashMap<>(); + for (ClientData clientData : allClients) { + clientNameToClientId.put(clientData.displayName().trim() + "(" + clientData.id() + ")", + clientData.id()); + } + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + for (int colIndex = 1; colIndex <= 10; colIndex++) + worksheet.setColumnWidth(colIndex, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + writeString(OFFICE_NAME_COL, rowHeader, "Office Names"); + writeString(CLIENT_NAME_COL, rowHeader, "Client Names"); + writeString(CLIENT_ID_COL, rowHeader, "Client ID"); + } + + private void setOfficeToClientsMap() { + officeToClients = new HashMap<>(); + for (ClientData person : allClients) { + addToOfficeClientMap(person.getOfficeName().trim().replaceAll("[ )(]", "_"), + person.displayName().trim() + "(" + person.id() + ")"); + } + } + + private void setClientNameToSavingsAccountsIdsMap(){ + clientNameToSavingsAccountIds=new HashMap<>(); + for (ClientData client: allClients) { + clientNameToSavingsAccountIds.put(client.displayName().trim() + "(" + client.id() + ")",client.getSavingsAccountId()); + } + + } + + // Guava Multi-map can reduce this. + private void addToOfficeClientMap(String key, String value) { + ArrayList values = officeToClients.get(key); + if (values == null) { + values = new ArrayList(); + } + values.add(value); + officeToClients.put(key, values); + } + + private void populateClientsByOfficeName(Sheet clientSheet) { + int rowIndex = 1, startIndex = 1, officeIndex = 0; + officeNameToBeginEndIndexesOfClients = new HashMap<>(); + Row row = clientSheet.createRow(rowIndex); + for (OfficeData office : officesDataList) { + startIndex = rowIndex + 1; + writeString(OFFICE_NAME_COL, row, office.name()); + ArrayList clientList = new ArrayList(); + if (officeToClients.containsKey(office.name().trim().replaceAll("[ )(]", "_"))) + clientList = officeToClients.get(office.name().trim().replaceAll("[ )(]", "_")); + if (!clientList.isEmpty()) { + for (String clientName : clientList) { + writeString(CLIENT_NAME_COL, row, clientName); + writeLong(CLIENT_ID_COL, row, clientNameToClientId.get(clientName)); + row = clientSheet.createRow(++rowIndex); + } + officeNameToBeginEndIndexesOfClients.put(officeIndex++, new Integer[] { startIndex, rowIndex }); + } else + officeIndex++; + } + } + + public List getClients() { + return allClients; + } + + public Integer getClientsSize() { + return allClients.size(); + } + + public Map getOfficeNameToBeginEndIndexesOfClients() { + return officeNameToBeginEndIndexesOfClients; + } + + public Map getClientNameToSavingsAccountIds() { + return clientNameToSavingsAccountIds; + } +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ExtrasSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ExtrasSheetPopulator.java new file mode 100644 index 000000000..e97eb7aeb --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/ExtrasSheetPopulator.java @@ -0,0 +1,116 @@ +/** + * 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.populator; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.organisation.monetary.data.CurrencyData; +import org.apache.fineract.portfolio.fund.data.FundData; +import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.util.List; + +public class ExtrasSheetPopulator extends AbstractWorkbookPopulator { + + private List funds; + private List paymentTypes; + private List currencies; + + private static final int FUND_ID_COL = 0; + private static final int FUND_NAME_COL = 1; + private static final int PAYMENT_TYPE_ID_COL = 2; + private static final int PAYMENT_TYPE_NAME_COL = 3; + private static final int CURRENCY_CODE_COL = 4; + private static final int CURRENCY_NAME_COL = 5; + + + public ExtrasSheetPopulator(List funds, List paymentTypes, + List currencies) { + this.funds = funds; + this.paymentTypes = paymentTypes; + this.currencies = currencies; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + int fundRowIndex = 1; + Sheet extrasSheet = workbook.createSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME); + setLayout(extrasSheet); + for (FundData fund : funds) { + Row row = extrasSheet.createRow(fundRowIndex++); + writeLong(FUND_ID_COL, row, fund.getId()); + writeString(FUND_NAME_COL, row, fund.getName()); + } + int paymentTypeRowIndex = 1; + for (PaymentTypeData paymentType : paymentTypes) { + Row row; + if (paymentTypeRowIndex < fundRowIndex) + row = extrasSheet.getRow(paymentTypeRowIndex++); + else + row = extrasSheet.createRow(paymentTypeRowIndex++); + writeLong(PAYMENT_TYPE_ID_COL, row, paymentType.getId()); + writeString(PAYMENT_TYPE_NAME_COL, row, paymentType.getName().trim().replaceAll("[ )(]", "_")); + } + int currencyCodeRowIndex = 1; + for (CurrencyData currencies : currencies) { + Row row; + if (currencyCodeRowIndex < paymentTypeRowIndex) + row = extrasSheet.getRow(currencyCodeRowIndex++); + else + row = extrasSheet.createRow(currencyCodeRowIndex++); + + writeString(CURRENCY_NAME_COL, row, currencies.getName().trim().replaceAll("[ )(]", "_")); + writeString(CURRENCY_CODE_COL, row, currencies.code()); + } + extrasSheet.protectSheet(""); + + } + + private void setLayout(Sheet worksheet) { + worksheet.setColumnWidth(FUND_ID_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(FUND_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(PAYMENT_TYPE_ID_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(PAYMENT_TYPE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(CURRENCY_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(CURRENCY_CODE_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + writeString(FUND_ID_COL, rowHeader, "Fund ID"); + writeString(FUND_NAME_COL, rowHeader, "Name"); + writeString(PAYMENT_TYPE_ID_COL, rowHeader, "Payment Type ID"); + writeString(PAYMENT_TYPE_NAME_COL, rowHeader, "Payment Type Name"); + writeString(CURRENCY_NAME_COL, rowHeader, "Currency Type "); + writeString(CURRENCY_CODE_COL, rowHeader, "Currency Code "); + } + public Integer getFundsSize() { + return funds.size(); + } + public Integer getPaymentTypesSize() { + return paymentTypes.size(); + } + + public Integer getCurrenciesSize() { + return currencies.size(); + } + + + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/FixedDepositProductSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/FixedDepositProductSheetPopulator.java new file mode 100644 index 000000000..0e2185b39 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/FixedDepositProductSheetPopulator.java @@ -0,0 +1,173 @@ +/** + * 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.populator; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.organisation.monetary.data.CurrencyData; +import org.apache.fineract.portfolio.savings.data.FixedDepositProductData; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.util.List; + +public class FixedDepositProductSheetPopulator extends AbstractWorkbookPopulator { + List products; + + private static final int ID_COL = 0; + private static final int NAME_COL = 1; + private static final int SHORT_NAME_COL = 2; + private static final int NOMINAL_ANNUAL_INTEREST_RATE_COL = 3; + private static final int INTEREST_COMPOUNDING_PERIOD_COL = 4; + private static final int INTEREST_POSTING_PERIOD_COL = 5; + private static final int INTEREST_CALCULATION_COL = 6; + private static final int INTEREST_CALCULATION_DAYS_IN_YEAR_COL = 7; + private static final int LOCKIN_PERIOD_COL = 8; + private static final int LOCKIN_PERIOD_FREQUENCY_COL = 9; + private static final int CURRENCY_COL = 10; + private static final int MIN_DEPOSIT_COL = 11; + private static final int MAX_DEPOSIT_COL = 12; + private static final int DEPOSIT_COL = 13; + private static final int MIN_DEPOSIT_TERM_COL = 14; + private static final int MIN_DEPOSIT_TERM_TYPE_COL = 15; + private static final int MAX_DEPOSIT_TERM_COL = 16; + private static final int MAX_DEPOSIT_TERM_TYPE_COL = 17; + private static final int PRECLOSURE_PENAL_APPLICABLE_COL = 18; + private static final int PRECLOSURE_PENAL_INTEREST_COL = 19; + private static final int PRECLOSURE_INTEREST_TYPE_COL = 20; + private static final int IN_MULTIPLES_OF_DEPOSIT_TERM_COL = 21; + private static final int IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL = 22; + + public FixedDepositProductSheetPopulator(List fixedDepositProducts) { + this.products =fixedDepositProducts; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + int rowIndex = 1; + Sheet productSheet = workbook.createSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME); + setLayout(productSheet); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + for(FixedDepositProductData product : products) { + Row row = productSheet.createRow(rowIndex++); + writeLong(ID_COL, row, product.getId()); + writeString(NAME_COL, row, product.getName().trim().replaceAll("[ )(]", "_")); + writeString(SHORT_NAME_COL, row, product.getShortName().trim().replaceAll("[ )(]", "_")); + writeBigDecimal(NOMINAL_ANNUAL_INTEREST_RATE_COL, row, product.getNominalAnnualInterestRate()); + writeString(INTEREST_COMPOUNDING_PERIOD_COL, row, product.getInterestCompoundingPeriodType().getValue()); + writeString(INTEREST_POSTING_PERIOD_COL, row, product.getInterestPostingPeriodType().getValue()); + writeString(INTEREST_CALCULATION_COL, row, product.getInterestCalculationType().getValue()); + writeString(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row, product.getInterestCalculationDaysInYearType().getValue()); + + writeBoolean(PRECLOSURE_PENAL_APPLICABLE_COL, row, product.isPreClosurePenalApplicable()); + writeInt(MIN_DEPOSIT_TERM_COL, row, product.getMinDepositTerm()); + writeString(MIN_DEPOSIT_TERM_TYPE_COL, row, product.getMinDepositTermType().getValue()); + + if(product.getMinDepositAmount() != null) + writeBigDecimal(MIN_DEPOSIT_COL, row, product.getMinDepositAmount()); + if(product.getMaxDepositAmount() != null) + writeBigDecimal(MAX_DEPOSIT_COL, row, product.getMaxDepositAmount()); + if(product.getDepositAmount() != null) + writeBigDecimal(DEPOSIT_COL, row, product.getDepositAmount()); + if(product.getMaxDepositTerm() != null) + writeInt(MAX_DEPOSIT_TERM_COL, row, product.getMaxDepositTerm()); + if(product.getInMultiplesOfDepositTerm() != null) + writeInt(IN_MULTIPLES_OF_DEPOSIT_TERM_COL, row, product.getInMultiplesOfDepositTerm()); + if(product.getPreClosurePenalInterest() != null) + writeBigDecimal(PRECLOSURE_PENAL_INTEREST_COL, row, product.getPreClosurePenalInterest()); + if(product.getMaxDepositTermType() != null) + writeString(MAX_DEPOSIT_TERM_TYPE_COL, row, product.getMaxDepositTermType().getValue()); + if(product.getPreClosurePenalInterestOnType() != null) + writeString(PRECLOSURE_INTEREST_TYPE_COL, row, product.getPreClosurePenalInterestOnType().getValue()); + if(product.getInMultiplesOfDepositTermType() != null) + writeString(IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL, row, product.getInMultiplesOfDepositTermType().getValue()); + + if(product.getLockinPeriodFrequency() != null) + writeInt(LOCKIN_PERIOD_COL, row, product.getLockinPeriodFrequency()); + if(product.getLockinPeriodFrequencyType() != null) + writeString(LOCKIN_PERIOD_FREQUENCY_COL, row, product.getLockinPeriodFrequencyType().getValue()); + CurrencyData currency = product.getCurrency(); + writeString(CURRENCY_COL, row, currency.code()); + } + productSheet.protectSheet(""); + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SHORT_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(NOMINAL_ANNUAL_INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_COMPOUNDING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_POSTING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_CALCULATION_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LOCKIN_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LOCKIN_PERIOD_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CURRENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MIN_DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MAX_DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MIN_DEPOSIT_TERM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MAX_DEPOSIT_TERM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MIN_DEPOSIT_TERM_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MAX_DEPOSIT_TERM_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(PRECLOSURE_PENAL_APPLICABLE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(PRECLOSURE_PENAL_INTEREST_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(PRECLOSURE_INTEREST_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(IN_MULTIPLES_OF_DEPOSIT_TERM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + + writeString(ID_COL, rowHeader, "ID"); + writeString(NAME_COL, rowHeader, "Name"); + writeString(SHORT_NAME_COL, rowHeader, "Short Name"); + writeString(NOMINAL_ANNUAL_INTEREST_RATE_COL, rowHeader, "Interest"); + writeString(INTEREST_COMPOUNDING_PERIOD_COL, rowHeader, "Interest Compounding Period"); + writeString(INTEREST_POSTING_PERIOD_COL, rowHeader, "Interest Posting Period"); + writeString(INTEREST_CALCULATION_COL, rowHeader, "Interest Calculated Using"); + writeString(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, rowHeader, "# Days In Year"); + writeString(LOCKIN_PERIOD_COL, rowHeader, "Locked In For"); + writeString(LOCKIN_PERIOD_FREQUENCY_COL, rowHeader, "Frequency"); + writeString(CURRENCY_COL, rowHeader, "Currency"); + writeString(MIN_DEPOSIT_COL, rowHeader, "Min Deposit"); + writeString(MAX_DEPOSIT_COL, rowHeader, "Max Deposit"); + writeString(DEPOSIT_COL, rowHeader, "Deposit"); + writeString(MIN_DEPOSIT_TERM_COL, rowHeader, "Min Deposit Term"); + writeString(MAX_DEPOSIT_TERM_COL, rowHeader, "Max Deposit Term"); + writeString(MIN_DEPOSIT_TERM_TYPE_COL, rowHeader, "Min Deposit Term Type"); + writeString(MAX_DEPOSIT_TERM_TYPE_COL, rowHeader, "Max Deposit Term Type"); + writeString(PRECLOSURE_PENAL_APPLICABLE_COL, rowHeader, "Preclosure Penal Applicable"); + writeString(PRECLOSURE_PENAL_INTEREST_COL, rowHeader, "Penal Interest"); + writeString(PRECLOSURE_INTEREST_TYPE_COL, rowHeader, "Penal Interest Type"); + writeString(IN_MULTIPLES_OF_DEPOSIT_TERM_COL, rowHeader, "Multiples of Deposit Term"); + writeString(IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL, rowHeader, "Multiples of Deposit Term Type"); + } + + public List getProducts() { + return products; + } + + public Integer getProductsSize() { + return products.size(); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/GlAccountSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/GlAccountSheetPopulator.java new file mode 100644 index 000000000..04390c1af --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/GlAccountSheetPopulator.java @@ -0,0 +1,71 @@ +/** + * 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.populator; + +import org.apache.fineract.accounting.glaccount.data.GLAccountData; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.util.List; + +public class GlAccountSheetPopulator extends AbstractWorkbookPopulator { + private List allGlAccounts; + + private static final int ID_COL = 0; + private static final int ACCOUNT_NAME_COL = 1; + + public GlAccountSheetPopulator(List glAccounts) { + this.allGlAccounts = glAccounts; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + int rowIndex = 1; + Sheet glAccountSheet = workbook.createSheet(TemplatePopulateImportConstants.GL_ACCOUNTS_SHEET_NAME); + setLayout(glAccountSheet); + populateglAccounts(glAccountSheet, rowIndex); + glAccountSheet.protectSheet(""); + + } + + private void setLayout(Sheet worksheet) { + worksheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ACCOUNT_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + writeString(ID_COL, rowHeader, "Gl Account ID"); + writeString(ACCOUNT_NAME_COL, rowHeader, "Gl Account Name"); + } + + private void populateglAccounts(Sheet GlAccountSheet, int rowIndex) { + for (GLAccountData glAccount : allGlAccounts) { + Row row = GlAccountSheet.createRow(rowIndex); + writeLong(ID_COL, row, glAccount.getId()); + writeString(ACCOUNT_NAME_COL, row, glAccount.getName().trim().replaceAll("[ )(]", "_")); + rowIndex++; + } + } + + public Integer getGlAccountNamesSize() { + return allGlAccounts.size(); + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/GroupSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/GroupSheetPopulator.java new file mode 100644 index 000000000..4d6e1b38d --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/GroupSheetPopulator.java @@ -0,0 +1,126 @@ +/** + * 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.populator; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.organisation.office.data.OfficeData; +import org.apache.fineract.portfolio.group.data.GroupGeneralData; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +public class GroupSheetPopulator extends AbstractWorkbookPopulator { + private List groups; + private List offices; + + private Map> officeToGroups; + private Map officeNameToBeginEndIndexesOfGroups; + private Map groupNameToGroupId; + + private static final int OFFICE_NAME_COL = 0; + private static final int GROUP_NAME_COL = 1; + private static final int GROUP_ID_COL = 2; + + public GroupSheetPopulator(final List groups, final List offices) { + this.groups = groups; + this.offices = offices; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet groupSheet = workbook.createSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME); + setLayout(groupSheet); + setGroupNameToGroupIdMap(); + setOfficeToGroupsMap(); + populateGroupsByOfficeName(groupSheet); + groupSheet.protectSheet(""); + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + for (int colIndex = 0; colIndex <= 10; colIndex++) + worksheet.setColumnWidth(colIndex, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + writeString(OFFICE_NAME_COL, rowHeader, "Office Names"); + writeString(GROUP_NAME_COL, rowHeader, "Group Names"); + writeString(GROUP_ID_COL, rowHeader, "Group ID"); + } + + private void setOfficeToGroupsMap() { + officeToGroups = new HashMap<>(); + for (GroupGeneralData group : groups) { + add(group.getOfficeName().trim().replaceAll("[ )(]", "_"), group.getName().trim()); + } + } + //Guava Multi-map can reduce this. + private void add(String key, String value) { + ArrayList values = officeToGroups.get(key); + if (values == null) { + values = new ArrayList<>(); + } + values.add(value); + officeToGroups.put(key, values); + } + private void populateGroupsByOfficeName(Sheet groupSheet) { + int rowIndex = 1, officeIndex = 0, startIndex = 1; + officeNameToBeginEndIndexesOfGroups = new HashMap<>(); + Row row = groupSheet.createRow(rowIndex); + for(OfficeData office : offices) { + startIndex = rowIndex+1; + writeString(OFFICE_NAME_COL, row, office.name()); + ArrayList groupsList = new ArrayList<>(); + + if(officeToGroups.containsKey(office.name().trim().replaceAll("[ )(]", "_"))) + groupsList = officeToGroups.get(office.name().trim().replaceAll("[ )(]", "_")); + + if(!groupsList.isEmpty()) { + for(String groupName : groupsList) { + writeString(GROUP_NAME_COL, row, groupName); + writeLong(GROUP_ID_COL, row, groupNameToGroupId.get(groupName)); + row = groupSheet.createRow(++rowIndex); + } + officeNameToBeginEndIndexesOfGroups.put(officeIndex++, new Integer[]{startIndex, rowIndex}); + } + else { + officeNameToBeginEndIndexesOfGroups.put(officeIndex++, new Integer[]{startIndex, rowIndex+1}); + } + } + } + public List getGroups() { + return groups; + } + public Integer getGroupsSize() { + return groups.size(); + } + public Map getOfficeNameToBeginEndIndexesOfGroups() { + return officeNameToBeginEndIndexesOfGroups; + } + private void setGroupNameToGroupIdMap(){ + groupNameToGroupId=new HashMap(); + for (GroupGeneralData group : groups) { + groupNameToGroupId.put(group.getName().trim(), group.getId()); + } + } +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/LoanProductSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/LoanProductSheetPopulator.java new file mode 100644 index 000000000..93de8841d --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/LoanProductSheetPopulator.java @@ -0,0 +1,199 @@ +/** + * 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.populator; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.portfolio.loanproduct.data.LoanProductData; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.util.List; + + +public class LoanProductSheetPopulator extends AbstractWorkbookPopulator { + + private List products; + + private static final int ID_COL = 0; + private static final int NAME_COL = 1; + private static final int FUND_NAME_COL = 2; + private static final int PRINCIPAL_COL = 3; + private static final int MIN_PRINCIPAL_COL = 4; + private static final int MAX_PRINCIPAL_COL = 5; + private static final int NO_OF_REPAYMENTS_COL = 6; + private static final int MIN_REPAYMENTS_COL = 7; + private static final int MAX_REPAYMENTS_COL = 8; + private static final int REPAYMENT_EVERY_COL = 9; + private static final int REPAYMENT_FREQUENCY_COL = 10; + private static final int INTEREST_RATE_COL = 11; + private static final int MIN_INTEREST_RATE_COL = 12; + private static final int MAX_INTEREST_RATE_COL = 13; + private static final int INTEREST_RATE_FREQUENCY_COL = 14; + private static final int AMORTIZATION_TYPE_COL = 15; + private static final int INTEREST_TYPE_COL = 16; + private static final int INTEREST_CALCULATION_PERIOD_TYPE_COL = 17; + private static final int IN_ARREARS_TOLERANCE_COL = 18; + private static final int TRANSACTION_PROCESSING_STRATEGY_NAME_COL = 19; + private static final int GRACE_ON_PRINCIPAL_PAYMENT_COL = 20; + private static final int GRACE_ON_INTEREST_PAYMENT_COL = 21; + private static final int GRACE_ON_INTEREST_CHARGED_COL = 22; + private static final int START_DATE_COL = 23; + private static final int CLOSE_DATE_COL = 24; + + + + public LoanProductSheetPopulator(List products) { + this.products = products; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + int rowIndex = 1; + Sheet productSheet = workbook.createSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME); + setLayout(productSheet); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + for (LoanProductData product : products) { + Row row = productSheet.createRow(rowIndex++); + writeLong(ID_COL, row, product.getId()); + writeString(NAME_COL, row, product.getName().trim().replaceAll("[ )(]", "_")); + if (product.getFundName() != null) + writeString(FUND_NAME_COL, row, product.getFundName()); + writeBigDecimal(PRINCIPAL_COL, row, product.getPrincipal()); + if (product.getMinPrincipal() != null) + writeBigDecimal(MIN_PRINCIPAL_COL, row, product.getMinPrincipal()); + else + writeInt(MIN_PRINCIPAL_COL, row, 1); + if (product.getMaxPrincipal() != null) + writeBigDecimal(MAX_PRINCIPAL_COL, row, product.getMaxPrincipal()); + else + writeInt(MAX_PRINCIPAL_COL, row, 999999999); + writeInt(NO_OF_REPAYMENTS_COL, row, product.getNumberOfRepayments()); + if (product.getMinNumberOfRepayments() != null) + writeInt(MIN_REPAYMENTS_COL, row, product.getMinNumberOfRepayments()); + else + writeInt(MIN_REPAYMENTS_COL, row, 1); + if (product.getMaxNumberOfRepayments() != null) + writeInt(MAX_REPAYMENTS_COL, row, product.getMaxNumberOfRepayments()); + else + writeInt(MAX_REPAYMENTS_COL, row, 999999999); + writeInt(REPAYMENT_EVERY_COL, row, product.getRepaymentEvery()); + writeString(REPAYMENT_FREQUENCY_COL, row, product.getRepaymentFrequencyType().getValue()); + writeBigDecimal(INTEREST_RATE_COL, row, product.getInterestRatePerPeriod()); + if (product.getMinInterestRatePerPeriod() != null) + writeBigDecimal(MIN_INTEREST_RATE_COL, row, product.getMinInterestRatePerPeriod()); + else + writeInt(MIN_INTEREST_RATE_COL, row, 1); + if (product.getMaxInterestRatePerPeriod() != null) + writeBigDecimal(MAX_INTEREST_RATE_COL, row, product.getMaxInterestRatePerPeriod()); + else + writeInt(MAX_INTEREST_RATE_COL, row, 999999999); + writeString(INTEREST_RATE_FREQUENCY_COL, row, product.getInterestRateFrequencyType().getValue()); + writeString(AMORTIZATION_TYPE_COL, row, product.getAmortizationType().getValue()); + writeString(INTEREST_TYPE_COL, row, product.getInterestType().getValue()); + writeString(INTEREST_CALCULATION_PERIOD_TYPE_COL, row, + product.getInterestCalculationPeriodType().getValue()); + if (product.getInArrearsTolerance() != null) + writeBigDecimal(IN_ARREARS_TOLERANCE_COL, row, product.getInArrearsTolerance()); + writeString(TRANSACTION_PROCESSING_STRATEGY_NAME_COL, row, product.getTransactionProcessingStrategyName()); + if (product.getGraceOnPrincipalPayment() != null) + writeInt(GRACE_ON_PRINCIPAL_PAYMENT_COL, row, product.getGraceOnPrincipalPayment()); + if (product.getGraceOnInterestPayment() != null) + writeInt(GRACE_ON_INTEREST_PAYMENT_COL, row, product.getGraceOnInterestPayment()); + if (product.getGraceOnInterestCharged() != null) + writeInt(GRACE_ON_INTEREST_CHARGED_COL, row, product.getGraceOnInterestCharged()); + if (product.getStartDate() != null) + writeDate(START_DATE_COL, row, product.getStartDate().toString(), dateCellStyle,dateFormat); + else + writeDate(START_DATE_COL, row, "1/1/1970", dateCellStyle,dateFormat); + if (product.getCloseDate() != null) + writeDate(CLOSE_DATE_COL, row, product.getCloseDate().toString(), dateCellStyle,dateFormat); + else + writeDate(CLOSE_DATE_COL, row, "1/1/2040", dateCellStyle,dateFormat); + productSheet.protectSheet(""); + } + + } + + private void setLayout(Sheet worksheet) { + worksheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FUND_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(PRINCIPAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MIN_PRINCIPAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MAX_PRINCIPAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(NO_OF_REPAYMENTS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MIN_REPAYMENTS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MAX_REPAYMENTS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(REPAYMENT_EVERY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(REPAYMENT_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MIN_INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MAX_INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_RATE_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(AMORTIZATION_TYPE_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(INTEREST_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_CALCULATION_PERIOD_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(IN_ARREARS_TOLERANCE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(TRANSACTION_PROCESSING_STRATEGY_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GRACE_ON_PRINCIPAL_PAYMENT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GRACE_ON_INTEREST_PAYMENT_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(GRACE_ON_INTEREST_CHARGED_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(START_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CLOSE_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + writeString(ID_COL, rowHeader, "ID"); + writeString(NAME_COL, rowHeader, "Name"); + writeString(FUND_NAME_COL, rowHeader, "Fund"); + writeString(PRINCIPAL_COL, rowHeader, "Principal"); + writeString(MIN_PRINCIPAL_COL, rowHeader, "Min Principal"); + writeString(MAX_PRINCIPAL_COL, rowHeader, "Max Principal"); + writeString(NO_OF_REPAYMENTS_COL, rowHeader, "# of Repayments"); + writeString(MIN_REPAYMENTS_COL, rowHeader, "Min Repayments"); + writeString(MAX_REPAYMENTS_COL, rowHeader, "Max Repayments"); + writeString(REPAYMENT_EVERY_COL, rowHeader, "Repayment Every"); + writeString(REPAYMENT_FREQUENCY_COL, rowHeader, "Frequency"); + writeString(INTEREST_RATE_COL, rowHeader, "Interest"); + writeString(MIN_INTEREST_RATE_COL, rowHeader, "Min Interest"); + writeString(MAX_INTEREST_RATE_COL, rowHeader, "Max Interest"); + writeString(INTEREST_RATE_FREQUENCY_COL, rowHeader, "Frequency"); + writeString(AMORTIZATION_TYPE_COL, rowHeader, "Amortization Type"); + writeString(INTEREST_TYPE_COL, rowHeader, "Interest Type"); + writeString(INTEREST_CALCULATION_PERIOD_TYPE_COL, rowHeader, "Interest Calculation Period"); + writeString(IN_ARREARS_TOLERANCE_COL, rowHeader, "In Arrears Tolerance"); + writeString(TRANSACTION_PROCESSING_STRATEGY_NAME_COL, rowHeader, "Transaction Processing Strategy"); + writeString(GRACE_ON_PRINCIPAL_PAYMENT_COL, rowHeader, "Grace On Principal Payment"); + writeString(GRACE_ON_INTEREST_PAYMENT_COL, rowHeader, "Grace on Interest Payment"); + writeString(GRACE_ON_INTEREST_CHARGED_COL, rowHeader, "Grace on Interest Charged"); + writeString(START_DATE_COL, rowHeader, "Start Date"); + writeString(CLOSE_DATE_COL, rowHeader, "End Date"); + } + public List getProducts(){ + return products; + + } + public Integer getProductsSize() { + return products.size(); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/OfficeSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/OfficeSheetPopulator.java new file mode 100644 index 000000000..a2ff62070 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/OfficeSheetPopulator.java @@ -0,0 +1,82 @@ +/** + * 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.populator; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.organisation.office.data.OfficeData; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.util.ArrayList; +import java.util.List; + +public class OfficeSheetPopulator extends AbstractWorkbookPopulator { + + private List offices; + + private static final int ID_COL = 0; + private static final int OFFICE_NAME_COL = 1; + + public OfficeSheetPopulator(final List offices) { + this.offices = offices; + } + + + @Override + public void populate(final Workbook workbook,String dateFormat) { + int rowIndex = 1; + Sheet officeSheet = workbook.createSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + setLayout(officeSheet); + + populateOffices(officeSheet, rowIndex); + officeSheet.protectSheet(""); + } + + private void populateOffices(Sheet officeSheet, int rowIndex) { + for (OfficeData office : offices) { + Row row = officeSheet.createRow(rowIndex); + writeLong(ID_COL, row, office.getId()); + writeString(OFFICE_NAME_COL, row, office.name().trim().replaceAll("[ )(]", "_")); + rowIndex++; + } + } + + private void setLayout(Sheet worksheet) { + worksheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + writeString(ID_COL, rowHeader, "ID"); + writeString(OFFICE_NAME_COL, rowHeader, "Name"); + } + + public List getOffices() { + return offices; + } + + public List getOfficeNames() { + List officeNames=new ArrayList<>(); + for (OfficeData office : offices) { + officeNames.add(office.name()); + } + return officeNames; + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/PersonnelSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/PersonnelSheetPopulator.java new file mode 100644 index 000000000..2894616bc --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/PersonnelSheetPopulator.java @@ -0,0 +1,131 @@ +/** + * 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.populator; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.organisation.office.data.OfficeData; +import org.apache.fineract.organisation.staff.data.StaffData; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +//import org.apache.commons.collections.CollectionUtils; + +public class PersonnelSheetPopulator extends AbstractWorkbookPopulator { + + private List personnel; + private List offices; + + // Maintaining the one to many relationship + private Map> officeToPersonnel; + + /* + * Guava Multimap would make this more readable. The value Integer[] contains the beginIndex and + * endIndex for the staff list of each office. Required for applying names in excel. + */ + private Map officeNameToBeginEndIndexesOfStaff; + + private static final int OFFICE_NAME_COL = 0; + private static final int STAFF_NAME_COL = 1; + private static final int STAFF_ID_COL = 2; + + public PersonnelSheetPopulator(List personnel, List offices) { + this.personnel = personnel; + this.offices = offices; + } + + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet staffSheet = workbook.createSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME); + setLayout(staffSheet); + + /* + * This piece of code could have been avoided by making multiple trips to the database for the + * staff of each office but this is more performance efficient + */ + setOfficeToPersonnelMap(); + + populateStaffByOfficeName(staffSheet); + staffSheet.protectSheet(""); + } + + + private void populateStaffByOfficeName(Sheet staffSheet) { + int rowIndex = 1, startIndex = 1, officeIndex = 0; + officeNameToBeginEndIndexesOfStaff = new HashMap<>(); + Row row = staffSheet.createRow(rowIndex); + for (OfficeData office : offices) { + startIndex = rowIndex + 1; + writeString(OFFICE_NAME_COL, row, office.name().trim().replaceAll("[ )(]", "_")); + + List staffList = + officeToPersonnel.get(office.name().trim().replaceAll("[ )(]", "_")); + + if (staffList!=null){ + if (!staffList.isEmpty()) { + for (StaffData staff : staffList) { + writeString(STAFF_NAME_COL, row, staff.getDisplayName()); + writeLong(STAFF_ID_COL, row, staff.getId()); + row = staffSheet.createRow(++rowIndex); + } + officeNameToBeginEndIndexesOfStaff.put(officeIndex++, new Integer[]{startIndex, rowIndex}); + } + }else + officeIndex++; + } + } + + private void setOfficeToPersonnelMap() { + officeToPersonnel = new HashMap<>(); + for (StaffData person : personnel) { + add(person.getOfficeName().trim().replaceAll("[ )(]", "_"), person); + } + } + + // Guava Multi-map can reduce this. + private void add(String key, StaffData value) { + List values = officeToPersonnel.get(key); + if (values == null) { + values = new ArrayList<>(); + } + values.add(value); + officeToPersonnel.put(key, values); + } + + private void setLayout(Sheet worksheet) { + for (Integer i = 0; i < 3; i++) + worksheet.setColumnWidth(i, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + writeString(OFFICE_NAME_COL, rowHeader, "Office Name"); + writeString(STAFF_NAME_COL, rowHeader, "Staff List"); + writeString(STAFF_ID_COL, rowHeader, "Staff ID"); + } + + public Map getOfficeNameToBeginEndIndexesOfStaff() { + return officeNameToBeginEndIndexesOfStaff; + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/RecurringDepositProductSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/RecurringDepositProductSheetPopulator.java new file mode 100644 index 000000000..32af96db5 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/RecurringDepositProductSheetPopulator.java @@ -0,0 +1,190 @@ +/** + * 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.populator; + + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.organisation.monetary.data.CurrencyData; +import org.apache.fineract.portfolio.savings.data.RecurringDepositProductData; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.util.List; + +public class RecurringDepositProductSheetPopulator extends AbstractWorkbookPopulator { + + private List products; + + private static final int ID_COL = 0; + private static final int NAME_COL = 1; + private static final int SHORT_NAME_COL = 2; + private static final int NOMINAL_ANNUAL_INTEREST_RATE_COL = 3; + private static final int INTEREST_COMPOUNDING_PERIOD_COL = 4; + private static final int INTEREST_POSTING_PERIOD_COL = 5; + private static final int INTEREST_CALCULATION_COL = 6; + private static final int INTEREST_CALCULATION_DAYS_IN_YEAR_COL = 7; + private static final int LOCKIN_PERIOD_COL = 8; + private static final int LOCKIN_PERIOD_FREQUENCY_COL = 9; + private static final int CURRENCY_COL = 10; + private static final int MIN_DEPOSIT_COL = 11; + private static final int MAX_DEPOSIT_COL = 12; + private static final int DEPOSIT_COL = 13; + private static final int MIN_DEPOSIT_TERM_COL = 14; + private static final int MIN_DEPOSIT_TERM_TYPE_COL = 15; + private static final int MAX_DEPOSIT_TERM_COL = 16; + private static final int MAX_DEPOSIT_TERM_TYPE_COL = 17; + private static final int PRECLOSURE_PENAL_APPLICABLE_COL = 18; + private static final int PRECLOSURE_PENAL_INTEREST_COL = 19; + private static final int PRECLOSURE_INTEREST_TYPE_COL = 20; + private static final int IN_MULTIPLES_OF_DEPOSIT_TERM_COL = 21; + private static final int IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL = 22; + private static final int IS_MANDATORY_DEPOSIT_COL = 23; + private static final int ALLOW_WITHDRAWAL_COL = 24; + private static final int ADJUST_ADVANCE_COL = 25; + + public RecurringDepositProductSheetPopulator(List recurringDepositProducts) { + this.products=recurringDepositProducts; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + int rowIndex = 1; + Sheet productSheet = workbook.createSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME); + setLayout(productSheet); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + for(RecurringDepositProductData product : products) { + Row row = productSheet.createRow(rowIndex++); + writeLong(ID_COL, row, product.getId()); + writeString(NAME_COL, row, product.getName().trim().replaceAll("[ )(]", "_")); + writeString(SHORT_NAME_COL, row, product.getShortName().trim().replaceAll("[ )(]", "_")); + writeBigDecimal(NOMINAL_ANNUAL_INTEREST_RATE_COL, row, product.getNominalAnnualInterestRate()); + writeString(INTEREST_COMPOUNDING_PERIOD_COL, row, product.getInterestCompoundingPeriodType().getValue()); + writeString(INTEREST_POSTING_PERIOD_COL, row, product.getInterestPostingPeriodType().getValue()); + writeString(INTEREST_CALCULATION_COL, row, product.getInterestCalculationType().getValue()); + writeString(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row, product.getInterestCalculationDaysInYearType().getValue()); + writeBoolean(PRECLOSURE_PENAL_APPLICABLE_COL, row, product.isPreClosurePenalApplicable()); + writeString(MIN_DEPOSIT_TERM_TYPE_COL, row, product.getMinDepositTermType().getValue()); + + if(product.getMinDepositAmount() != null) + writeBigDecimal(MIN_DEPOSIT_COL, row, product.getMinDepositAmount()); + if(product.getMaxDepositAmount() != null) + writeBigDecimal(MAX_DEPOSIT_COL, row, product.getMaxDepositAmount()); + if(product.getDepositAmount() != null) + writeBigDecimal(DEPOSIT_COL, row, product.getDepositAmount()); + if(product.getMaxDepositTerm() != null) + writeInt(MAX_DEPOSIT_TERM_COL, row, product.getMaxDepositTerm()); + + if(product.getMinDepositTerm() != null) + writeInt(MIN_DEPOSIT_TERM_COL, row, product.getMinDepositTerm()); + + + if(product.getInMultiplesOfDepositTerm() != null) + writeInt(IN_MULTIPLES_OF_DEPOSIT_TERM_COL, row, product.getInMultiplesOfDepositTerm()); + if(product.getPreClosurePenalInterest() != null) + writeBigDecimal(PRECLOSURE_PENAL_INTEREST_COL, row, product.getPreClosurePenalInterest()); + if(product.getMaxDepositTermType() != null) + writeString(MAX_DEPOSIT_TERM_TYPE_COL, row, product.getMaxDepositTermType().getValue()); + if(product.getPreClosurePenalInterestOnType() != null) + writeString(PRECLOSURE_INTEREST_TYPE_COL, row, product.getPreClosurePenalInterestOnType().getValue()); + if(product.getInMultiplesOfDepositTermType() != null) + writeString(IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL, row, product.getInMultiplesOfDepositTermType().getValue()); + writeBoolean(ALLOW_WITHDRAWAL_COL, row, product.isAllowWithdrawal()); + writeBoolean(ADJUST_ADVANCE_COL, row, product.isAdjustAdvanceTowardsFuturePayments()); + writeBoolean(IS_MANDATORY_DEPOSIT_COL, row, product.isMandatoryDeposit()); + if(product.getLockinPeriodFrequency() != null) + writeInt(LOCKIN_PERIOD_COL, row, product.getLockinPeriodFrequency()); + if(product.getLockinPeriodFrequencyType() != null) + writeString(LOCKIN_PERIOD_FREQUENCY_COL, row, product.getLockinPeriodFrequencyType().getValue()); + CurrencyData currency = product.getCurrency(); + writeString(CURRENCY_COL, row, currency.code()); + } + productSheet.protectSheet(""); + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(SHORT_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(NOMINAL_ANNUAL_INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_COMPOUNDING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_POSTING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_CALCULATION_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LOCKIN_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LOCKIN_PERIOD_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CURRENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MIN_DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MAX_DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MIN_DEPOSIT_TERM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MAX_DEPOSIT_TERM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MIN_DEPOSIT_TERM_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MAX_DEPOSIT_TERM_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(PRECLOSURE_PENAL_APPLICABLE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(PRECLOSURE_PENAL_INTEREST_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(PRECLOSURE_INTEREST_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(IN_MULTIPLES_OF_DEPOSIT_TERM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(IS_MANDATORY_DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ALLOW_WITHDRAWAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ADJUST_ADVANCE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + + writeString(ID_COL, rowHeader, "ID"); + writeString(NAME_COL, rowHeader, "Name"); + writeString(SHORT_NAME_COL, rowHeader, "Short Name"); + writeString(NOMINAL_ANNUAL_INTEREST_RATE_COL, rowHeader, "Interest"); + writeString(INTEREST_COMPOUNDING_PERIOD_COL, rowHeader, "Interest Compounding Period"); + writeString(INTEREST_POSTING_PERIOD_COL, rowHeader, "Interest Posting Period"); + writeString(INTEREST_CALCULATION_COL, rowHeader, "Interest Calculated Using"); + writeString(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, rowHeader, "# Days In Year"); + writeString(LOCKIN_PERIOD_COL, rowHeader, "Locked In For"); + writeString(LOCKIN_PERIOD_FREQUENCY_COL, rowHeader, "Frequency"); + writeString(CURRENCY_COL, rowHeader, "Currency"); + writeString(MIN_DEPOSIT_COL, rowHeader, "Min Deposit"); + writeString(MAX_DEPOSIT_COL, rowHeader, "Max Deposit"); + writeString(DEPOSIT_COL, rowHeader, "Deposit"); + writeString(MIN_DEPOSIT_TERM_COL, rowHeader, "Min Deposit Term"); + writeString(MAX_DEPOSIT_TERM_COL, rowHeader, "Max Deposit Term"); + writeString(MIN_DEPOSIT_TERM_TYPE_COL, rowHeader, "Min Deposit Term Type"); + writeString(MAX_DEPOSIT_TERM_TYPE_COL, rowHeader, "Max Deposit Term Type"); + writeString(PRECLOSURE_PENAL_APPLICABLE_COL, rowHeader, "Preclosure Penal Applicable"); + writeString(PRECLOSURE_PENAL_INTEREST_COL, rowHeader, "Penal Interest"); + writeString(PRECLOSURE_INTEREST_TYPE_COL, rowHeader, "Penal Interest Type"); + writeString(IN_MULTIPLES_OF_DEPOSIT_TERM_COL, rowHeader, "Multiples of Deposit Term"); + writeString(IN_MULTIPLES_OF_DEPOSIT_TERM_TYPE_COL, rowHeader, "Multiples of Deposit Term Type"); + writeString(IS_MANDATORY_DEPOSIT_COL, rowHeader, "Is Mandatory Deposit?"); + writeString(ALLOW_WITHDRAWAL_COL, rowHeader, "Allow Withdrawal?"); + writeString(ADJUST_ADVANCE_COL, rowHeader, "Adjust Advance Towards Future Payments?"); + } + + public List getProducts() { + return products; + } + + public Integer getProductsSize() { + return products.size(); + } + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/RoleSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/RoleSheetPopulator.java new file mode 100644 index 000000000..a7717f86f --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/RoleSheetPopulator.java @@ -0,0 +1,67 @@ +/** + * 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.populator; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.useradministration.data.RoleData; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.util.List; + +public class RoleSheetPopulator extends AbstractWorkbookPopulator { + private ListrolesList; + + private static final int ID_COL=0; + private static final int ROLE_NAME=1; + + public RoleSheetPopulator(List roles) { + this.rolesList=roles; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + int rowIndex = 1; + Sheet rolesSheet = workbook.createSheet(TemplatePopulateImportConstants.ROLES_SHEET_NAME); + setLayout(rolesSheet); + populateRoles(rolesSheet, rowIndex); + rolesSheet.protectSheet(""); + } + + private void populateRoles(Sheet rolesSheet, int rowIndex) { + for (RoleData role : rolesList) { + Row row = rolesSheet.createRow(rowIndex); + writeLong(ID_COL, row, role.getId()); + writeString(ROLE_NAME, row, role.getName().trim().replaceAll("[ )(]", "_")); + rowIndex++; + } + } + + private void setLayout(Sheet rolesSheet) { + rolesSheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + rolesSheet.setColumnWidth(ROLE_NAME, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + Row rowHeader = rolesSheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + writeString(ID_COL, rowHeader, "ID"); + writeString(ROLE_NAME, rowHeader, "Role Name"); + } + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SavingsAccountSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SavingsAccountSheetPopulator.java new file mode 100644 index 000000000..e2a9c77fb --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SavingsAccountSheetPopulator.java @@ -0,0 +1,84 @@ +/** + * 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.populator; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.portfolio.client.data.ClientData; +import org.apache.fineract.portfolio.savings.data.SavingsAccountData; +import org.apache.fineract.template.domain.Template; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.util.List; +import java.util.Map; + +public class SavingsAccountSheetPopulator extends AbstractWorkbookPopulator { + + private List savingsAccountDataList; + private Map> clientToSavingsMap; + + private static final int SAVINGS_ACCOUNT_ID_COL=0; + private static final int SAVING_ACCOUNT_NO=1; + private static final int CURRENCY_COL=2; + private static final int CLIENT_NAME=3; + + + public SavingsAccountSheetPopulator(List savingsAccountDataList) { + this.savingsAccountDataList=savingsAccountDataList; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet savingsSheet=workbook.createSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME); + setLayout(savingsSheet); + populateSavingsSheet(savingsSheet); + savingsSheet.protectSheet(""); + } + + private void populateSavingsSheet(Sheet savingsSheet) { + int rowIndex=1; + for (SavingsAccountData savings: savingsAccountDataList) { + Row row=savingsSheet.createRow(rowIndex++); + writeLong(SAVINGS_ACCOUNT_ID_COL,row,savings.id()); + writeString(SAVING_ACCOUNT_NO,row,savings.getAccountNo()); + writeString(CURRENCY_COL,row,savings.currency().code()); + writeString(CLIENT_NAME,row,savings.getClientName()); + } + } + + + private void setLayout(Sheet savingsSheet) { + Row rowHeader = savingsSheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + + savingsSheet.setColumnWidth(SAVINGS_ACCOUNT_ID_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + writeString(SAVINGS_ACCOUNT_ID_COL,rowHeader,"Savings Account Id"); + + savingsSheet.setColumnWidth(SAVING_ACCOUNT_NO,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + writeString(SAVING_ACCOUNT_NO,rowHeader,"Savings Account No"); + + savingsSheet.setColumnWidth(CURRENCY_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(CURRENCY_COL,rowHeader,"Currency Code"); + + savingsSheet.setColumnWidth(CLIENT_NAME,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(CLIENT_NAME,rowHeader,"Client Name"); + + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SavingsProductSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SavingsProductSheetPopulator.java new file mode 100644 index 000000000..2803a01a7 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SavingsProductSheetPopulator.java @@ -0,0 +1,136 @@ +/** + * 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.populator; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.organisation.monetary.data.CurrencyData; +import org.apache.fineract.portfolio.savings.data.SavingsProductData; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.util.List; + +public class SavingsProductSheetPopulator extends AbstractWorkbookPopulator { + private List savingsProducts; + + private static final int ID_COL = 0; + private static final int NAME_COL = 1; + private static final int NOMINAL_ANNUAL_INTEREST_RATE_COL = 2; + private static final int INTEREST_COMPOUNDING_PERIOD_COL = 3; + private static final int INTEREST_POSTING_PERIOD_COL = 4; + private static final int INTEREST_CALCULATION_COL = 5; + private static final int INTEREST_CALCULATION_DAYS_IN_YEAR_COL = 6; + private static final int MIN_OPENING_BALANCE_COL = 7; + private static final int LOCKIN_PERIOD_COL = 8; + private static final int LOCKIN_PERIOD_FREQUENCY_COL = 9; + private static final int CURRENCY_COL = 10; + private static final int DECIMAL_PLACES_COL = 11; + private static final int IN_MULTIPLES_OF_COL = 12; + private static final int WITHDRAWAL_FEE_COL = 13; + private static final int ALLOW_OVERDRAFT_COL = 14; + private static final int OVERDRAFT_LIMIT_COL = 15; + + public SavingsProductSheetPopulator(List savingsProducts) { + this.savingsProducts=savingsProducts; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + int rowIndex = 1; + Sheet productSheet = workbook.createSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME); + setLayout(productSheet); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + for(SavingsProductData product : savingsProducts) { + Row row = productSheet.createRow(rowIndex++); + writeLong(ID_COL, row, product.getId()); + writeString(NAME_COL, row, product.getName().trim().replaceAll("[ )(]", "_")); + writeBigDecimal(NOMINAL_ANNUAL_INTEREST_RATE_COL, row, product.getNominalAnnualInterestRate()); + writeString(INTEREST_COMPOUNDING_PERIOD_COL, row, product.getInterestCompoundingPeriodType().getValue()); + writeString(INTEREST_POSTING_PERIOD_COL, row, product.getInterestPostingPeriodType().getValue()); + writeString(INTEREST_CALCULATION_COL, row, product.getInterestCalculationType().getValue()); + writeString(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row, product.getInterestCalculationDaysInYearType().getValue()); + if(product.getMinRequiredOpeningBalance() != null) + writeBigDecimal(MIN_OPENING_BALANCE_COL, row, product.getMinRequiredOpeningBalance()); + if(product.getLockinPeriodFrequency() != null) + writeInt(LOCKIN_PERIOD_COL, row, product.getLockinPeriodFrequency()); + if(product.getLockinPeriodFrequencyType() != null) + writeString(LOCKIN_PERIOD_FREQUENCY_COL, row, product.getLockinPeriodFrequencyType().getValue()); + CurrencyData currency = product.getCurrency(); + writeString(CURRENCY_COL, row, currency.code()); + writeInt(DECIMAL_PLACES_COL, row, currency.decimalPlaces()); + if(currency.currencyInMultiplesOf() != null) + writeInt(IN_MULTIPLES_OF_COL, row, currency.currencyInMultiplesOf()); + writeBoolean(WITHDRAWAL_FEE_COL, row, product.isWithdrawalFeeForTransfers()); + writeBoolean(ALLOW_OVERDRAFT_COL, row,product.isAllowOverdraft()); + if(product.getOverdraftLimit() != null) + writeBigDecimal(OVERDRAFT_LIMIT_COL, row, product.getOverdraftLimit()); + } + productSheet.protectSheet(""); + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(NOMINAL_ANNUAL_INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_COMPOUNDING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_POSTING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_CALCULATION_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(MIN_OPENING_BALANCE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LOCKIN_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LOCKIN_PERIOD_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CURRENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(DECIMAL_PLACES_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(IN_MULTIPLES_OF_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(WITHDRAWAL_FEE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ALLOW_OVERDRAFT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(OVERDRAFT_LIMIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + + writeString(ID_COL, rowHeader, "ID"); + writeString(NAME_COL, rowHeader, "Name"); + writeString(NOMINAL_ANNUAL_INTEREST_RATE_COL, rowHeader, "Interest"); + writeString(INTEREST_COMPOUNDING_PERIOD_COL, rowHeader, "Interest Compounding Period"); + writeString(INTEREST_POSTING_PERIOD_COL, rowHeader, "Interest Posting Period"); + writeString(INTEREST_CALCULATION_COL, rowHeader, "Interest Calculated Using"); + writeString(INTEREST_CALCULATION_DAYS_IN_YEAR_COL, rowHeader, "# Days In Year"); + writeString(MIN_OPENING_BALANCE_COL, rowHeader, "Min Opening Balance"); + writeString(LOCKIN_PERIOD_COL, rowHeader, "Locked In For"); + writeString(LOCKIN_PERIOD_FREQUENCY_COL, rowHeader, "Frequency"); + writeString(CURRENCY_COL, rowHeader, "Currency"); + writeString(DECIMAL_PLACES_COL, rowHeader, "Decimal Places"); + writeString(IN_MULTIPLES_OF_COL, rowHeader, "In Multiples Of"); + writeString(WITHDRAWAL_FEE_COL, rowHeader, "Withdrawal Fee for Transfers?"); + writeString(ALLOW_OVERDRAFT_COL, rowHeader, "Apply Overdraft"); + writeString(OVERDRAFT_LIMIT_COL, rowHeader, "Overdraft Limit"); + } + + public List getProducts() { + return savingsProducts; + } + + public Integer getProductsSize() { + return savingsProducts.size(); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SharedProductsSheetPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SharedProductsSheetPopulator.java new file mode 100644 index 000000000..33fbd8fa1 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/SharedProductsSheetPopulator.java @@ -0,0 +1,159 @@ +/** + * 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.populator; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.core.service.DateUtils; +import org.apache.fineract.portfolio.charge.data.ChargeData; +import org.apache.fineract.portfolio.shareproducts.data.ShareProductData; +import org.apache.fineract.portfolio.shareproducts.data.ShareProductMarketPriceData; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import java.math.BigDecimal; +import java.util.*; + +public class SharedProductsSheetPopulator extends AbstractWorkbookPopulator { + private List sharedProductDataList; + private List chargesForSharedProducts; + private MapproductToBeginEndIndexesofCharges; + + private static final int PRODUCT_ID=0; + private static final int PRODUCT_NAME_COL = 1; + private static final int CURRENCY_COL = 2; + private static final int DECIMAL_PLACES_COL = 3; + private static final int TODAYS_PRICE_COL = 4; + private static final int CURRENCY_IN_MULTIPLES_COL = 5; + private static final int CHARGES_ID_1_COL = 7; + private static final int CHARGES_NAME_1_COL = 8; + private static final int CHARGES_ID_2_COL = 9; + private static final int CHARGES_NAME_2_COL = 10; + private static final int CHARGES_ID_3_COL = 11; + private static final int CHARGES_NAME_3_COL = 12; + + + + public SharedProductsSheetPopulator(List shareProductDataList,List chargesForShares) { + this.sharedProductDataList=shareProductDataList; + this.chargesForSharedProducts=chargesForShares; + + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet sharedProductsSheet=workbook.createSheet(TemplatePopulateImportConstants.SHARED_PRODUCTS_SHEET_NAME); + setLayout(sharedProductsSheet); + populateSheet(sharedProductsSheet); + sharedProductsSheet.protectSheet(""); + } + + private void populateSheet(Sheet sharedProductsSheet) { + int index = 0; + int startIndexCharges = 1; + int endIndexCharges = 0; + productToBeginEndIndexesofCharges = new HashMap<>(); + for (ShareProductData productData : sharedProductDataList) { + Row row = sharedProductsSheet.createRow(++index); + writeLong(PRODUCT_ID, row, productData.getId()); + writeString(PRODUCT_NAME_COL, row, productData.getName().replaceAll("[ ]", "_")); + writeString(CURRENCY_COL, row, productData.getCurrency().getName().replaceAll("[ ]", "_")); + writeInt(DECIMAL_PLACES_COL, row, productData.getCurrency().decimalPlaces()); + writeBigDecimal(TODAYS_PRICE_COL, row, deriveMarketPrice(productData)); + writeInt(CURRENCY_IN_MULTIPLES_COL,row,productData.getCurrency().currencyInMultiplesOf()); + if (chargesForSharedProducts != null) { + int chargeRowIndex=0; + for (ChargeData chargeData:chargesForSharedProducts) { + if (chargeData.getCurrency().getName().equals(productData.getCurrency().getName())) { + writeString(CHARGES_NAME_1_COL+chargeRowIndex, row, chargeData.getName()); + writeLong(CHARGES_ID_1_COL+chargeRowIndex, row, chargeData.getId()); + chargeRowIndex+=2; + endIndexCharges++; + } + } + productToBeginEndIndexesofCharges.put(productData.getId(), new Integer[]{startIndexCharges, endIndexCharges}); + startIndexCharges = endIndexCharges + 1; + } + } + } + private BigDecimal deriveMarketPrice(final ShareProductData shareProductData) { + BigDecimal marketValue = shareProductData.getUnitPrice(); + Collection marketDataSet = shareProductData.getMarketPrice(); + if (marketDataSet != null && !marketDataSet.isEmpty()) { + Date currentDate = DateUtils.getDateOfTenant(); + for (ShareProductMarketPriceData data : marketDataSet) { + Date futureDate = data.getStartDate(); + if (currentDate.after(futureDate)) { + marketValue = data.getShareValue(); + } + } + } + return marketValue; + } + + private void setLayout(Sheet workSheet) { + Row rowHeader=workSheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + + workSheet.setColumnWidth(PRODUCT_ID,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(PRODUCT_ID,rowHeader,"Product Id"); + + workSheet.setColumnWidth(PRODUCT_NAME_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + writeString(PRODUCT_NAME_COL,rowHeader,"Product Name"); + + workSheet.setColumnWidth(CURRENCY_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + writeString(CURRENCY_COL,rowHeader,"Currency"); + + workSheet.setColumnWidth(DECIMAL_PLACES_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(DECIMAL_PLACES_COL,rowHeader,"Decimal Places"); + + workSheet.setColumnWidth(TODAYS_PRICE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(TODAYS_PRICE_COL,rowHeader,"Today's Price"); + + workSheet.setColumnWidth(CURRENCY_IN_MULTIPLES_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(CURRENCY_IN_MULTIPLES_COL,rowHeader,"Currency in multiples of"); + + workSheet.setColumnWidth(CHARGES_NAME_1_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(CHARGES_NAME_1_COL,rowHeader,"Charges Name 1"); + + workSheet.setColumnWidth(CHARGES_ID_1_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(CHARGES_ID_1_COL,rowHeader,"Charges Id 1"); + + workSheet.setColumnWidth(CHARGES_NAME_2_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(CHARGES_NAME_2_COL,rowHeader,"Charges Name 2"); + + workSheet.setColumnWidth(CHARGES_ID_2_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(CHARGES_ID_2_COL,rowHeader,"Charges Id 2"); + + workSheet.setColumnWidth(CHARGES_NAME_3_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(CHARGES_NAME_3_COL,rowHeader,"Charges Name 3"); + + workSheet.setColumnWidth(CHARGES_ID_3_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(CHARGES_ID_3_COL,rowHeader,"Charges Id 3"); + + } + + public List getSharedProductDataList() { + return sharedProductDataList; + } + + public Map getProductToBeginEndIndexesofCharges() { + return productToBeginEndIndexesofCharges; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/WorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/WorkbookPopulator.java new file mode 100644 index 000000000..9ff2a1c17 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/WorkbookPopulator.java @@ -0,0 +1,27 @@ +/** + * 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.populator; + +import org.apache.poi.ss.usermodel.Workbook; + +public interface WorkbookPopulator { + + void populate(Workbook workbook,String dateFormat); + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/centers/CentersWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/centers/CentersWorkbookPopulator.java new file mode 100644 index 000000000..27248c620 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/centers/CentersWorkbookPopulator.java @@ -0,0 +1,235 @@ +/** + * 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.populator.centers; + +import org.apache.fineract.infrastructure.bulkimport.constants.CenterConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.GroupSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.OfficeSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.PersonnelSheetPopulator; +import org.apache.fineract.organisation.office.data.OfficeData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.List; + + +public class CentersWorkbookPopulator extends AbstractWorkbookPopulator { + + + private OfficeSheetPopulator officeSheetPopulator; + private PersonnelSheetPopulator personnelSheetPopulator; + private GroupSheetPopulator groupSheetPopulator; + + public CentersWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, + PersonnelSheetPopulator personnelSheetPopulator,GroupSheetPopulator groupSheetPopulator) { + this.officeSheetPopulator = officeSheetPopulator; + this.personnelSheetPopulator = personnelSheetPopulator; + this.groupSheetPopulator=groupSheetPopulator; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet centerSheet = workbook.createSheet(TemplatePopulateImportConstants.CENTER_SHEET_NAME); + personnelSheetPopulator.populate(workbook,dateFormat); + officeSheetPopulator.populate(workbook,dateFormat); + groupSheetPopulator.populate(workbook,dateFormat); + setLayout(centerSheet); + setLookupTable(centerSheet,dateFormat); + setRules(centerSheet,dateFormat); + } + + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(0); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(CenterConstants.CENTER_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.STAFF_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.EXTERNAL_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.ACTIVE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.ACTIVATION_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.SUBMITTED_ON_DATE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.MEETING_START_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.IS_REPEATING_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.INTERVAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.REPEATS_ON_DAY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.CENTER_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.FAILURE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.GROUP_NAMES_STARTING_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.LOOKUP_OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.LOOKUP_OFFICE_OPENING_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.LOOKUP_REPEAT_NORMAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.LOOKUP_REPEAT_MONTHLY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(CenterConstants.LOOKUP_IF_REPEAT_WEEKLY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + + writeString(CenterConstants.CENTER_NAME_COL, rowHeader, "Center Name*"); + writeString(CenterConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(CenterConstants.STAFF_NAME_COL, rowHeader, "Staff Name*"); + writeString(CenterConstants.EXTERNAL_ID_COL, rowHeader, "External ID"); + writeString(CenterConstants.ACTIVE_COL, rowHeader, "Active*"); + writeString(CenterConstants.ACTIVATION_DATE_COL, rowHeader, "Activation Date*"); + writeString(CenterConstants.SUBMITTED_ON_DATE_COL,rowHeader,"Submitted On Date"); + writeString(CenterConstants.MEETING_START_DATE_COL, rowHeader, "Meeting Start Date* (On or After)"); + writeString(CenterConstants.IS_REPEATING_COL, rowHeader, "Repeat*"); + writeString(CenterConstants.FREQUENCY_COL, rowHeader, "Frequency*"); + writeString(CenterConstants.INTERVAL_COL, rowHeader, "Interval*"); + writeString(CenterConstants.REPEATS_ON_DAY_COL, rowHeader, "Repeats On*"); + writeString(CenterConstants.GROUP_NAMES_STARTING_COL,rowHeader,"Group Names* (Enter in consecutive cells horizontally)"); + writeString(CenterConstants.LOOKUP_OFFICE_NAME_COL, rowHeader, "Office Name"); + writeString(CenterConstants.LOOKUP_OFFICE_OPENING_DATE_COL, rowHeader, "Opening Date"); + writeString(CenterConstants.LOOKUP_REPEAT_NORMAL_COL, rowHeader, "Repeat Normal Range"); + writeString(CenterConstants.LOOKUP_REPEAT_MONTHLY_COL, rowHeader, "Repeat Monthly Range"); + writeString(CenterConstants.LOOKUP_IF_REPEAT_WEEKLY_COL, rowHeader, "If Repeat Weekly Range"); + } + private void setLookupTable(Sheet centerSheet,String dateFormat) { + setOfficeDateLookupTable(centerSheet, officeSheetPopulator.getOffices(), CenterConstants.LOOKUP_OFFICE_NAME_COL,CenterConstants.LOOKUP_OFFICE_OPENING_DATE_COL,dateFormat); + int rowIndex; + for(rowIndex = 1; rowIndex <= 11; rowIndex++) { + Row row = centerSheet.getRow(rowIndex); + if(row == null) + row = centerSheet.createRow(rowIndex); + writeInt(CenterConstants.LOOKUP_REPEAT_MONTHLY_COL, row, rowIndex); + } + for(rowIndex = 1; rowIndex <= 3; rowIndex++) + writeInt(CenterConstants.LOOKUP_REPEAT_NORMAL_COL, centerSheet.getRow(rowIndex), rowIndex); + + String[] days = new String[]{ + TemplatePopulateImportConstants.MONDAY, + TemplatePopulateImportConstants.TUESDAY, + TemplatePopulateImportConstants.WEDNESDAY, + TemplatePopulateImportConstants.THURSDAY, + TemplatePopulateImportConstants.FRIDAY, + TemplatePopulateImportConstants.SATURDAY, + TemplatePopulateImportConstants.SUNDAY}; + + for(rowIndex = 1; rowIndex <= 7; rowIndex++) + writeString(CenterConstants.LOOKUP_IF_REPEAT_WEEKLY_COL, centerSheet.getRow(rowIndex), days[rowIndex-1]); + + } + private void setRules(Sheet worksheet,String dateFormat) { + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.OFFICE_NAME_COL,CenterConstants. OFFICE_NAME_COL); + CellRangeAddressList staffNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.STAFF_NAME_COL,CenterConstants. STAFF_NAME_COL); + CellRangeAddressList activationDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(),CenterConstants. ACTIVATION_DATE_COL,CenterConstants. ACTIVATION_DATE_COL); + CellRangeAddressList activeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.ACTIVE_COL, CenterConstants.ACTIVE_COL); + CellRangeAddressList submittedDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(),CenterConstants. SUBMITTED_ON_DATE_COL,CenterConstants.SUBMITTED_ON_DATE_COL); + CellRangeAddressList meetingStartDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.MEETING_START_DATE_COL,CenterConstants. MEETING_START_DATE_COL); + CellRangeAddressList isRepeatRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(),CenterConstants. IS_REPEATING_COL,CenterConstants. IS_REPEATING_COL); + CellRangeAddressList repeatsRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.FREQUENCY_COL, CenterConstants.FREQUENCY_COL); + CellRangeAddressList repeatsEveryRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.INTERVAL_COL,CenterConstants. INTERVAL_COL); + CellRangeAddressList repeatsOnRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), CenterConstants.REPEATS_ON_DAY_COL,CenterConstants. REPEATS_ON_DAY_COL); + + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet)worksheet); + List offices = officeSheetPopulator.getOffices(); + setNames(worksheet, offices); + + + DataValidationConstraint officeNameConstraint = validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint staffNameConstraint = validationHelper. + createFormulaListConstraint("INDIRECT(CONCATENATE(\"Staff_\",$B1))"); + DataValidationConstraint activationDateConstraint = validationHelper.createDateConstraint + (DataValidationConstraint.OperatorType.BETWEEN, "=VLOOKUP($B1,$IR$2:$IS" + (offices.size() + 1)+",2,FALSE)", + "=TODAY()", dateFormat); + DataValidationConstraint booleanConstraint = validationHelper.createExplicitListConstraint(new String[]{"True", "False"}); + DataValidationConstraint submittedOnDateConstraint = + validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.LESS_OR_EQUAL, + "=$F1", null,dateFormat); + DataValidationConstraint meetingStartDateConstraint = + validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.BETWEEN, + "=$F1", "=TODAY()", dateFormat); + DataValidationConstraint repeatsConstraint = + validationHelper.createExplicitListConstraint(new String[]{ + TemplatePopulateImportConstants.FREQUENCY_DAILY, + TemplatePopulateImportConstants.FREQUENCY_WEEKLY, + TemplatePopulateImportConstants.FREQUENCY_MONTHLY, + TemplatePopulateImportConstants.FREQUENCY_YEARLY}); + DataValidationConstraint repeatsEveryConstraint = validationHelper.createFormulaListConstraint("INDIRECT($J1)"); + DataValidationConstraint repeatsOnConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE($J1,\"_DAYS\"))"); + + + DataValidation officeValidation = validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation staffValidation = validationHelper.createValidation(staffNameConstraint, staffNameRange); + DataValidation activationDateValidation = validationHelper.createValidation(activationDateConstraint, activationDateRange); + DataValidation activeValidation = validationHelper.createValidation(booleanConstraint, activeRange); + DataValidation submittedOnValidation=validationHelper.createValidation(submittedOnDateConstraint,submittedDateRange); + DataValidation meetingStartDateValidation = validationHelper.createValidation(meetingStartDateConstraint, meetingStartDateRange); + DataValidation isRepeatValidation = validationHelper.createValidation(booleanConstraint, isRepeatRange); + DataValidation repeatsValidation = validationHelper.createValidation(repeatsConstraint, repeatsRange); + DataValidation repeatsEveryValidation = validationHelper.createValidation(repeatsEveryConstraint, repeatsEveryRange); + DataValidation repeatsOnValidation = validationHelper.createValidation(repeatsOnConstraint, repeatsOnRange); + + + worksheet.addValidationData(activeValidation); + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(staffValidation); + worksheet.addValidationData(activationDateValidation); + worksheet.addValidationData(submittedOnValidation); + worksheet.addValidationData(meetingStartDateValidation); + worksheet.addValidationData(isRepeatValidation); + worksheet.addValidationData(repeatsValidation); + worksheet.addValidationData(repeatsEveryValidation); + worksheet.addValidationData(repeatsOnValidation); + } + + private void setNames(Sheet worksheet, List offices) { + Workbook centerWorkbook = worksheet.getWorkbook(); + Name officeCenter = centerWorkbook.createName(); + officeCenter.setNameName("Office"); + officeCenter.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME +"!$B$2:$B$" + (offices.size() + 1)); + + + //Repeat constraint names + Name repeatsDaily = centerWorkbook.createName(); + repeatsDaily.setNameName("Daily"); + repeatsDaily.setRefersToFormula(TemplatePopulateImportConstants.CENTER_SHEET_NAME+"!$IT$2:$IT$4"); + Name repeatsWeekly = centerWorkbook.createName(); + repeatsWeekly.setNameName("Weekly"); + repeatsWeekly.setRefersToFormula(TemplatePopulateImportConstants.CENTER_SHEET_NAME+"!$IT$2:$IT$4"); + Name repeatYearly = centerWorkbook.createName(); + repeatYearly.setNameName("Yearly"); + repeatYearly.setRefersToFormula(TemplatePopulateImportConstants.CENTER_SHEET_NAME+"!$IT$2:$IT$4"); + Name repeatsMonthly = centerWorkbook.createName(); + repeatsMonthly.setNameName("Monthly"); + repeatsMonthly.setRefersToFormula(TemplatePopulateImportConstants.CENTER_SHEET_NAME+"!$IU$2:$IU$12"); + Name repeatsOnWeekly = centerWorkbook.createName(); + repeatsOnWeekly.setNameName("Weekly_Days"); + repeatsOnWeekly.setRefersToFormula(TemplatePopulateImportConstants.CENTER_SHEET_NAME+"!$IV$2:$IV$8"); + + + //Staff Names for each office + for(Integer i = 0; i < offices.size(); i++) { + Integer[] officeNameToBeginEndIndexesOfStaff = personnelSheetPopulator.getOfficeNameToBeginEndIndexesOfStaff().get(i); + Name loanOfficerName = centerWorkbook.createName(); + if(officeNameToBeginEndIndexesOfStaff != null) { + loanOfficerName.setNameName("Staff_" + offices.get(i).name().trim().replaceAll("[ )(]", "_")); + loanOfficerName.setRefersToFormula(TemplatePopulateImportConstants.STAFF_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfStaff[0] + ":$B$" + officeNameToBeginEndIndexesOfStaff[1]); + } + } + + } + + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/chartofaccounts/ChartOfAccountsWorkbook.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/chartofaccounts/ChartOfAccountsWorkbook.java new file mode 100644 index 000000000..f65be136c --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/chartofaccounts/ChartOfAccountsWorkbook.java @@ -0,0 +1,236 @@ +/** + * 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.populator.chartofaccounts; + +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.infrastructure.bulkimport.constants.ChartOfAcountsConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ChartOfAccountsWorkbook extends AbstractWorkbookPopulator { + private List glAccounts; + private Map> accountTypeToAccountNameAndTag; + private MapaccountTypeToBeginEndIndexesofAccountNames; + private List accountTypesNoDuplicatesList; + + + public ChartOfAccountsWorkbook(List glAccounts) { + this.glAccounts = glAccounts; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet chartOfAccountsSheet=workbook.createSheet(TemplatePopulateImportConstants.CHART_OF_ACCOUNTS_SHEET_NAME); + setLayout(chartOfAccountsSheet); + setAccountTypeToAccountNameAndTag(); + setLookupTable(chartOfAccountsSheet); + setRules(chartOfAccountsSheet); + setDefaults(chartOfAccountsSheet); + } + + private void setAccountTypeToAccountNameAndTag() { + accountTypeToAccountNameAndTag=new HashMap<>(); + for (GLAccountData glAccount: glAccounts) { + addToaccountTypeToAccountNameMap(glAccount.getType().getValue(),glAccount.getName()+ + "-"+glAccount.getId()+"-"+glAccount.getTagId().getName()+"-"+glAccount.getTagId().getId()); + } + } + + private void addToaccountTypeToAccountNameMap(String key, String value) { + List values=accountTypeToAccountNameAndTag.get(key); + if (values==null){ + values=new ArrayList(); + } + if (!values.contains(value)){ + values.add(value); + accountTypeToAccountNameAndTag.put(key,values); + } + } + + private void setRules(Sheet chartOfAccountsSheet) { + CellRangeAddressList accountTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + ChartOfAcountsConstants. ACCOUNT_TYPE_COL,ChartOfAcountsConstants.ACCOUNT_TYPE_COL); + CellRangeAddressList accountUsageRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + ChartOfAcountsConstants.ACCOUNT_USAGE_COL,ChartOfAcountsConstants.ACCOUNT_USAGE_COL); + CellRangeAddressList manualEntriesAllowedRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + ChartOfAcountsConstants.MANUAL_ENTRIES_ALLOWED_COL,ChartOfAcountsConstants.MANUAL_ENTRIES_ALLOWED_COL); + CellRangeAddressList parentRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + ChartOfAcountsConstants.PARENT_COL,ChartOfAcountsConstants.PARENT_COL); + CellRangeAddressList tagRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + ChartOfAcountsConstants.TAG_COL,ChartOfAcountsConstants.TAG_COL); + + DataValidationHelper validationHelper=new HSSFDataValidationHelper((HSSFSheet) chartOfAccountsSheet); + setNames(chartOfAccountsSheet, accountTypesNoDuplicatesList); + + DataValidationConstraint accountTypeConstraint=validationHelper. + createExplicitListConstraint(new String[]{ + GLAccountType.ASSET.toString(), + GLAccountType.LIABILITY.toString(), + GLAccountType.EQUITY.toString(), + GLAccountType.INCOME.toString(), + GLAccountType.EXPENSE.toString()}); + DataValidationConstraint accountUsageConstraint=validationHelper. + createExplicitListConstraint(new String[]{ + GLAccountUsage.DETAIL.toString(), + GLAccountUsage.HEADER.toString()}); + DataValidationConstraint booleanConstraint=validationHelper. + createExplicitListConstraint(new String[]{"True","False"}); + DataValidationConstraint parentConstraint=validationHelper. + createFormulaListConstraint("INDIRECT(CONCATENATE(\"AccountName_\",$A1))"); + DataValidationConstraint tagConstraint=validationHelper. + createFormulaListConstraint("INDIRECT(CONCATENATE(\"Tags_\",$A1))"); + + 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); + + chartOfAccountsSheet.addValidationData(accountTypeValidation); + chartOfAccountsSheet.addValidationData(accountUsageValidation); + chartOfAccountsSheet.addValidationData(manualEntriesValidation); + chartOfAccountsSheet.addValidationData(parentValidation); + chartOfAccountsSheet.addValidationData(tagValidation); + } + + private void setNames(Sheet chartOfAccountsSheet,List accountTypesNoDuplicatesList) { + Workbook chartOfAccountsWorkbook=chartOfAccountsSheet.getWorkbook(); + for (Integer i=0;i(); + for (int i = 0; i (); + for (String accountType: accountTypesNoDuplicatesList) { + startIndex=rowIndex+1; + Row row =chartOfAccountsSheet.createRow(rowIndex); + writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_TYPE_COL,row,accountType); + List accountNamesandTags =accountTypeToAccountNameAndTag.get(accountType); + if (!accountNamesandTags.isEmpty()){ + for (String accountNameandTag:accountNamesandTags) { + if (chartOfAccountsSheet.getRow(rowIndex)!=null){ + String accountNameAndTagAr[]=accountNameandTag.split("-"); + writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_NAME_COL,row,accountNameAndTagAr[0]); + writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_ID_COL,row,accountNameAndTagAr[1]); + writeString(ChartOfAcountsConstants.LOOKUP_TAG_COL,row,accountNameAndTagAr[2]); + writeString(ChartOfAcountsConstants.LOOKUP_TAG_ID_COL,row,accountNameAndTagAr[3]); + rowIndex++; + }else{ + row =chartOfAccountsSheet.createRow(rowIndex); + String accountNameAndTagAr[]=accountNameandTag.split("-"); + writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_NAME_COL,row,accountNameAndTagAr[0]); + writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_ID_COL,row,accountNameAndTagAr[1]); + writeString(ChartOfAcountsConstants.LOOKUP_TAG_COL,row,accountNameAndTagAr[2]); + writeString(ChartOfAcountsConstants.LOOKUP_TAG_ID_COL,row,accountNameAndTagAr[3]); + rowIndex++; + } + } + accountTypeToBeginEndIndexesofAccountNames.put(accountTypeIndex++,new Integer[]{startIndex,rowIndex}); + }else { + accountTypeIndex++; + } + } + } + + private void setLayout(Sheet chartOfAccountsSheet) { + Row rowHeader=chartOfAccountsSheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.ACCOUNT_TYPE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.ACCOUNT_NAME_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.ACCOUNT_USAGE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.MANUAL_ENTRIES_ALLOWED_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.PARENT_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.PARENT_ID_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.GL_CODE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.TAG_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.TAG_ID_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.DESCRIPTION_COL,TemplatePopulateImportConstants.EXTRALARGE_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.LOOKUP_ACCOUNT_TYPE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.LOOKUP_ACCOUNT_NAME_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.LOOKUP_ACCOUNT_ID_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.LOOKUP_TAG_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + chartOfAccountsSheet.setColumnWidth(ChartOfAcountsConstants.LOOKUP_TAG_ID_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + + writeString(ChartOfAcountsConstants.ACCOUNT_TYPE_COL,rowHeader,"Account Type*"); + writeString(ChartOfAcountsConstants.GL_CODE_COL,rowHeader,"GL Code *"); + writeString(ChartOfAcountsConstants.ACCOUNT_USAGE_COL,rowHeader,"Account Usage *"); + writeString(ChartOfAcountsConstants.MANUAL_ENTRIES_ALLOWED_COL,rowHeader,"Manual entries allowed *"); + writeString(ChartOfAcountsConstants.PARENT_COL,rowHeader,"Parent"); + writeString(ChartOfAcountsConstants.PARENT_ID_COL,rowHeader,"Parent Id"); + writeString(ChartOfAcountsConstants.ACCOUNT_NAME_COL,rowHeader,"Account Name"); + writeString(ChartOfAcountsConstants.TAG_COL,rowHeader,"Tag *"); + writeString(ChartOfAcountsConstants.TAG_ID_COL,rowHeader,"Tag Id"); + writeString(ChartOfAcountsConstants.DESCRIPTION_COL,rowHeader,"Description *"); + writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_TYPE_COL,rowHeader,"Lookup Account type"); + writeString(ChartOfAcountsConstants.LOOKUP_TAG_COL,rowHeader,"Lookup Tag"); + writeString(ChartOfAcountsConstants.LOOKUP_TAG_ID_COL,rowHeader,"Lookup Tag Id"); + writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_NAME_COL,rowHeader,"Lookup Account name *"); + writeString(ChartOfAcountsConstants.LOOKUP_ACCOUNT_ID_COL,rowHeader,"Lookup Account Id"); + + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/client/ClientEntityWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/client/ClientEntityWorkbookPopulator.java new file mode 100644 index 000000000..9907985b3 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/client/ClientEntityWorkbookPopulator.java @@ -0,0 +1,405 @@ +/** + * 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.populator.client; + +import org.apache.fineract.infrastructure.bulkimport.constants.ClientEntityConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.OfficeSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.PersonnelSheetPopulator; +import org.apache.fineract.infrastructure.codes.data.CodeValueData; +import org.apache.fineract.organisation.office.data.OfficeData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.List; + +public class ClientEntityWorkbookPopulator extends AbstractWorkbookPopulator { + + private OfficeSheetPopulator officeSheetPopulator; + private PersonnelSheetPopulator personnelSheetPopulator; + private List clientTypeCodeValues; + private List constitutionCodeValues; + private List clientClassificationCodeValues; + private List addressTypesCodeValues; + private List stateProvinceCodeValues; + private List countryCodeValues; + private List mainBusinesslineCodeValues; + + + public ClientEntityWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, + PersonnelSheetPopulator personnelSheetPopulator,ListclientTypeCodeValues, + ListconstitutionCodeValues,ListmainBusinessline , + ListclientClassification,ListaddressTypesCodeValues, + ListstateProvinceCodeValues,ListcountryCodeValues ) { + this.officeSheetPopulator = officeSheetPopulator; + this.personnelSheetPopulator = personnelSheetPopulator; + this.clientTypeCodeValues=clientTypeCodeValues; + this.constitutionCodeValues=constitutionCodeValues; + this.clientClassificationCodeValues=clientClassification; + this.addressTypesCodeValues=addressTypesCodeValues; + this.stateProvinceCodeValues=stateProvinceCodeValues; + this.countryCodeValues=countryCodeValues; + this.mainBusinesslineCodeValues=mainBusinessline; + } + + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet clientSheet = workbook.createSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME); + personnelSheetPopulator.populate(workbook,dateFormat); + officeSheetPopulator.populate(workbook,dateFormat); + setLayout(clientSheet); + setOfficeDateLookupTable(clientSheet, officeSheetPopulator.getOffices(), + ClientEntityConstants.RELATIONAL_OFFICE_NAME_COL, ClientEntityConstants.RELATIONAL_OFFICE_OPENING_DATE_COL,dateFormat); + setClientDataLookupTable(clientSheet); + setRules(clientSheet,dateFormat); + } + + private void setClientDataLookupTable(Sheet clientSheet) { + int rowIndex=0; + for (CodeValueData clientTypeCodeValue:clientTypeCodeValues) { + Row row =clientSheet.getRow(++rowIndex); + if(row==null) + row=clientSheet.createRow(rowIndex); + writeString(ClientEntityConstants.LOOKUP_CLIENT_TYPES,row,clientTypeCodeValue.getName()+"-"+clientTypeCodeValue.getId()); + } + rowIndex=0; + for (CodeValueData clientClassificationCodeValue:clientClassificationCodeValues) { + Row row =clientSheet.getRow(++rowIndex); + if(row==null) + row=clientSheet.createRow(rowIndex); + writeString(ClientEntityConstants.LOOKUP_CLIENT_CLASSIFICATION,row, + clientClassificationCodeValue.getName()+"-"+clientClassificationCodeValue.getId()); + } + rowIndex=0; + for (CodeValueData constitutionCodeValue:constitutionCodeValues) { + Row row =clientSheet.getRow(++rowIndex); + if(row==null) + row=clientSheet.createRow(rowIndex); + writeString(ClientEntityConstants.LOOKUP_CONSTITUTION_COL,row, + constitutionCodeValue.getName()+"-"+constitutionCodeValue.getId()); + } + rowIndex=0; + for (CodeValueData mainBusinessCodeValue:mainBusinesslineCodeValues) { + Row row =clientSheet.getRow(++rowIndex); + if(row==null) + row=clientSheet.createRow(rowIndex); + writeString(ClientEntityConstants.LOOKUP_MAIN_BUSINESS_LINE,row, + mainBusinessCodeValue.getName()+"-"+mainBusinessCodeValue.getId()); + } + rowIndex=0; + for (CodeValueData addressTypeCodeValue:addressTypesCodeValues) { + Row row =clientSheet.getRow(++rowIndex); + if(row==null) + row=clientSheet.createRow(rowIndex); + writeString(ClientEntityConstants.LOOKUP_ADDRESS_TYPE,row, + addressTypeCodeValue.getName()+"-"+addressTypeCodeValue.getId()); + } + rowIndex=0; + for (CodeValueData stateCodeValue:stateProvinceCodeValues) { + Row row =clientSheet.getRow(++rowIndex); + if(row==null) + row=clientSheet.createRow(rowIndex); + writeString(ClientEntityConstants.LOOKUP_STATE_PROVINCE,row, + stateCodeValue.getName()+"-"+stateCodeValue.getId()); + } + rowIndex=0; + for (CodeValueData countryCodeValue: countryCodeValues) { + Row row =clientSheet.getRow(++rowIndex); + if(row==null) + row=clientSheet.createRow(rowIndex); + writeString(ClientEntityConstants.LOOKUP_COUNTRY,row, + countryCodeValue.getName()+"-"+countryCodeValue.getId()); + } + + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(ClientEntityConstants.NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + writeString(ClientEntityConstants.NAME_COL, rowHeader, "Name*"); + worksheet.setColumnWidth(ClientEntityConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.STAFF_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.INCOPORATION_DATE_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.INCOPORATION_VALID_TILL_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.MOBILE_NO_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.CLIENT_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.CLIENT_CLASSIFICATION_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.INCOPORATION_NUMBER_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.MAIN_BUSINESS_LINE,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.CONSTITUTION_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.REMARKS_COL,TemplatePopulateImportConstants.LARGE_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.EXTERNAL_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.SUBMITTED_ON_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.ACTIVE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.ACTIVATION_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.ADDRESS_ENABLED,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.ADDRESS_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.STREET_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.ADDRESS_LINE_1_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.ADDRESS_LINE_2_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.ADDRESS_LINE_3_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.CITY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.STATE_PROVINCE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.COUNTRY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.POSTAL_CODE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.IS_ACTIVE_ADDRESS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.WARNING_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + + worksheet.setColumnWidth(ClientEntityConstants.RELATIONAL_OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.RELATIONAL_OFFICE_OPENING_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_CONSTITUTION_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_CLIENT_TYPES,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_CLIENT_CLASSIFICATION,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_ADDRESS_TYPE,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_STATE_PROVINCE,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_COUNTRY,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientEntityConstants.LOOKUP_MAIN_BUSINESS_LINE,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + writeString(ClientEntityConstants.NAME_COL,rowHeader,"Name"); + writeString(ClientEntityConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(ClientEntityConstants.STAFF_NAME_COL, rowHeader, "Staff Name"); + writeString(ClientEntityConstants.INCOPORATION_DATE_COL,rowHeader,"Incorporation Date"); + writeString(ClientEntityConstants.INCOPORATION_VALID_TILL_COL,rowHeader,"Incorporation Validity Till Date"); + writeString(ClientEntityConstants.MOBILE_NO_COL, rowHeader, "Mobile number"); + writeString(ClientEntityConstants.CLIENT_TYPE_COL, rowHeader, "Client Type "); + writeString(ClientEntityConstants.CLIENT_CLASSIFICATION_COL, rowHeader, "Client Classification "); + writeString(ClientEntityConstants.INCOPORATION_NUMBER_COL,rowHeader,"Incorporation Number"); + writeString(ClientEntityConstants.MAIN_BUSINESS_LINE,rowHeader,"Main Business Line"); + writeString(ClientEntityConstants.CONSTITUTION_COL,rowHeader,"Constitution"); + writeString(ClientEntityConstants.REMARKS_COL,rowHeader,"Remarks"); + writeString(ClientEntityConstants.EXTERNAL_ID_COL, rowHeader, "External ID "); + writeString(ClientEntityConstants.SUBMITTED_ON_COL,rowHeader,"Submitted On Date"); + writeString(ClientEntityConstants.ACTIVE_COL, rowHeader, "Active*"); + writeString(ClientEntityConstants.ACTIVATION_DATE_COL, rowHeader, "Activation Date "); + writeString(ClientEntityConstants.ADDRESS_ENABLED,rowHeader,"Address Enabled "); + writeString(ClientEntityConstants.ADDRESS_TYPE_COL, rowHeader, "Address Type "); + writeString(ClientEntityConstants.STREET_COL, rowHeader, "Street "); + writeString(ClientEntityConstants.ADDRESS_LINE_1_COL, rowHeader, "Address Line 1"); + writeString(ClientEntityConstants.ADDRESS_LINE_2_COL, rowHeader, "Address Line 2"); + writeString(ClientEntityConstants.ADDRESS_LINE_3_COL, rowHeader, "Address Line 3"); + writeString(ClientEntityConstants.CITY_COL, rowHeader, "City"); + writeString(ClientEntityConstants.STATE_PROVINCE_COL, rowHeader, "State/ Province"); + writeString(ClientEntityConstants.COUNTRY_COL, rowHeader, "Country"); + writeString(ClientEntityConstants.POSTAL_CODE_COL, rowHeader, "Postal Code"); + writeString(ClientEntityConstants.IS_ACTIVE_ADDRESS_COL, rowHeader, "Is active Address ? "); + writeString(ClientEntityConstants.WARNING_COL, rowHeader, "All * marked fields are compulsory."); + + writeString(ClientEntityConstants.RELATIONAL_OFFICE_NAME_COL, rowHeader, "Lookup office Name "); + writeString(ClientEntityConstants.RELATIONAL_OFFICE_OPENING_DATE_COL, rowHeader, "Lookup Office Opened Date "); + writeString(ClientEntityConstants.LOOKUP_CONSTITUTION_COL, rowHeader, "Lookup Constitution "); + writeString(ClientEntityConstants.LOOKUP_CLIENT_TYPES, rowHeader, "Lookup Client Types "); + writeString(ClientEntityConstants.LOOKUP_CLIENT_CLASSIFICATION, rowHeader, "Lookup Client Classification "); + writeString(ClientEntityConstants.LOOKUP_ADDRESS_TYPE, rowHeader, "Lookup AddressType "); + writeString(ClientEntityConstants.LOOKUP_STATE_PROVINCE, rowHeader, "Lookup State/Province "); + writeString(ClientEntityConstants.LOOKUP_COUNTRY, rowHeader, "Lookup Country "); + writeString(ClientEntityConstants.LOOKUP_MAIN_BUSINESS_LINE,rowHeader,"Lookup Business Line"); + + + } + + private void setRules(Sheet worksheet,String dateFormat) { + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.OFFICE_NAME_COL, + ClientEntityConstants.OFFICE_NAME_COL); + CellRangeAddressList staffNameRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.STAFF_NAME_COL, ClientEntityConstants.STAFF_NAME_COL); + CellRangeAddressList submittedOnDateRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.SUBMITTED_ON_COL,ClientEntityConstants. SUBMITTED_ON_COL); + CellRangeAddressList dateRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientEntityConstants. ACTIVATION_DATE_COL,ClientEntityConstants. ACTIVATION_DATE_COL); + CellRangeAddressList activeRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientEntityConstants. ACTIVE_COL,ClientEntityConstants. ACTIVE_COL); + CellRangeAddressList clientTypeRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientEntityConstants. CLIENT_TYPE_COL,ClientEntityConstants. CLIENT_TYPE_COL); + CellRangeAddressList constitutionRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.CONSTITUTION_COL,ClientEntityConstants. CONSTITUTION_COL); + CellRangeAddressList mainBusinessLineRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientEntityConstants. MAIN_BUSINESS_LINE,ClientEntityConstants. MAIN_BUSINESS_LINE); + CellRangeAddressList clientClassificationRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.CLIENT_CLASSIFICATION_COL, + ClientEntityConstants.CLIENT_CLASSIFICATION_COL); + CellRangeAddressList enabledAddressRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.ADDRESS_ENABLED, ClientEntityConstants.ADDRESS_ENABLED); + CellRangeAddressList addressTypeRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.ADDRESS_TYPE_COL,ClientEntityConstants. ADDRESS_TYPE_COL); + CellRangeAddressList stateProvinceRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.STATE_PROVINCE_COL,ClientEntityConstants. STATE_PROVINCE_COL); + CellRangeAddressList countryRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientEntityConstants. COUNTRY_COL,ClientEntityConstants. COUNTRY_COL); + CellRangeAddressList activeAddressRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientEntityConstants. IS_ACTIVE_ADDRESS_COL,ClientEntityConstants. IS_ACTIVE_ADDRESS_COL); + CellRangeAddressList incorporateDateRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.INCOPORATION_DATE_COL,ClientEntityConstants.INCOPORATION_DATE_COL); + CellRangeAddressList incorporateDateTillRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientEntityConstants.INCOPORATION_VALID_TILL_COL, + ClientEntityConstants.INCOPORATION_VALID_TILL_COL); + + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet) worksheet); + + List offices = officeSheetPopulator.getOffices(); + setNames(worksheet, offices); + + DataValidationConstraint officeNameConstraint = + validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint staffNameConstraint = + validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Staff_\",$B1))"); + DataValidationConstraint submittedOnDateConstraint = + validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.LESS_OR_EQUAL, + "=$O1" ,null, dateFormat); + DataValidationConstraint activationDateConstraint = + validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.BETWEEN, + "=VLOOKUP($B1,$AJ$2:$AK" + (offices.size() + 1) + ",2,FALSE)", "=TODAY()", dateFormat); + DataValidationConstraint activeConstraint = + validationHelper.createExplicitListConstraint(new String[] {"True", "False"}); + DataValidationConstraint clientTypesConstraint = + validationHelper.createFormulaListConstraint("ClientTypes"); + DataValidationConstraint constitutionConstraint = + validationHelper.createFormulaListConstraint("Constitution"); + DataValidationConstraint mainBusinessLineConstraint = + validationHelper.createFormulaListConstraint("MainBusinessLine"); + DataValidationConstraint clientClassificationConstraint = + validationHelper.createFormulaListConstraint("ClientClassification"); + DataValidationConstraint enabledAddressConstraint = + validationHelper.createExplicitListConstraint(new String[] {"True", "False"}); + DataValidationConstraint addressTypeConstraint = + validationHelper.createFormulaListConstraint("AddressType"); + DataValidationConstraint stateProvinceConstraint = + validationHelper.createFormulaListConstraint("StateProvince"); + DataValidationConstraint countryConstraint = + validationHelper.createFormulaListConstraint("Country"); + DataValidationConstraint activeAddressConstraint = + validationHelper.createExplicitListConstraint(new String[] {"True", "False"}); + DataValidationConstraint incorpDateConstraint= + validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.LESS_OR_EQUAL, + "=TODAY()",null,dateFormat); + DataValidationConstraint incorpDateTillConstraint= + validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.GREATER_OR_EQUAL, + "=TODAY()",null,dateFormat); + + + DataValidation officeValidation = + validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation staffValidation = + validationHelper.createValidation(staffNameConstraint, staffNameRange); + DataValidation submittedOnDateValidation = + validationHelper.createValidation(submittedOnDateConstraint, submittedOnDateRange); + DataValidation activationDateValidation = + validationHelper.createValidation(activationDateConstraint, dateRange); + DataValidation activeValidation = + validationHelper.createValidation(activeConstraint, activeRange); + DataValidation clientTypeValidation = + validationHelper.createValidation(clientTypesConstraint, clientTypeRange); + DataValidation constitutionValidation = + validationHelper.createValidation(constitutionConstraint,constitutionRange); + DataValidation mainBusinessLineValidation = + validationHelper.createValidation(mainBusinessLineConstraint,mainBusinessLineRange); + DataValidation clientClassificationValidation = + validationHelper.createValidation(clientClassificationConstraint, clientClassificationRange); + DataValidation enabledAddressValidation= + validationHelper.createValidation(enabledAddressConstraint,enabledAddressRange); + DataValidation addressTypeValidation = + validationHelper.createValidation(addressTypeConstraint, addressTypeRange); + DataValidation stateProvinceValidation = + validationHelper.createValidation(stateProvinceConstraint, stateProvinceRange); + DataValidation countryValidation = + validationHelper.createValidation(countryConstraint, countryRange); + DataValidation activeAddressValidation = + validationHelper.createValidation(activeAddressConstraint,activeAddressRange); + DataValidation incorporateDateValidation=validationHelper.createValidation(incorpDateConstraint,incorporateDateRange); + DataValidation incorporateDateTillValidation=validationHelper.createValidation(incorpDateTillConstraint,incorporateDateTillRange); + + worksheet.addValidationData(activeValidation); + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(staffValidation); + worksheet.addValidationData(activationDateValidation); + worksheet.addValidationData(submittedOnDateValidation); + worksheet.addValidationData(clientTypeValidation); + worksheet.addValidationData(constitutionValidation); + worksheet.addValidationData(mainBusinessLineValidation); + worksheet.addValidationData(clientClassificationValidation); + worksheet.addValidationData(enabledAddressValidation); + worksheet.addValidationData(addressTypeValidation); + worksheet.addValidationData(stateProvinceValidation); + worksheet.addValidationData(countryValidation); + worksheet.addValidationData(activeAddressValidation); + worksheet.addValidationData(incorporateDateValidation); + worksheet.addValidationData(incorporateDateTillValidation); + } + + private void setNames(Sheet worksheet, List offices) { + Workbook clientWorkbook = worksheet.getWorkbook(); + Name officeGroup = clientWorkbook.createName(); + officeGroup.setNameName("Office"); + officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (offices.size() + 1)); + + Name clientTypeGroup = clientWorkbook.createName(); + clientTypeGroup.setNameName("ClientTypes"); + clientTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+"!$AN$2:$AN$" + + (clientTypeCodeValues.size() + 1)); + + Name constitutionGroup = clientWorkbook.createName(); + constitutionGroup.setNameName("Constitution"); + constitutionGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+"!$AL$2:$AL$" + + (constitutionCodeValues.size() + 1)); + + Name mainBusinessLineGroup = clientWorkbook.createName(); + mainBusinessLineGroup.setNameName("MainBusinessLine"); + mainBusinessLineGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+"!$AR$2:$AR$" + + (mainBusinesslineCodeValues.size() + 1)); + + Name clientClassficationGroup = clientWorkbook.createName(); + clientClassficationGroup.setNameName("ClientClassification"); + clientClassficationGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+"!$AM$2:$AM$" + + (clientClassificationCodeValues.size() + 1)); + + Name addressTypeGroup = clientWorkbook.createName(); + addressTypeGroup.setNameName("AddressType"); + addressTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+ + "!$AO$2:$AO$" + (addressTypesCodeValues.size() + 1)); + + Name stateProvinceGroup = clientWorkbook.createName(); + stateProvinceGroup.setNameName("StateProvince"); + stateProvinceGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+ + "!$AP$2:$AP$" + (stateProvinceCodeValues.size() + 1)); + + Name countryGroup = clientWorkbook.createName(); + countryGroup.setNameName("Country"); + countryGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME+"!$AQ$2:$AQ$" + + (countryCodeValues.size() + 1)); + + for (Integer i = 0; i < offices.size(); i++) { + Integer[] officeNameToBeginEndIndexesOfStaff = + personnelSheetPopulator.getOfficeNameToBeginEndIndexesOfStaff().get(i); + if (officeNameToBeginEndIndexesOfStaff != null) { + Name name = clientWorkbook.createName(); + name.setNameName("Staff_" + offices.get(i).name().trim().replaceAll("[ )(]", "_")); + name.setRefersToFormula(TemplatePopulateImportConstants.STAFF_SHEET_NAME+"!$B$" + + officeNameToBeginEndIndexesOfStaff[0] + ":$B$" + + officeNameToBeginEndIndexesOfStaff[1]); + } + } + } + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/client/ClientPersonWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/client/ClientPersonWorkbookPopulator.java new file mode 100644 index 000000000..69d11192a --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/client/ClientPersonWorkbookPopulator.java @@ -0,0 +1,370 @@ +/** + * 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.populator.client; + +import org.apache.fineract.infrastructure.bulkimport.constants.ClientPersonConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.OfficeSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.PersonnelSheetPopulator; +import org.apache.fineract.infrastructure.codes.data.CodeValueData; +import org.apache.fineract.organisation.office.data.OfficeData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.List; + +public class ClientPersonWorkbookPopulator extends AbstractWorkbookPopulator { + + private OfficeSheetPopulator officeSheetPopulator; + private PersonnelSheetPopulator personnelSheetPopulator; + private ListclientTypeCodeValues; + private ListgenderCodeValues; + private ListclientClassificationCodeValues; + private ListaddressTypesCodeValues; + private ListstateProvinceCodeValues; + private ListcountryCodeValues; + + + public ClientPersonWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, + PersonnelSheetPopulator personnelSheetPopulator,ListclientTypeCodeValues, + ListgenderCodeValues, ListclientClassification,ListaddressTypesCodeValues, + ListstateProvinceCodeValues,ListcountryCodeValues ) { + this.officeSheetPopulator = officeSheetPopulator; + this.personnelSheetPopulator = personnelSheetPopulator; + this.clientTypeCodeValues=clientTypeCodeValues; + this.genderCodeValues=genderCodeValues; + this.clientClassificationCodeValues=clientClassification; + this.addressTypesCodeValues=addressTypesCodeValues; + this.stateProvinceCodeValues=stateProvinceCodeValues; + this.countryCodeValues=countryCodeValues; + } + + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet clientSheet = workbook.createSheet(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME); + personnelSheetPopulator.populate(workbook,dateFormat); + officeSheetPopulator.populate(workbook,dateFormat); + setLayout(clientSheet); + setOfficeDateLookupTable(clientSheet, officeSheetPopulator.getOffices(), + ClientPersonConstants.RELATIONAL_OFFICE_NAME_COL, ClientPersonConstants.RELATIONAL_OFFICE_OPENING_DATE_COL,dateFormat); + setClientDataLookupTable(clientSheet); + setRules(clientSheet,dateFormat); + } + + private void setClientDataLookupTable(Sheet clientSheet) { + int rowIndex=0; + for (CodeValueData clientTypeCodeValue:clientTypeCodeValues) { + Row row =clientSheet.getRow(++rowIndex); + if(row==null) + row=clientSheet.createRow(rowIndex); + writeString(ClientPersonConstants.LOOKUP_CLIENT_TYPES_COL,row,clientTypeCodeValue.getName()+ + "-"+clientTypeCodeValue.getId()); + } + rowIndex=0; + for (CodeValueData clientClassificationCodeValue:clientClassificationCodeValues) { + Row row =clientSheet.getRow(++rowIndex); + if(row==null) + row=clientSheet.createRow(rowIndex); + writeString(ClientPersonConstants.LOOKUP_CLIENT_CLASSIFICATION_COL,row, + clientClassificationCodeValue.getName()+"-"+clientClassificationCodeValue.getId()); + } + rowIndex=0; + for (CodeValueData genderCodeValue:genderCodeValues) { + Row row =clientSheet.getRow(++rowIndex); + if(row==null) + row=clientSheet.createRow(rowIndex); + writeString(ClientPersonConstants.LOOKUP_GENDER_COL,row,genderCodeValue.getName()+"-"+genderCodeValue.getId()); + } + rowIndex=0; + for (CodeValueData addressTypeCodeValue:addressTypesCodeValues) { + Row row =clientSheet.getRow(++rowIndex); + if(row==null) + row=clientSheet.createRow(rowIndex); + writeString(ClientPersonConstants.LOOKUP_ADDRESS_TYPE_COL,row, + addressTypeCodeValue.getName()+"-"+addressTypeCodeValue.getId()); + } + rowIndex=0; + for (CodeValueData stateCodeValue:stateProvinceCodeValues) { + Row row =clientSheet.getRow(++rowIndex); + if(row==null) + row=clientSheet.createRow(rowIndex); + writeString(ClientPersonConstants.LOOKUP_STATE_PROVINCE_COL,row,stateCodeValue.getName()+"-"+stateCodeValue.getId()); + } + rowIndex=0; + for (CodeValueData countryCodeValue: countryCodeValues) { + Row row =clientSheet.getRow(++rowIndex); + if(row==null) + row=clientSheet.createRow(rowIndex); + writeString(ClientPersonConstants.LOOKUP_COUNTRY_COL,row,countryCodeValue.getName()+"-"+countryCodeValue.getId()); + } + + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(ClientPersonConstants.FIRST_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.LAST_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.MIDDLE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + writeString(ClientPersonConstants.FIRST_NAME_COL, rowHeader, "First Name*"); + writeString(ClientPersonConstants.LAST_NAME_COL, rowHeader, "Last Name*"); + writeString(ClientPersonConstants.MIDDLE_NAME_COL, rowHeader, "Middle Name"); + worksheet.setColumnWidth(ClientPersonConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.STAFF_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.EXTERNAL_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.SUBMITTED_ON_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.ACTIVATION_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.ACTIVE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.MOBILE_NO_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.DOB_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.CLIENT_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.GENDER_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.CLIENT_CLASSIFICATION_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.IS_STAFF_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.ADDRESS_ENABLED_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.ADDRESS_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.STREET_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.ADDRESS_LINE_1_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.ADDRESS_LINE_2_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.ADDRESS_LINE_3_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.CITY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.STATE_PROVINCE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.COUNTRY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.POSTAL_CODE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.IS_ACTIVE_ADDRESS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.WARNING_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + + worksheet.setColumnWidth(ClientPersonConstants.RELATIONAL_OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.RELATIONAL_OFFICE_OPENING_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.LOOKUP_GENDER_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.LOOKUP_CLIENT_TYPES_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.LOOKUP_CLIENT_CLASSIFICATION_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.LOOKUP_ADDRESS_TYPE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.LOOKUP_STATE_PROVINCE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(ClientPersonConstants.LOOKUP_COUNTRY_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(ClientPersonConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(ClientPersonConstants.STAFF_NAME_COL, rowHeader, "Staff Name"); + writeString(ClientPersonConstants.EXTERNAL_ID_COL, rowHeader, "External ID "); + writeString(ClientPersonConstants.SUBMITTED_ON_COL,rowHeader,"Submitted On Date"); + writeString(ClientPersonConstants.ACTIVATION_DATE_COL, rowHeader, "Activation date"); + writeString(ClientPersonConstants.ACTIVE_COL, rowHeader, "Active*"); + writeString(ClientPersonConstants.MOBILE_NO_COL, rowHeader, "Mobile number"); + writeString(ClientPersonConstants.DOB_COL, rowHeader, "Date of Birth "); + writeString(ClientPersonConstants.CLIENT_TYPE_COL, rowHeader, "Client Type "); + writeString(ClientPersonConstants.IS_STAFF_COL, rowHeader, "Is a staff memeber "); + writeString(ClientPersonConstants.GENDER_COL, rowHeader, "Gender "); + writeString(ClientPersonConstants.ADDRESS_ENABLED_COL,rowHeader,"Address Enabled *"); + writeString(ClientPersonConstants.CLIENT_CLASSIFICATION_COL, rowHeader, "Client Classification "); + writeString(ClientPersonConstants.ADDRESS_TYPE_COL, rowHeader, "Address Type "); + writeString(ClientPersonConstants.STREET_COL, rowHeader, "Street "); + writeString(ClientPersonConstants.ADDRESS_LINE_1_COL, rowHeader, "Address Line 1"); + writeString(ClientPersonConstants.ADDRESS_LINE_2_COL, rowHeader, "Address Line 2"); + writeString(ClientPersonConstants.ADDRESS_LINE_3_COL, rowHeader, "Address Line 3 "); + writeString(ClientPersonConstants.CITY_COL, rowHeader, "City "); + writeString(ClientPersonConstants.STATE_PROVINCE_COL, rowHeader, "State/ Province "); + writeString(ClientPersonConstants.COUNTRY_COL, rowHeader, "Country "); + writeString(ClientPersonConstants.POSTAL_CODE_COL, rowHeader, "Postal Code "); + writeString(ClientPersonConstants.IS_ACTIVE_ADDRESS_COL, rowHeader, "Is active Address ? "); + writeString(ClientPersonConstants.WARNING_COL, rowHeader, "All * marked fields are compulsory."); + + writeString(ClientPersonConstants.RELATIONAL_OFFICE_NAME_COL, rowHeader, "Lookup office Name "); + writeString(ClientPersonConstants.RELATIONAL_OFFICE_OPENING_DATE_COL, rowHeader, "Lookup Office Opened Date "); + writeString(ClientPersonConstants.LOOKUP_GENDER_COL, rowHeader, "Lookup Gender "); + writeString(ClientPersonConstants.LOOKUP_CLIENT_TYPES_COL, rowHeader, "Lookup Client Types "); + writeString(ClientPersonConstants.LOOKUP_CLIENT_CLASSIFICATION_COL, rowHeader, "Lookup Client Classification "); + writeString(ClientPersonConstants.LOOKUP_ADDRESS_TYPE_COL, rowHeader, "Lookup AddressType "); + writeString(ClientPersonConstants.LOOKUP_STATE_PROVINCE_COL, rowHeader, "Lookup State/Province "); + writeString(ClientPersonConstants.LOOKUP_COUNTRY_COL, rowHeader, "Lookup Country "); + + + } + + private void setRules(Sheet worksheet,String dateformat) { + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.OFFICE_NAME_COL, ClientPersonConstants.OFFICE_NAME_COL); + CellRangeAddressList staffNameRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. STAFF_NAME_COL,ClientPersonConstants. STAFF_NAME_COL); + CellRangeAddressList submittedOnDateRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. SUBMITTED_ON_COL, ClientPersonConstants.SUBMITTED_ON_COL); + CellRangeAddressList activationDateRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.ACTIVATION_DATE_COL, ClientPersonConstants.ACTIVATION_DATE_COL); + CellRangeAddressList activeRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.ACTIVE_COL,ClientPersonConstants. ACTIVE_COL); + CellRangeAddressList clientTypeRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. CLIENT_TYPE_COL,ClientPersonConstants. CLIENT_TYPE_COL); + CellRangeAddressList dobRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. DOB_COL,ClientPersonConstants. DOB_COL); + CellRangeAddressList isStaffRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. IS_STAFF_COL,ClientPersonConstants. IS_STAFF_COL); + CellRangeAddressList genderRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.GENDER_COL,ClientPersonConstants. GENDER_COL); + CellRangeAddressList clientClassificationRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.CLIENT_CLASSIFICATION_COL, ClientPersonConstants.CLIENT_CLASSIFICATION_COL); + CellRangeAddressList enabledAddressRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.ADDRESS_ENABLED_COL, ClientPersonConstants.ADDRESS_ENABLED_COL); + CellRangeAddressList addressTypeRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. ADDRESS_TYPE_COL, ClientPersonConstants.ADDRESS_TYPE_COL); + CellRangeAddressList stateProvinceRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. STATE_PROVINCE_COL, ClientPersonConstants.STATE_PROVINCE_COL); + CellRangeAddressList countryRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), ClientPersonConstants.COUNTRY_COL, ClientPersonConstants.COUNTRY_COL); + CellRangeAddressList activeAddressRange=new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),ClientPersonConstants. IS_ACTIVE_ADDRESS_COL,ClientPersonConstants. IS_ACTIVE_ADDRESS_COL); + + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet) worksheet); + + List offices = officeSheetPopulator.getOffices(); + setNames(worksheet, offices); + + DataValidationConstraint officeNameConstraint = + validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint staffNameConstraint = + validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Staff_\",$D1))"); + DataValidationConstraint submittedOnDateConstraint = + validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.LESS_OR_EQUAL, + "=$I1" ,null,dateformat); + DataValidationConstraint activationDateConstraint = + validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.BETWEEN, + "=VLOOKUP($D1,$AJ$2:$AK" + (offices.size() + 1) + ",2,FALSE)", "=TODAY()", dateformat); + DataValidationConstraint dobDateConstraint = + validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.LESS_OR_EQUAL, + "=TODAY()",null, dateformat); + DataValidationConstraint activeConstraint = + validationHelper.createExplicitListConstraint(new String[] {"True", "False"}); + DataValidationConstraint clientTypesConstraint = + validationHelper.createFormulaListConstraint("ClientTypes"); + DataValidationConstraint isStaffConstraint = + validationHelper.createExplicitListConstraint(new String[] {"True", "False"}); + DataValidationConstraint genderConstraint = + validationHelper.createFormulaListConstraint("Gender"); + DataValidationConstraint clientClassificationConstraint = + validationHelper.createFormulaListConstraint("ClientClassification"); + DataValidationConstraint enabledAddressConstraint = + validationHelper.createExplicitListConstraint(new String[] {"True", "False"}); + DataValidationConstraint addressTypeConstraint = + validationHelper.createFormulaListConstraint("AddressType"); + DataValidationConstraint stateProvinceConstraint = + validationHelper.createFormulaListConstraint("StateProvince"); + DataValidationConstraint countryConstraint = + validationHelper.createFormulaListConstraint("Country"); + DataValidationConstraint activeAddressConstraint = + validationHelper.createExplicitListConstraint(new String[] {"True", "False"}); + + DataValidation officeValidation = + validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation staffValidation = + validationHelper.createValidation(staffNameConstraint, staffNameRange); + DataValidation submittedOnDateValidation = + validationHelper.createValidation(submittedOnDateConstraint, submittedOnDateRange); + DataValidation activationDateValidation = + validationHelper.createValidation(activationDateConstraint, activationDateRange); + DataValidation dobDateValidation = + validationHelper.createValidation(dobDateConstraint, dobRange); + DataValidation activeValidation = + validationHelper.createValidation(activeConstraint, activeRange); + DataValidation clientTypeValidation = + validationHelper.createValidation(clientTypesConstraint, clientTypeRange); + DataValidation isStaffValidation = + validationHelper.createValidation(isStaffConstraint, isStaffRange); + DataValidation genderValidation = + validationHelper.createValidation(genderConstraint, genderRange); + DataValidation clientClassificationValidation = + validationHelper.createValidation(clientClassificationConstraint, clientClassificationRange); + DataValidation enabledAddressValidation= + validationHelper.createValidation(enabledAddressConstraint,enabledAddressRange); + DataValidation addressTypeValidation = + validationHelper.createValidation(addressTypeConstraint, addressTypeRange); + DataValidation stateProvinceValidation = + validationHelper.createValidation(stateProvinceConstraint, stateProvinceRange); + DataValidation countryValidation = + validationHelper.createValidation(countryConstraint, countryRange); + DataValidation activeAddressValidation = + validationHelper.createValidation(activeAddressConstraint,activeAddressRange); + + worksheet.addValidationData(activeValidation); + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(staffValidation); + worksheet.addValidationData(activationDateValidation); + worksheet.addValidationData(submittedOnDateValidation); + worksheet.addValidationData(dobDateValidation); + worksheet.addValidationData(clientTypeValidation); + worksheet.addValidationData(isStaffValidation); + worksheet.addValidationData(genderValidation); + worksheet.addValidationData(clientClassificationValidation); + worksheet.addValidationData(enabledAddressValidation); + worksheet.addValidationData(addressTypeValidation); + worksheet.addValidationData(stateProvinceValidation); + worksheet.addValidationData(countryValidation); + worksheet.addValidationData(activeAddressValidation); + } + + private void setNames(Sheet worksheet, List offices) { + Workbook clientWorkbook = worksheet.getWorkbook(); + Name officeGroup = clientWorkbook.createName(); + officeGroup.setNameName("Office"); + officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (offices.size() + 1)); + + Name clientTypeGroup = clientWorkbook.createName(); + clientTypeGroup.setNameName("ClientTypes"); + clientTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME+"!$AN$2:$AN$" + + (clientTypeCodeValues.size() + 1)); + + Name genderGroup = clientWorkbook.createName(); + genderGroup.setNameName("Gender"); + genderGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME+"!$AL$2:$AL$" + (genderCodeValues.size() + 1)); + + Name clientClassficationGroup = clientWorkbook.createName(); + clientClassficationGroup.setNameName("ClientClassification"); + clientClassficationGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME+"!$AM$2:$AM$" + + (clientClassificationCodeValues.size() + 1)); + + Name addressTypeGroup = clientWorkbook.createName(); + addressTypeGroup.setNameName("AddressType"); + addressTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME+"!$AO$2:$AO$" + + (addressTypesCodeValues.size() + 1)); + + Name stateProvinceGroup = clientWorkbook.createName(); + stateProvinceGroup.setNameName("StateProvince"); + stateProvinceGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME+"!$AP$2:$AP$" + + (stateProvinceCodeValues.size() + 1)); + + Name countryGroup = clientWorkbook.createName(); + countryGroup.setNameName("Country"); + countryGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_PERSON_SHEET_NAME+"!$AQ$2:$AQ$" + + (countryCodeValues.size() + 1)); + + for (Integer i = 0; i < offices.size(); i++) { + Integer[] officeNameToBeginEndIndexesOfStaff = + personnelSheetPopulator.getOfficeNameToBeginEndIndexesOfStaff().get(i); + if (officeNameToBeginEndIndexesOfStaff != null) { + Name name = clientWorkbook.createName(); + name.setNameName("Staff_" + offices.get(i).name().trim().replaceAll("[ )(]", "_")); + name.setRefersToFormula(TemplatePopulateImportConstants.STAFF_SHEET_NAME+"!$B$" + + officeNameToBeginEndIndexesOfStaff[0] + ":$B$" + officeNameToBeginEndIndexesOfStaff[1]); + } + } + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/comparator/LoanComparatorByStatusActive.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/comparator/LoanComparatorByStatusActive.java new file mode 100644 index 000000000..9a8157469 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/comparator/LoanComparatorByStatusActive.java @@ -0,0 +1,52 @@ +/** + * 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.populator.comparator; + +import org.apache.fineract.portfolio.loanaccount.data.LoanAccountData; + +import java.util.Comparator; + +/** + * Sorting the loan values based on loan status giving priority to active loans + * */ + +public class LoanComparatorByStatusActive implements Comparator { + + @Override + public int compare(LoanAccountData o1, LoanAccountData o2) { + + boolean isData1StatusActive = o1.getStatusStringValue().equals("Active"); + boolean isData2StatusActive = o2.getStatusStringValue().equals("Active"); + + // if both status active, these have the same rank + if (isData1StatusActive && isData2StatusActive){ + return 0; + } + + if (isData1StatusActive){ + return -1; + } + + if (isData2StatusActive){ + return 1; + } + // if no status active, these have the same rank + return 0; + } +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/fixeddeposits/FixedDepositTransactionWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/fixeddeposits/FixedDepositTransactionWorkbookPopulator.java new file mode 100644 index 000000000..cd7dd9bd2 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/fixeddeposits/FixedDepositTransactionWorkbookPopulator.java @@ -0,0 +1,235 @@ +/** + * 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.populator.fixeddeposits; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TransactionConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.*; +import org.apache.fineract.portfolio.savings.data.SavingsAccountData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; + +public class FixedDepositTransactionWorkbookPopulator extends AbstractWorkbookPopulator { + private OfficeSheetPopulator officeSheetPopulator; + private ClientSheetPopulator clientSheetPopulator; + private ExtrasSheetPopulator extrasSheetPopulator; + + private ListsavingsAccounts; + + public FixedDepositTransactionWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, + ClientSheetPopulator clientSheetPopulator, ExtrasSheetPopulator extrasSheetPopulator, + List savingsAccounts) { + this.officeSheetPopulator = officeSheetPopulator; + this.clientSheetPopulator = clientSheetPopulator; + this.extrasSheetPopulator = extrasSheetPopulator; + this.savingsAccounts=savingsAccounts; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet savingsTransactionSheet = workbook.createSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_TRANSACTION_SHEET_NAME); + setLayout(savingsTransactionSheet); + officeSheetPopulator.populate(workbook,dateFormat); + clientSheetPopulator.populate(workbook,dateFormat); + extrasSheetPopulator.populate(workbook,dateFormat); + populateSavingsTable(savingsTransactionSheet,dateFormat); + setRules(savingsTransactionSheet,dateFormat); + setDefaults(savingsTransactionSheet); + } + + private void setDefaults(Sheet worksheet) { + for(Integer rowNo = 1; rowNo < 3000; rowNo++) + { + Row row = worksheet.getRow(rowNo); + if(row == null) + row = worksheet.createRow(rowNo); + writeFormula(TransactionConstants.PRODUCT_COL, row, "IF(ISERROR(VLOOKUP($C"+ (rowNo+1) +",$Q$2:$S$" + (savingsAccounts.size() + 1) + ",2,FALSE)),\"\",VLOOKUP($C"+ (rowNo+1) +",$Q$2:$S$" + (savingsAccounts.size() + 1) + ",2,FALSE))"); + writeFormula(TransactionConstants.OPENING_BALANCE_COL, row, "IF(ISERROR(VLOOKUP($C"+ (rowNo+1) +",$Q$2:$S$" + (savingsAccounts.size() + 1) + ",3,FALSE)),\"\",VLOOKUP($C"+ (rowNo+1) +",$Q$2:$S$" + (savingsAccounts.size() + 1) + ",3,FALSE))"); + } + } + + + private void setRules(Sheet worksheet,String dateFormat) { + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.OFFICE_NAME_COL, TransactionConstants.OFFICE_NAME_COL); + CellRangeAddressList clientNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.CLIENT_NAME_COL, TransactionConstants.CLIENT_NAME_COL); + CellRangeAddressList accountNumberRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.SAVINGS_ACCOUNT_NO_COL, TransactionConstants.SAVINGS_ACCOUNT_NO_COL); + CellRangeAddressList transactionTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.TRANSACTION_TYPE_COL, TransactionConstants.TRANSACTION_TYPE_COL); + CellRangeAddressList paymentTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.PAYMENT_TYPE_COL, TransactionConstants.PAYMENT_TYPE_COL); + CellRangeAddressList transactionDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.TRANSACTION_DATE_COL, TransactionConstants.TRANSACTION_DATE_COL); + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet)worksheet); + + setNames(worksheet); + + DataValidationConstraint officeNameConstraint = validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint clientNameConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Client_\",$A1))"); + DataValidationConstraint accountNumberConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Account_\",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($B1,\" \",\"_\"),\"(\",\"_\"),\")\",\"_\")))"); + DataValidationConstraint transactionTypeConstraint = validationHelper.createExplicitListConstraint(new String[] {"Withdrawal","Deposit"}); + DataValidationConstraint paymentTypeConstraint = validationHelper.createFormulaListConstraint("PaymentTypes"); + DataValidationConstraint transactionDateConstraint = validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.BETWEEN, "=VLOOKUP($C1,$Q$2:$T$" + (savingsAccounts.size() + 1) + ",4,FALSE)", "=TODAY()", dateFormat); + + DataValidation officeValidation = validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation clientValidation = validationHelper.createValidation(clientNameConstraint, clientNameRange); + DataValidation accountNumberValidation = validationHelper.createValidation(accountNumberConstraint, accountNumberRange); + DataValidation transactionTypeValidation = validationHelper.createValidation(transactionTypeConstraint, transactionTypeRange); + DataValidation paymentTypeValidation = validationHelper.createValidation(paymentTypeConstraint, paymentTypeRange); + DataValidation transactionDateValidation = validationHelper.createValidation(transactionDateConstraint, transactionDateRange); + + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(clientValidation); + worksheet.addValidationData(accountNumberValidation); + worksheet.addValidationData(transactionTypeValidation); + worksheet.addValidationData(paymentTypeValidation); + worksheet.addValidationData(transactionDateValidation); + } + + private void setNames(Sheet worksheet) { + Workbook savingsTransactionWorkbook = worksheet.getWorkbook(); + List officeNames = officeSheetPopulator.getOfficeNames(); + + //Office Names + Name officeGroup = savingsTransactionWorkbook.createName(); + officeGroup.setNameName("Office"); + officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (officeNames.size() + 1)); + + //Clients Named after Offices + for(Integer i = 0; i < officeNames.size(); i++) { + Integer[] officeNameToBeginEndIndexesOfClients = clientSheetPopulator.getOfficeNameToBeginEndIndexesOfClients().get(i); + Name name = savingsTransactionWorkbook.createName(); + if(officeNameToBeginEndIndexesOfClients != null) { + name.setNameName("Client_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + name.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfClients[0] + ":$B$" + officeNameToBeginEndIndexesOfClients[1]); + } + } + + //Counting clients with active savings and starting and end addresses of cells for naming + HashMap clientNameToBeginEndIndexes = new HashMap<>(); + ArrayList clientsWithActiveSavings = new ArrayList<>(); + ArrayList clientIdsWithActiveSavings = new ArrayList<>(); + int startIndex = 1, endIndex = 1; + String clientName = ""; + Long clientId = null; + for(int i = 0; i < savingsAccounts.size(); i++){ + if(!clientName.equals(savingsAccounts.get(i).getClientName())) { + endIndex = i + 1; + clientNameToBeginEndIndexes.put(clientName, new Integer[]{startIndex, endIndex}); + startIndex = i + 2; + clientName = savingsAccounts.get(i).getClientName(); + clientId = savingsAccounts.get(i).getClientId(); + clientsWithActiveSavings.add(clientName); + clientIdsWithActiveSavings.add(clientId); + } + if(i == savingsAccounts.size()-1) { + endIndex = i + 2; + clientNameToBeginEndIndexes.put(clientName, new Integer[]{startIndex, endIndex}); + } + } + + //Account Number Named after Clients + for(int j = 0; j < clientsWithActiveSavings.size(); j++) { + Name name = savingsTransactionWorkbook.createName(); + name.setNameName("Account_" + clientsWithActiveSavings.get(j).replaceAll(" ", "_") + "_" + clientIdsWithActiveSavings.get(j) + "_"); + name.setRefersToFormula(TemplatePopulateImportConstants.FIXED_DEPOSIT_TRANSACTION_SHEET_NAME+"!$Q$" + clientNameToBeginEndIndexes.get(clientsWithActiveSavings.get(j))[0] + ":$Q$" + clientNameToBeginEndIndexes.get(clientsWithActiveSavings.get(j))[1]); + } + + //Payment Type Name + Name paymentTypeGroup = savingsTransactionWorkbook.createName(); + paymentTypeGroup.setNameName("PaymentTypes"); + paymentTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME+"!$D$2:$D$" + (extrasSheetPopulator.getPaymentTypesSize() + 1)); + } + + private void populateSavingsTable(Sheet savingsTransactionSheet,String dateFormat) { + Workbook workbook = savingsTransactionSheet.getWorkbook(); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + int rowIndex = 1; + Row row; + Collections.sort(savingsAccounts, SavingsAccountData.ClientNameComparator); + for(SavingsAccountData savingsAccount : savingsAccounts) { + row = savingsTransactionSheet.createRow(rowIndex++); + writeString(TransactionConstants.LOOKUP_CLIENT_NAME_COL, row, savingsAccount.getClientName() + "(" + savingsAccount.getClientId() + ")"); + writeLong(TransactionConstants.LOOKUP_ACCOUNT_NO_COL, row, Long.parseLong(savingsAccount.getAccountNo())); + writeString(TransactionConstants.LOOKUP_PRODUCT_COL, row, savingsAccount.getSavingsProductName()); + if(savingsAccount.getMinRequiredOpeningBalance() != null) + writeBigDecimal(TransactionConstants.LOOKUP_OPENING_BALANCE_COL, row, savingsAccount.getMinRequiredOpeningBalance()); + writeDate(TransactionConstants.LOOKUP_SAVINGS_ACTIVATION_DATE_COL, row,"" + + savingsAccount.getTimeline().getActivatedOnDate().getDayOfMonth() + "/" + + savingsAccount.getTimeline().getActivatedOnDate().getMonthOfYear() + "/" + + savingsAccount.getTimeline().getActivatedOnDate().getYear() , dateCellStyle,dateFormat); + } + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(TransactionConstants.OFFICE_NAME_COL, 4000); + worksheet.setColumnWidth(TransactionConstants.CLIENT_NAME_COL, 5000); + worksheet.setColumnWidth(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.PRODUCT_COL, 4000); + worksheet.setColumnWidth(TransactionConstants.OPENING_BALANCE_COL, 4000); + worksheet.setColumnWidth(TransactionConstants.TRANSACTION_TYPE_COL, 3300); + worksheet.setColumnWidth(TransactionConstants.AMOUNT_COL, 4000); + worksheet.setColumnWidth(TransactionConstants.TRANSACTION_DATE_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.PAYMENT_TYPE_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.ACCOUNT_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.CHECK_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.RECEIPT_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.ROUTING_CODE_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.BANK_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_CLIENT_NAME_COL, 5000); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_ACCOUNT_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_PRODUCT_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_OPENING_BALANCE_COL, 3700); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_SAVINGS_ACTIVATION_DATE_COL, 3500); + writeString(TransactionConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(TransactionConstants.CLIENT_NAME_COL, rowHeader, "Client Name*"); + writeString(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, rowHeader, "Account No.*"); + writeString(TransactionConstants.PRODUCT_COL, rowHeader, "Product Name"); + writeString(TransactionConstants.OPENING_BALANCE_COL, rowHeader, "Opening Balance"); + writeString(TransactionConstants.TRANSACTION_TYPE_COL, rowHeader, "Transaction Type*"); + writeString(TransactionConstants.AMOUNT_COL, rowHeader, "Amount*"); + writeString(TransactionConstants.TRANSACTION_DATE_COL, rowHeader, "Date*"); + writeString(TransactionConstants.PAYMENT_TYPE_COL, rowHeader, "Type*"); + writeString(TransactionConstants.ACCOUNT_NO_COL, rowHeader, "Account No"); + writeString(TransactionConstants.CHECK_NO_COL, rowHeader, "Check No"); + writeString(TransactionConstants.RECEIPT_NO_COL, rowHeader, "Receipt No"); + writeString(TransactionConstants.ROUTING_CODE_COL, rowHeader, "Routing Code"); + writeString(TransactionConstants.BANK_NO_COL, rowHeader, "Bank No"); + writeString(TransactionConstants.LOOKUP_CLIENT_NAME_COL, rowHeader, "Lookup Client"); + writeString(TransactionConstants.LOOKUP_ACCOUNT_NO_COL, rowHeader, "Lookup Account"); + writeString(TransactionConstants.LOOKUP_PRODUCT_COL, rowHeader, "Lookup Product"); + writeString(TransactionConstants.LOOKUP_OPENING_BALANCE_COL, rowHeader, "Lookup Opening Balance"); + writeString(TransactionConstants.LOOKUP_SAVINGS_ACTIVATION_DATE_COL, rowHeader, "Lookup Savings Activation Date"); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/fixeddeposits/FixedDepositWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/fixeddeposits/FixedDepositWorkbookPopulator.java new file mode 100644 index 000000000..9afe7dc44 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/fixeddeposits/FixedDepositWorkbookPopulator.java @@ -0,0 +1,349 @@ +/** + * 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.populator.fixeddeposits; + +import org.apache.fineract.infrastructure.bulkimport.constants.FixedDepositConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.*; +import org.apache.fineract.portfolio.savings.data.FixedDepositProductData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.List; + +public class FixedDepositWorkbookPopulator extends AbstractWorkbookPopulator { + + private OfficeSheetPopulator officeSheetPopulator; + private ClientSheetPopulator clientSheetPopulator; + private PersonnelSheetPopulator personnelSheetPopulator; + private FixedDepositProductSheetPopulator productSheetPopulator; + + + + public FixedDepositWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, + ClientSheetPopulator clientSheetPopulator, PersonnelSheetPopulator personnelSheetPopulator, + FixedDepositProductSheetPopulator fixedDepositProductSheetPopulator) { + this.officeSheetPopulator = officeSheetPopulator; + this.clientSheetPopulator = clientSheetPopulator; + this.personnelSheetPopulator = personnelSheetPopulator; + this.productSheetPopulator = fixedDepositProductSheetPopulator; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet fixedDepositSheet = workbook.createSheet(TemplatePopulateImportConstants.FIXED_DEPOSIT_SHEET_NAME); + officeSheetPopulator.populate(workbook,dateFormat); + clientSheetPopulator.populate(workbook,dateFormat); + personnelSheetPopulator.populate(workbook,dateFormat); + productSheetPopulator.populate(workbook,dateFormat); + setRules(fixedDepositSheet,dateFormat); + setDefaults(fixedDepositSheet,dateFormat); + setClientAndGroupDateLookupTable(fixedDepositSheet, clientSheetPopulator.getClients(), null, + FixedDepositConstants.LOOKUP_CLIENT_NAME_COL,FixedDepositConstants.LOOKUP_ACTIVATION_DATE_COL,!TemplatePopulateImportConstants.CONTAINS_CLIENT_EXTERNAL_ID,dateFormat); + setLayout(fixedDepositSheet); + } + + private void setRules(Sheet worksheet,String dateFormat) { + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + FixedDepositConstants.OFFICE_NAME_COL,FixedDepositConstants.OFFICE_NAME_COL); + CellRangeAddressList clientNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + FixedDepositConstants.CLIENT_NAME_COL,FixedDepositConstants.CLIENT_NAME_COL); + CellRangeAddressList productNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + FixedDepositConstants.PRODUCT_COL, FixedDepositConstants.PRODUCT_COL); + CellRangeAddressList fieldOfficerRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + FixedDepositConstants.FIELD_OFFICER_NAME_COL, FixedDepositConstants.FIELD_OFFICER_NAME_COL); + CellRangeAddressList submittedDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + FixedDepositConstants.SUBMITTED_ON_DATE_COL, FixedDepositConstants.SUBMITTED_ON_DATE_COL); + CellRangeAddressList approvedDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + FixedDepositConstants.APPROVED_DATE_COL, FixedDepositConstants.APPROVED_DATE_COL); + CellRangeAddressList activationDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + FixedDepositConstants.ACTIVATION_DATE_COL, FixedDepositConstants.ACTIVATION_DATE_COL); + CellRangeAddressList interestCompudingPeriodRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + FixedDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL, FixedDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL); + CellRangeAddressList interestPostingPeriodRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + FixedDepositConstants.INTEREST_POSTING_PERIOD_COL, FixedDepositConstants.INTEREST_POSTING_PERIOD_COL); + CellRangeAddressList interestCalculationRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + FixedDepositConstants.INTEREST_CALCULATION_COL, FixedDepositConstants.INTEREST_CALCULATION_COL); + CellRangeAddressList interestCalculationDaysInYearRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), FixedDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, + FixedDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL); + CellRangeAddressList lockinPeriodFrequencyRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + FixedDepositConstants.LOCKIN_PERIOD_FREQUENCY_COL, FixedDepositConstants.LOCKIN_PERIOD_FREQUENCY_COL); + CellRangeAddressList depositAmountRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + FixedDepositConstants.DEPOSIT_AMOUNT_COL, FixedDepositConstants.DEPOSIT_AMOUNT_COL); + CellRangeAddressList depositPeriodTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + FixedDepositConstants.DEPOSIT_PERIOD_FREQUENCY_COL, FixedDepositConstants.DEPOSIT_PERIOD_FREQUENCY_COL); + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet) worksheet); + + setNames(worksheet); + + DataValidationConstraint officeNameConstraint = validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint clientNameConstraint = validationHelper + .createFormulaListConstraint("INDIRECT(CONCATENATE(\"Client_\",$A1))"); + DataValidationConstraint productNameConstraint = validationHelper.createFormulaListConstraint("Products"); + DataValidationConstraint fieldOfficerNameConstraint = validationHelper + .createFormulaListConstraint("INDIRECT(CONCATENATE(\"Staff_\",$A1))"); + DataValidationConstraint submittedDateConstraint = validationHelper.createDateConstraint( + DataValidationConstraint.OperatorType.BETWEEN, "=VLOOKUP($B1,$AF$2:$AG$" + + (clientSheetPopulator.getClientsSize() + 1) + ",2,FALSE)", "=TODAY()", + dateFormat); + DataValidationConstraint approvalDateConstraint = validationHelper.createDateConstraint( + DataValidationConstraint.OperatorType.BETWEEN, "=$E1", "=TODAY()", dateFormat); + DataValidationConstraint activationDateConstraint = validationHelper.createDateConstraint( + DataValidationConstraint.OperatorType.BETWEEN, "=$F1", "=TODAY()", dateFormat); + DataValidationConstraint interestCompudingPeriodConstraint = validationHelper. + createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_DAILY, + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_MONTHLY, + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_QUARTERLY, + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_SEMI_ANNUALLY, + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_ANNUALLY }); + DataValidationConstraint interestPostingPeriodConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_MONTHLY, + TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_QUARTERLY, + TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_BIANUALLY, + TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_ANNUALLY }); + DataValidationConstraint interestCalculationConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.INTEREST_CAL_DAILY_BALANCE, + TemplatePopulateImportConstants.INTEREST_CAL_AVG_BALANCE }); + DataValidationConstraint interestCalculationDaysInYearConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.INTEREST_CAL_DAYS_IN_YEAR_360, + TemplatePopulateImportConstants.INTEREST_CAL_DAYS_IN_YEAR_365 }); + DataValidationConstraint frequency = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.FREQUENCY_DAYS, + TemplatePopulateImportConstants.FREQUENCY_WEEKS, + TemplatePopulateImportConstants.FREQUENCY_MONTHS, + TemplatePopulateImportConstants.FREQUENCY_YEARS }); + DataValidationConstraint depositConstraint = validationHelper.createDecimalConstraint(DataValidationConstraint.OperatorType.GREATER_OR_EQUAL, "=INDIRECT(CONCATENATE(\"Min_Deposit_\",$C1))", null); + + DataValidation officeValidation = validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation clientValidation = validationHelper.createValidation(clientNameConstraint, clientNameRange); + DataValidation productNameValidation = validationHelper.createValidation(productNameConstraint, productNameRange); + DataValidation fieldOfficerValidation = validationHelper.createValidation(fieldOfficerNameConstraint, fieldOfficerRange); + DataValidation interestCompudingPeriodValidation = validationHelper.createValidation(interestCompudingPeriodConstraint, + interestCompudingPeriodRange); + DataValidation interestPostingPeriodValidation = validationHelper.createValidation(interestPostingPeriodConstraint, + interestPostingPeriodRange); + DataValidation interestCalculationValidation = validationHelper.createValidation(interestCalculationConstraint, + interestCalculationRange); + DataValidation interestCalculationDaysInYearValidation = validationHelper.createValidation( + interestCalculationDaysInYearConstraint, interestCalculationDaysInYearRange); + DataValidation lockinPeriodFrequencyValidation = validationHelper.createValidation(frequency, + lockinPeriodFrequencyRange); + DataValidation depositPeriodTypeValidation = validationHelper.createValidation(frequency, + depositPeriodTypeRange); + DataValidation submittedDateValidation = validationHelper.createValidation(submittedDateConstraint, submittedDateRange); + DataValidation approvalDateValidation = validationHelper.createValidation(approvalDateConstraint, approvedDateRange); + DataValidation activationDateValidation = validationHelper.createValidation(activationDateConstraint, activationDateRange); + DataValidation depositAmountValidation = validationHelper.createValidation(depositConstraint, depositAmountRange); + + + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(clientValidation); + worksheet.addValidationData(productNameValidation); + worksheet.addValidationData(fieldOfficerValidation); + worksheet.addValidationData(submittedDateValidation); + worksheet.addValidationData(approvalDateValidation); + worksheet.addValidationData(activationDateValidation); + worksheet.addValidationData(interestCompudingPeriodValidation); + worksheet.addValidationData(interestPostingPeriodValidation); + worksheet.addValidationData(interestCalculationValidation); + worksheet.addValidationData(interestCalculationDaysInYearValidation); + worksheet.addValidationData(lockinPeriodFrequencyValidation); + worksheet.addValidationData(depositPeriodTypeValidation); + worksheet.addValidationData(depositAmountValidation); + + } + + private void setNames(Sheet worksheet) { + Workbook savingsWorkbook = worksheet.getWorkbook(); + List officeNames = officeSheetPopulator.getOfficeNames(); + List products = productSheetPopulator.getProducts(); + + // Office Names + Name officeGroup = savingsWorkbook.createName(); + officeGroup.setNameName("Office"); + officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (officeNames.size() + 1)); + + // Client and Loan Officer Names for each office + for (Integer i = 0; i < officeNames.size(); i++) { + Integer[] officeNameToBeginEndIndexesOfClients = clientSheetPopulator.getOfficeNameToBeginEndIndexesOfClients().get(i); + Integer[] officeNameToBeginEndIndexesOfStaff = personnelSheetPopulator.getOfficeNameToBeginEndIndexesOfStaff().get(i); + Name clientName = savingsWorkbook.createName(); + Name fieldOfficerName = savingsWorkbook.createName(); + if (officeNameToBeginEndIndexesOfStaff != null) { + fieldOfficerName.setNameName("Staff_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + fieldOfficerName.setRefersToFormula(TemplatePopulateImportConstants.STAFF_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfStaff[0] + ":$B$" + + officeNameToBeginEndIndexesOfStaff[1]); + } + if (officeNameToBeginEndIndexesOfClients != null) { + clientName.setNameName("Client_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + clientName.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfClients[0] + ":$B$" + + officeNameToBeginEndIndexesOfClients[1]); + } + } + + // Product Name + Name productGroup = savingsWorkbook.createName(); + productGroup.setNameName("Products"); + productGroup.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$B$2:$B$" + (productSheetPopulator.getProductsSize() + 1)); + + // Default Interest Rate, Interest Compounding Period, Interest Posting + // Period, Interest Calculation, Interest Calculation Days In Year, + // Minimum Deposit, Lockin Period, Lockin Period Frequency + // Names for each product + for (Integer i = 0; i < products.size(); i++) { + Name interestCompoundingPeriodName = savingsWorkbook.createName(); + Name interestPostingPeriodName = savingsWorkbook.createName(); + Name interestCalculationName = savingsWorkbook.createName(); + Name daysInYearName = savingsWorkbook.createName(); + Name lockinPeriodName = savingsWorkbook.createName(); + Name lockinPeriodFrequencyName = savingsWorkbook.createName(); + Name depositName = savingsWorkbook.createName(); + Name minDepositName = savingsWorkbook.createName(); + Name maxDepositName = savingsWorkbook.createName(); + Name minDepositTermTypeName = savingsWorkbook.createName(); + + FixedDepositProductData product = products.get(i); + String productName = product.getName().replaceAll("[ ]", "_"); + + interestCompoundingPeriodName.setNameName("Interest_Compouding_" + productName); + interestPostingPeriodName.setNameName("Interest_Posting_" + productName); + interestCalculationName.setNameName("Interest_Calculation_" + productName); + daysInYearName.setNameName("Days_In_Year_" + productName); + minDepositName.setNameName("Min_Deposit_" + productName); + maxDepositName.setNameName("Max_Deposit_" + productName); + depositName.setNameName("Deposit_" + productName); + interestCompoundingPeriodName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$E$" + (i + 2)); + interestPostingPeriodName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$F$" + (i + 2)); + interestCalculationName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$G$" + (i + 2)); + daysInYearName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$H$" + (i + 2)); + depositName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$N$" + (i + 2)); + minDepositName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$L$" + (i + 2)); + maxDepositName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$M$" + (i + 2)); + + if(product.getMinDepositTermType() != null) { + minDepositTermTypeName.setNameName("Term_Type_" + productName); + minDepositTermTypeName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$P$" + (i + 2)); + } + if (product.getLockinPeriodFrequency() != null) { + lockinPeriodName.setNameName("Lockin_Period_" + productName); + lockinPeriodName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$I$" + (i + 2)); + } + if (product.getLockinPeriodFrequencyType() != null) { + lockinPeriodFrequencyName.setNameName("Lockin_Frequency_" + productName); + lockinPeriodFrequencyName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$J$" + (i + 2)); + } + } + } + + private void setDefaults(Sheet worksheet,String dateFormat) { + Workbook workbook = worksheet.getWorkbook(); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + try { + for (Integer rowNo = 1; rowNo < 1000; rowNo++) { + Row row = worksheet.createRow(rowNo); + writeFormula(FixedDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Interest_Compouding_\",$C" + + (rowNo + 1) + "))),\"\",INDIRECT(CONCATENATE(\"Interest_Compouding_\",$C" + (rowNo + 1) + ")))"); + writeFormula(FixedDepositConstants.INTEREST_POSTING_PERIOD_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Interest_Posting_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Interest_Posting_\",$C" + (rowNo + 1) + ")))"); + writeFormula(FixedDepositConstants.INTEREST_CALCULATION_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Interest_Calculation_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Interest_Calculation_\",$C" + (rowNo + 1) + ")))"); + writeFormula(FixedDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Days_In_Year_\",$C" + + (rowNo + 1) + "))),\"\",INDIRECT(CONCATENATE(\"Days_In_Year_\",$C" + (rowNo + 1) + ")))"); + writeFormula(FixedDepositConstants.LOCKIN_PERIOD_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Lockin_Period_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Lockin_Period_\",$C" + (rowNo + 1) + ")))"); + writeFormula(FixedDepositConstants.LOCKIN_PERIOD_FREQUENCY_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Lockin_Frequency_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Lockin_Frequency_\",$C" + (rowNo + 1) + ")))"); + writeFormula(FixedDepositConstants.DEPOSIT_AMOUNT_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Deposit_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Deposit_\",$C" + (rowNo + 1) + ")))"); + writeFormula(FixedDepositConstants.DEPOSIT_PERIOD_FREQUENCY_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Term_Type_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Term_Type_\",$C" + (rowNo + 1) + ")))"); + } + } catch (RuntimeException re) { + re.printStackTrace(); + } + } + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(FixedDepositConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.CLIENT_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.PRODUCT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.FIELD_OFFICER_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.SUBMITTED_ON_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.APPROVED_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.ACTIVATION_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.INTEREST_POSTING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.INTEREST_CALCULATION_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.LOCKIN_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.LOCKIN_PERIOD_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.DEPOSIT_AMOUNT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.DEPOSIT_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.DEPOSIT_PERIOD_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.EXTERNAL_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + + worksheet.setColumnWidth(FixedDepositConstants.CHARGE_ID_1, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.CHARGE_AMOUNT_1, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.CHARGE_DUE_DATE_1, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.CHARGE_ID_2, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.CHARGE_AMOUNT_2, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.CHARGE_DUE_DATE_2, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + + worksheet.setColumnWidth(FixedDepositConstants.LOOKUP_CLIENT_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(FixedDepositConstants.LOOKUP_ACTIVATION_DATE_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + + writeString(FixedDepositConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(FixedDepositConstants.CLIENT_NAME_COL, rowHeader, "Client Name*"); + writeString(FixedDepositConstants.PRODUCT_COL, rowHeader, "Product*"); + writeString(FixedDepositConstants.FIELD_OFFICER_NAME_COL, rowHeader, "Field Officer*"); + writeString(FixedDepositConstants.SUBMITTED_ON_DATE_COL, rowHeader, "Submitted On*"); + writeString(FixedDepositConstants.APPROVED_DATE_COL, rowHeader, "Approved On*"); + writeString(FixedDepositConstants.ACTIVATION_DATE_COL, rowHeader, "Activation Date*"); + writeString(FixedDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL, rowHeader, "Interest Compounding Period*"); + writeString(FixedDepositConstants.INTEREST_POSTING_PERIOD_COL, rowHeader, "Interest Posting Period*"); + writeString(FixedDepositConstants.INTEREST_CALCULATION_COL, rowHeader, "Interest Calculated*"); + writeString(FixedDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, rowHeader, "# Days in Year*"); + writeString(FixedDepositConstants.LOCKIN_PERIOD_COL, rowHeader, "Locked In For"); + writeString(FixedDepositConstants.DEPOSIT_AMOUNT_COL, rowHeader, "Deposit Amount"); + writeString(FixedDepositConstants.DEPOSIT_PERIOD_COL, rowHeader, "Deposit Period"); + writeString(FixedDepositConstants.EXTERNAL_ID_COL, rowHeader, "External Id"); + + writeString(FixedDepositConstants.CHARGE_ID_1,rowHeader,"Charge Id"); + writeString(FixedDepositConstants.CHARGE_AMOUNT_1, rowHeader, "Charged Amount"); + writeString(FixedDepositConstants.CHARGE_DUE_DATE_1, rowHeader, "Charged On Date"); + writeString(FixedDepositConstants.CHARGE_ID_2,rowHeader,"Charge Id"); + writeString(FixedDepositConstants.CHARGE_AMOUNT_2, rowHeader, "Charged Amount"); + writeString(FixedDepositConstants.CHARGE_DUE_DATE_2, rowHeader, "Charged On Date"); + writeString(FixedDepositConstants.CLOSED_ON_DATE, rowHeader, "Close on Date"); + writeString(FixedDepositConstants.ON_ACCOUNT_CLOSURE_ID,rowHeader,"Action(Account Transfer(200) or cash(100) "); + writeString(FixedDepositConstants.TO_SAVINGS_ACCOUNT_ID,rowHeader, "Transfered Account No."); + writeString(FixedDepositConstants.LOOKUP_CLIENT_NAME_COL, rowHeader, "Client Name"); + writeString(FixedDepositConstants.LOOKUP_ACTIVATION_DATE_COL, rowHeader, "Client Activation Date"); + } + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/group/GroupsWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/group/GroupsWorkbookPopulator.java new file mode 100644 index 000000000..038e10872 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/group/GroupsWorkbookPopulator.java @@ -0,0 +1,254 @@ +/** + * 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.populator.group; + +import org.apache.fineract.infrastructure.bulkimport.constants.GroupConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.*; +import org.apache.fineract.organisation.office.data.OfficeData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.List; + +public class GroupsWorkbookPopulator extends AbstractWorkbookPopulator { + + private OfficeSheetPopulator officeSheetPopulator; + private PersonnelSheetPopulator personnelSheetPopulator; + private CenterSheetPopulator centerSheetPopulator; + private ClientSheetPopulator clientSheetPopulator; + + public GroupsWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, + PersonnelSheetPopulator personnelSheetPopulator, CenterSheetPopulator centerSheetPopulator, + ClientSheetPopulator clientSheetPopulator) { + this.officeSheetPopulator = officeSheetPopulator; + this.personnelSheetPopulator = personnelSheetPopulator; + this.centerSheetPopulator = centerSheetPopulator; + this.clientSheetPopulator = clientSheetPopulator; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet groupSheet = workbook.createSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME); + personnelSheetPopulator.populate(workbook,dateFormat); + officeSheetPopulator.populate(workbook,dateFormat); + centerSheetPopulator.populate(workbook,dateFormat); + clientSheetPopulator.populate(workbook,dateFormat); + setLayout(groupSheet); + setLookupTable(groupSheet,dateFormat); + setRules(groupSheet,dateFormat); + + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(GroupConstants.NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.STAFF_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.CENTER_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.EXTERNAL_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.ACTIVE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.ACTIVATION_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.SUBMITTED_ON_DATE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.MEETING_START_DATE_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.IS_REPEATING_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.INTERVAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.REPEATS_ON_DAY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.STATUS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.GROUP_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.FAILURE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.CLIENT_NAMES_STARTING_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.LOOKUP_OFFICE_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.LOOKUP_OFFICE_OPENING_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.LOOKUP_REPEAT_NORMAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.LOOKUP_REPEAT_MONTHLY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GroupConstants.LOOKUP_IF_REPEAT_WEEKLY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + + writeString(GroupConstants.NAME_COL, rowHeader, "Group Name*"); + writeString(GroupConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(GroupConstants.STAFF_NAME_COL, rowHeader, "Staff Name*"); + writeString(GroupConstants.CENTER_NAME_COL, rowHeader, "Center Name"); + writeString(GroupConstants.EXTERNAL_ID_COL, rowHeader, "External ID"); + writeString(GroupConstants.ACTIVE_COL, rowHeader, "Active*"); + writeString(GroupConstants.ACTIVATION_DATE_COL, rowHeader, "Activation Date*"); + writeString(GroupConstants.SUBMITTED_ON_DATE_COL,rowHeader,"Submitted On Date *"); + writeString(GroupConstants.MEETING_START_DATE_COL, rowHeader, "Meeting Start Date* (On or After)"); + writeString(GroupConstants.IS_REPEATING_COL, rowHeader, "Repeat*"); + writeString(GroupConstants.FREQUENCY_COL, rowHeader, "Frequency*"); + writeString(GroupConstants.INTERVAL_COL, rowHeader, "Interval*"); + writeString(GroupConstants.REPEATS_ON_DAY_COL, rowHeader, "Repeats On*"); + writeString(GroupConstants.CLIENT_NAMES_STARTING_COL, rowHeader, "Client Names* (Enter in consecutive cells horizontally)"); + writeString(GroupConstants.LOOKUP_OFFICE_NAME_COL, rowHeader, "Office Name"); + writeString(GroupConstants.LOOKUP_OFFICE_OPENING_DATE_COL, rowHeader, "Opening Date"); + writeString(GroupConstants.LOOKUP_REPEAT_NORMAL_COL, rowHeader, "Repeat Normal Range"); + writeString(GroupConstants.LOOKUP_REPEAT_MONTHLY_COL, rowHeader, "Repeat Monthly Range"); + writeString(GroupConstants.LOOKUP_IF_REPEAT_WEEKLY_COL, rowHeader, "If Repeat Weekly Range"); + + } + private void setLookupTable(Sheet groupSheet,String dateFormat) { + setOfficeDateLookupTable(groupSheet, officeSheetPopulator.getOffices(),GroupConstants.LOOKUP_OFFICE_NAME_COL, + GroupConstants. LOOKUP_OFFICE_OPENING_DATE_COL,dateFormat); + int rowIndex; + for(rowIndex = 1; rowIndex <= 11; rowIndex++) { + Row row = groupSheet.getRow(rowIndex); + if(row == null) + row = groupSheet.createRow(rowIndex); + writeInt(GroupConstants.LOOKUP_REPEAT_MONTHLY_COL, row, rowIndex); + } + for(rowIndex = 1; rowIndex <= 3; rowIndex++) + writeInt(GroupConstants.LOOKUP_REPEAT_NORMAL_COL, groupSheet.getRow(rowIndex), rowIndex); + String[] days = new String[]{ + TemplatePopulateImportConstants.MONDAY, + TemplatePopulateImportConstants.TUESDAY, + TemplatePopulateImportConstants.WEDNESDAY, + TemplatePopulateImportConstants.THURSDAY, + TemplatePopulateImportConstants.FRIDAY, + TemplatePopulateImportConstants.SATURDAY, + TemplatePopulateImportConstants.SUNDAY}; + for(rowIndex = 1; rowIndex <= 7; rowIndex++) + writeString(GroupConstants.LOOKUP_IF_REPEAT_WEEKLY_COL, groupSheet.getRow(rowIndex), days[rowIndex-1]); + } + + private void setRules(Sheet worksheet,String dateFormat){ + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GroupConstants.OFFICE_NAME_COL, GroupConstants.OFFICE_NAME_COL); + CellRangeAddressList staffNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GroupConstants.STAFF_NAME_COL, GroupConstants.STAFF_NAME_COL); + CellRangeAddressList centerNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GroupConstants.CENTER_NAME_COL, GroupConstants.CENTER_NAME_COL); + CellRangeAddressList activeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GroupConstants.ACTIVE_COL, GroupConstants.ACTIVE_COL); + CellRangeAddressList activationDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GroupConstants.ACTIVATION_DATE_COL,GroupConstants.ACTIVATION_DATE_COL); + CellRangeAddressList submittedOnDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GroupConstants.SUBMITTED_ON_DATE_COL,GroupConstants.SUBMITTED_ON_DATE_COL); + CellRangeAddressList meetingStartDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GroupConstants.MEETING_START_DATE_COL,GroupConstants.MEETING_START_DATE_COL); + CellRangeAddressList isRepeatRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GroupConstants.IS_REPEATING_COL, GroupConstants.IS_REPEATING_COL); + CellRangeAddressList repeatsRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GroupConstants. FREQUENCY_COL, GroupConstants.FREQUENCY_COL); + CellRangeAddressList repeatsEveryRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GroupConstants.INTERVAL_COL,GroupConstants. INTERVAL_COL); + CellRangeAddressList repeatsOnRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GroupConstants.REPEATS_ON_DAY_COL, GroupConstants.REPEATS_ON_DAY_COL); + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet)worksheet); + List offices = officeSheetPopulator.getOffices(); + setNames(worksheet, offices); + + DataValidationConstraint centerNameConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Center_\",$B1))"); + DataValidationConstraint officeNameConstraint = validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint staffNameConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Staff_\",$B1))"); + DataValidationConstraint booleanConstraint = validationHelper.createExplicitListConstraint(new String[]{"True", "False"}); + DataValidationConstraint activationDateConstraint = validationHelper.createDateConstraint + (DataValidationConstraint.OperatorType.BETWEEN, + "=VLOOKUP($B1,$IR$2:$IS" + (offices.size() + 1)+",2,FALSE)", "=TODAY()", dateFormat); + DataValidationConstraint submittedOnDateConstraint = + validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.LESS_OR_EQUAL, + "=$G1" ,null,dateFormat); + DataValidationConstraint meetingStartDateConstraint = validationHelper. + createDateConstraint(DataValidationConstraint.OperatorType.BETWEEN, + "=$G1", "=TODAY()", dateFormat); + DataValidationConstraint repeatsConstraint = validationHelper.createExplicitListConstraint(new String[]{ + TemplatePopulateImportConstants.FREQUENCY_DAILY, + TemplatePopulateImportConstants.FREQUENCY_WEEKLY, + TemplatePopulateImportConstants.FREQUENCY_MONTHLY, + TemplatePopulateImportConstants.FREQUENCY_YEARLY}); + DataValidationConstraint repeatsEveryConstraint = validationHelper.createFormulaListConstraint("INDIRECT($K1)"); + DataValidationConstraint repeatsOnConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE($K1,\"_DAYS\"))"); + + DataValidation centerValidation=validationHelper.createValidation(centerNameConstraint, centerNameRange); + DataValidation officeValidation = validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation staffValidation = validationHelper.createValidation(staffNameConstraint, staffNameRange); + DataValidation activationDateValidation = validationHelper.createValidation(activationDateConstraint, activationDateRange); + DataValidation activeValidation = validationHelper.createValidation(booleanConstraint, activeRange); + DataValidation submittedOnDateValidation=validationHelper.createValidation(submittedOnDateConstraint,submittedOnDateRange); + DataValidation meetingStartDateValidation = validationHelper.createValidation(meetingStartDateConstraint, meetingStartDateRange); + DataValidation isRepeatValidation = validationHelper.createValidation(booleanConstraint, isRepeatRange); + DataValidation repeatsValidation = validationHelper.createValidation(repeatsConstraint, repeatsRange); + DataValidation repeatsEveryValidation = validationHelper.createValidation(repeatsEveryConstraint, repeatsEveryRange); + DataValidation repeatsOnValidation = validationHelper.createValidation(repeatsOnConstraint, repeatsOnRange); + + worksheet.addValidationData(centerValidation); + worksheet.addValidationData(activeValidation); + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(staffValidation); + worksheet.addValidationData(activationDateValidation); + worksheet.addValidationData(submittedOnDateValidation); + worksheet.addValidationData(meetingStartDateValidation); + worksheet.addValidationData(isRepeatValidation); + worksheet.addValidationData(repeatsValidation); + worksheet.addValidationData(repeatsEveryValidation); + worksheet.addValidationData(repeatsOnValidation); + } + + private void setNames(Sheet worksheet, List offices) { + Workbook centerWorkbook = worksheet.getWorkbook(); + Name officeCenter = centerWorkbook.createName(); + officeCenter.setNameName("Office"); + officeCenter.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (offices.size() + 1)); + + + //Repeat constraint names + Name repeatsDaily = centerWorkbook.createName(); + repeatsDaily.setNameName("Daily"); + repeatsDaily.setRefersToFormula(TemplatePopulateImportConstants.GROUP_SHEET_NAME+"!$IT$2:$IT$4"); + Name repeatsWeekly = centerWorkbook.createName(); + repeatsWeekly.setNameName("Weekly"); + repeatsWeekly.setRefersToFormula(TemplatePopulateImportConstants.GROUP_SHEET_NAME+"!$IT$2:$IT$4"); + Name repeatYearly = centerWorkbook.createName(); + repeatYearly.setNameName("Yearly"); + repeatYearly.setRefersToFormula(TemplatePopulateImportConstants.GROUP_SHEET_NAME+"!$IT$2:$IT$4"); + Name repeatsMonthly = centerWorkbook.createName(); + repeatsMonthly.setNameName("Monthly"); + repeatsMonthly.setRefersToFormula(TemplatePopulateImportConstants.GROUP_SHEET_NAME+"!$IU$2:$IU$12"); + Name repeatsOnWeekly = centerWorkbook.createName(); + repeatsOnWeekly.setNameName("Weekly_Days"); + repeatsOnWeekly.setRefersToFormula(TemplatePopulateImportConstants.GROUP_SHEET_NAME+"!$IV$2:$IV$8"); + + + //Staff Names for each office & center Names for each office + for(Integer i = 0; i < offices.size(); i++) { + Integer[] officeNameToBeginEndIndexesOfCenters =centerSheetPopulator.getOfficeNameToBeginEndIndexesOfCenters().get(i); + Integer[] officeNameToBeginEndIndexesOfStaff = personnelSheetPopulator.getOfficeNameToBeginEndIndexesOfStaff().get(i); + + Name loanOfficerName = centerWorkbook.createName(); + Name centerName=centerWorkbook.createName(); + + if(officeNameToBeginEndIndexesOfStaff != null) { + loanOfficerName.setNameName("Staff_" + offices.get(i).name().trim().replaceAll("[ )(]", "_")); + loanOfficerName.setRefersToFormula(TemplatePopulateImportConstants.STAFF_SHEET_NAME+ + "!$B$" + officeNameToBeginEndIndexesOfStaff[0] + ":$B$" + officeNameToBeginEndIndexesOfStaff[1]); + } + if (officeNameToBeginEndIndexesOfCenters!=null) { + centerName.setNameName("Center_" + offices.get(i).name().trim().replaceAll("[ )(]", "_")); + centerName.setRefersToFormula(TemplatePopulateImportConstants.CENTER_SHEET_NAME+ + "!$B$" + officeNameToBeginEndIndexesOfCenters[0] + ":$B$" + officeNameToBeginEndIndexesOfCenters[1]); + } + } + + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/guarantor/GuarantorWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/guarantor/GuarantorWorkbookPopulator.java new file mode 100644 index 000000000..912eb2b1a --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/guarantor/GuarantorWorkbookPopulator.java @@ -0,0 +1,314 @@ +/** + * 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.populator.guarantor; + +import org.apache.fineract.infrastructure.bulkimport.constants.GuarantorConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.ClientSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.OfficeSheetPopulator; +import org.apache.fineract.infrastructure.codes.data.CodeValueData; +import org.apache.fineract.portfolio.loanaccount.data.LoanAccountData; +import org.apache.fineract.portfolio.savings.data.SavingsAccountData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; + +public class GuarantorWorkbookPopulator extends AbstractWorkbookPopulator { + private OfficeSheetPopulator officeSheetPopulator; + private ClientSheetPopulator clientSheetPopulator; + private List loans; + private List savings; + private ListguarantorRelationshipTypes; + + public GuarantorWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, + ClientSheetPopulator clientSheetPopulator, + List loans, List savings, + List guarantorRelationshipTypes) { + this.officeSheetPopulator = officeSheetPopulator; + this.clientSheetPopulator = clientSheetPopulator; + this.loans = loans; + this.savings = savings; + this.guarantorRelationshipTypes=guarantorRelationshipTypes; + + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet addGuarantorSheet = workbook.createSheet(TemplatePopulateImportConstants.GUARANTOR_SHEET_NAME); + setLayout(addGuarantorSheet); + officeSheetPopulator.populate(workbook,dateFormat); + clientSheetPopulator.populate(workbook,dateFormat); + populateLoansTable(addGuarantorSheet,dateFormat); + populateSavingsTable(addGuarantorSheet,dateFormat); + populateGuarantorRelationshipTypes(addGuarantorSheet,dateFormat); + setRules(addGuarantorSheet); + + } + + + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(0); + worksheet.setColumnWidth(GuarantorConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.CLIENT_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.LOAN_ACCOUNT_NO_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.GUARANTO_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.CLIENT_RELATIONSHIP_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.ENTITY_OFFICE_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.ENTITY_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.FIRST_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.LAST_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.ADDRESS_LINE_1_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.ADDRESS_LINE_2_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.CITY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.DOB_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.ZIP_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.SAVINGS_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.AMOUNT, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.LOOKUP_CLIENT_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.LOOKUP_ACCOUNT_NO_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.LOOKUP_SAVINGS_CLIENT_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(GuarantorConstants.LOOKUP_SAVINGS_ACCOUNT_NO_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(GuarantorConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(GuarantorConstants.CLIENT_NAME_COL, rowHeader, "Client Name*"); + writeString(GuarantorConstants.LOAN_ACCOUNT_NO_COL, rowHeader, " Loan Account NO"); + writeString(GuarantorConstants.GUARANTO_TYPE_COL, rowHeader, "Guranter_type*"); + writeString(GuarantorConstants.CLIENT_RELATIONSHIP_TYPE_COL, rowHeader, "Client Relationship type*"); + writeString(GuarantorConstants.ENTITY_OFFICE_NAME_COL, rowHeader, "Guranter office"); + writeString(GuarantorConstants.ENTITY_ID_COL, rowHeader, "Gurantor client id*"); + writeString(GuarantorConstants.FIRST_NAME_COL, rowHeader, "First Name*"); + writeString(GuarantorConstants.LAST_NAME_COL, rowHeader, "Last Name"); + writeString(GuarantorConstants.ADDRESS_LINE_1_COL, rowHeader, "ADDRESS LINE 1"); + writeString(GuarantorConstants.ADDRESS_LINE_2_COL, rowHeader, "ADDRESS LINE 2"); + writeString(GuarantorConstants.CITY_COL, rowHeader, "City"); + writeString(GuarantorConstants.DOB_COL, rowHeader, "Date of Birth"); + writeString(GuarantorConstants.ZIP_COL, rowHeader, "Zip*"); + writeString(GuarantorConstants.SAVINGS_ID_COL, rowHeader, "Savings Account Id"); + writeString(GuarantorConstants.AMOUNT, rowHeader, "Amount"); + writeString(GuarantorConstants.LOOKUP_CLIENT_NAME_COL, rowHeader, "Lookup Client"); + writeString(GuarantorConstants.LOOKUP_ACCOUNT_NO_COL, rowHeader, "Lookup Loan Account"); + writeString(GuarantorConstants.LOOKUP_SAVINGS_CLIENT_NAME_COL, rowHeader, "Savings Lookup Client"); + writeString(GuarantorConstants.LOOKUP_SAVINGS_ACCOUNT_NO_COL, rowHeader, "Savings Lookup Account"); + + } + private void populateSavingsTable(Sheet addGuarantorSheet,String dateFormat) { + Workbook workbook = addGuarantorSheet.getWorkbook(); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + int rowIndex = 1; + Row row; + Collections.sort(savings, SavingsAccountData.ClientNameComparator); + for(SavingsAccountData savingsAccount : savings) { + if(addGuarantorSheet.getRow(rowIndex)==null) { + row = addGuarantorSheet.createRow(rowIndex++); + } + else { + row=addGuarantorSheet.getRow(rowIndex++); + } + writeString(GuarantorConstants.LOOKUP_SAVINGS_CLIENT_NAME_COL, row, savingsAccount.getClientName() + "(" + savingsAccount.getClientId() + ")"); + writeLong(GuarantorConstants.LOOKUP_SAVINGS_ACCOUNT_NO_COL, row, Long.parseLong(savingsAccount.getAccountNo())); + } + + } + private void populateLoansTable(Sheet addGuarantorSheet,String dateFormat) { + Workbook workbook = addGuarantorSheet.getWorkbook(); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + int rowIndex = 1; + Row row; + Collections.sort(loans, LoanAccountData.ClientNameComparator); + for(LoanAccountData loan : loans) { + if(addGuarantorSheet.getRow(rowIndex)==null){ + row = addGuarantorSheet.createRow(rowIndex++); + } + else{ + row= addGuarantorSheet.getRow(rowIndex++); + } + writeString(GuarantorConstants.LOOKUP_CLIENT_NAME_COL, row, loan.getClientName() + "(" + loan.getClientId() + ")"); + writeString(GuarantorConstants.LOOKUP_ACCOUNT_NO_COL, row, Long.parseLong(loan.getAccountNo())+"-"+loan.getStatusStringValue()); + } + } + private void populateGuarantorRelationshipTypes(Sheet addGuarantorSheet, String dateFormat) { + Workbook workbook = addGuarantorSheet.getWorkbook(); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + int rowIndex = 1; + Row row; + for (CodeValueData relationshipType:guarantorRelationshipTypes) { + if (addGuarantorSheet.getRow(rowIndex)==null){ + row=addGuarantorSheet.createRow(rowIndex++); + }else { + row=addGuarantorSheet.getRow(rowIndex++); + } + writeString(GuarantorConstants.LOOKUP_GUARANTOR_RELATIONSHIPS,row,relationshipType.getName()+"-"+relationshipType.getId()); + } + + } + private void setRules(Sheet worksheet) { + + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GuarantorConstants.OFFICE_NAME_COL, GuarantorConstants.OFFICE_NAME_COL); + CellRangeAddressList clientNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GuarantorConstants.CLIENT_NAME_COL, GuarantorConstants.CLIENT_NAME_COL); + CellRangeAddressList entityofficeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GuarantorConstants.ENTITY_OFFICE_NAME_COL, GuarantorConstants.ENTITY_OFFICE_NAME_COL); + CellRangeAddressList entityclientNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GuarantorConstants.ENTITY_ID_COL, GuarantorConstants.ENTITY_ID_COL); + CellRangeAddressList accountNumberRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GuarantorConstants.LOAN_ACCOUNT_NO_COL, GuarantorConstants.LOAN_ACCOUNT_NO_COL); + CellRangeAddressList savingsaccountNumberRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GuarantorConstants.SAVINGS_ID_COL, GuarantorConstants.SAVINGS_ID_COL); + CellRangeAddressList guranterTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GuarantorConstants.GUARANTO_TYPE_COL, GuarantorConstants.GUARANTO_TYPE_COL); + CellRangeAddressList guranterRelationshipTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + GuarantorConstants.CLIENT_RELATIONSHIP_TYPE_COL, GuarantorConstants.CLIENT_RELATIONSHIP_TYPE_COL); + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet)worksheet); + + setNames(worksheet); + + DataValidationConstraint officeNameConstraint = validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint clientNameConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Client_\",$A1))"); + DataValidationConstraint accountNumberConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Account_\",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($B1,\" \",\"_\"),\"(\",\"_\"),\")\",\"_\")))"); + DataValidationConstraint savingsaccountNumberConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"SavingsAccount_\",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($G1,\" \",\"_\"),\"(\",\"_\"),\")\",\"_\")))"); + DataValidationConstraint guranterTypeConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.GUARANTOR_INTERNAL, + TemplatePopulateImportConstants.GUARANTOR_EXTERNAL}); + DataValidationConstraint guarantorRelationshipConstraint = validationHelper.createFormulaListConstraint("GuarantorRelationship"); + DataValidationConstraint entityofficeNameConstraint = validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint entityclientNameConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Client_\",$F1))"); + + DataValidation officeValidation = validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation clientValidation = validationHelper.createValidation(clientNameConstraint, clientNameRange); + DataValidation accountNumberValidation = validationHelper.createValidation(accountNumberConstraint, accountNumberRange); + DataValidation savingsaccountNumberValidation = validationHelper.createValidation(savingsaccountNumberConstraint, savingsaccountNumberRange); + DataValidation guranterTypeValidation = validationHelper.createValidation(guranterTypeConstraint, guranterTypeRange); + DataValidation guarantorRelationshipValidation=validationHelper.createValidation(guarantorRelationshipConstraint,guranterRelationshipTypeRange); + DataValidation entityofficeValidation = validationHelper.createValidation(entityofficeNameConstraint, entityofficeNameRange); + DataValidation entityclientValidation = validationHelper.createValidation(entityclientNameConstraint, entityclientNameRange); + + + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(clientValidation); + worksheet.addValidationData(accountNumberValidation); + worksheet.addValidationData(guranterTypeValidation); + worksheet.addValidationData(guarantorRelationshipValidation); + worksheet.addValidationData(entityofficeValidation); + worksheet.addValidationData(entityclientValidation); + worksheet.addValidationData(savingsaccountNumberValidation); + + } + private void setNames(Sheet worksheet) { + Workbook addGurarantorWorkbook = worksheet.getWorkbook(); + ArrayList officeNames = new ArrayList(officeSheetPopulator.getOfficeNames()); + + //Office Names + Name officeGroup = addGurarantorWorkbook.createName(); + officeGroup.setNameName("Office"); + officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (officeNames.size() + 1)); + + //GurantorRelationshipTypes Names + Name guarantorRelationshipsGroup = addGurarantorWorkbook.createName(); + guarantorRelationshipsGroup.setNameName("GuarantorRelationship"); + guarantorRelationshipsGroup.setRefersToFormula(TemplatePopulateImportConstants.GUARANTOR_SHEET_NAME+"!$CH$2:$CH$" + (guarantorRelationshipTypes.size() + 1)); + + //Clients Named after Offices + for(Integer i = 0; i < officeNames.size(); i++) { + Integer[] officeNameToBeginEndIndexesOfClients = clientSheetPopulator.getOfficeNameToBeginEndIndexesOfClients().get(i); + Name name = addGurarantorWorkbook.createName(); + if(officeNameToBeginEndIndexesOfClients != null) { + name.setNameName("Client_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + name.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfClients[0] + + ":$B$" + officeNameToBeginEndIndexesOfClients[1]); + } + } + + //Counting clients with active loans and starting and end addresses of cells + HashMap clientNameToBeginEndIndexes = new HashMap(); + ArrayList clientsWithActiveLoans = new ArrayList(); + ArrayList clientIdsWithActiveLoans = new ArrayList(); + int startIndex = 1, endIndex = 1; + String clientName = ""; + String clientId = ""; + for(int i = 0; i < loans.size(); i++){ + if(!clientName.equals(loans.get(i).getClientName())) { + endIndex = i + 1; + clientNameToBeginEndIndexes.put(clientName, new Integer[]{startIndex, endIndex}); + startIndex = i + 2; + clientName = loans.get(i).getClientName(); + clientId = loans.get(i).getClientId().toString(); + clientsWithActiveLoans.add(clientName); + clientIdsWithActiveLoans.add(clientId); + } + if(i == loans.size()-1) { + endIndex = i + 2; + clientNameToBeginEndIndexes.put(clientName, new Integer[]{startIndex, endIndex}); + } + } + + //Account Number Named after Clients + for(int j = 0; j < clientsWithActiveLoans.size(); j++) { + Name name = addGurarantorWorkbook.createName(); + name.setNameName("Account_" + clientsWithActiveLoans.get(j).replaceAll(" ", "_") + "_" + clientIdsWithActiveLoans.get(j) + "_"); + name.setRefersToFormula(TemplatePopulateImportConstants.GUARANTOR_SHEET_NAME+"!$CE$" + clientNameToBeginEndIndexes.get(clientsWithActiveLoans.get(j))[0] + + ":$CE$" + clientNameToBeginEndIndexes.get(clientsWithActiveLoans.get(j))[1]); + } + ///savings + //Counting clients with active savings and starting and end addresses of cells for naming + ArrayList clientsWithActiveSavings = new ArrayList(); + ArrayList clientIdsWithActiveSavings = new ArrayList(); + clientName=""; + clientId=""; + for(int i = 0; i < savings.size(); i++){ + if(!clientName.equals(savings.get(i).getClientName())) { + endIndex = i + 1; + clientNameToBeginEndIndexes.put(clientName, new Integer[]{startIndex, endIndex}); + startIndex = i + 2; + clientName = savings.get(i).getClientName(); + clientId = savings.get(i).getClientId().toString(); + clientsWithActiveSavings.add(clientName); + clientIdsWithActiveSavings.add(clientId); + } + if(i == savings.size()-1) { + endIndex = i + 2; + clientNameToBeginEndIndexes.put(clientName, new Integer[]{startIndex, endIndex}); + } + } + //Account Number Named after Clients + for(int j = 0; j < clientsWithActiveSavings.size(); j++) { + Name name = addGurarantorWorkbook.createName(); + name.setNameName("SavingsAccount_" + clientsWithActiveSavings.get(j).replaceAll(" ", "_") + "_" + clientIdsWithActiveSavings.get(j) + "_"); + name.setRefersToFormula(TemplatePopulateImportConstants.GUARANTOR_SHEET_NAME+"!$CG$" + clientNameToBeginEndIndexes.get(clientsWithActiveSavings.get(j))[0] + + ":$CG$" + clientNameToBeginEndIndexes.get(clientsWithActiveSavings.get(j))[1]); + } + + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/journalentry/JournalEntriesWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/journalentry/JournalEntriesWorkbookPopulator.java new file mode 100644 index 000000000..23ae4404e --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/journalentry/JournalEntriesWorkbookPopulator.java @@ -0,0 +1,191 @@ +/** + * 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.populator.journalentry; + +import org.apache.fineract.infrastructure.bulkimport.constants.JournalEntryConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.ExtrasSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.GlAccountSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.OfficeSheetPopulator; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.ArrayList; + + +public class JournalEntriesWorkbookPopulator extends AbstractWorkbookPopulator { + + private OfficeSheetPopulator officeSheetPopulator; + private GlAccountSheetPopulator glAccountSheetPopulator; + private ExtrasSheetPopulator extrasSheetPopulator; + + public JournalEntriesWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, + GlAccountSheetPopulator glAccountSheetPopulator, ExtrasSheetPopulator extrasSheetPopulator) { + this.officeSheetPopulator = officeSheetPopulator; + this.glAccountSheetPopulator = glAccountSheetPopulator; + this.extrasSheetPopulator = extrasSheetPopulator; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet addJournalEntriesSheet = workbook.createSheet(TemplatePopulateImportConstants.JOURNAL_ENTRY_SHEET_NAME); + officeSheetPopulator.populate(workbook,dateFormat); + glAccountSheetPopulator.populate(workbook,dateFormat); + extrasSheetPopulator.populate(workbook,dateFormat); + setRules(addJournalEntriesSheet); + setDefaults(addJournalEntriesSheet); + setLayout(addJournalEntriesSheet); + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(JournalEntryConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.TRANSACION_ON_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.CURRENCY_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.PAYMENT_TYPE_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.TRANSACTION_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.GL_ACCOUNT_ID_CREDIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.AMOUNT_CREDIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.GL_ACCOUNT_ID_DEBIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.AMOUNT_DEBIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.ACCOUNT_NO_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.CHECK_NO_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.ROUTING_CODE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.RECEIPT_NO_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.BANK_NO_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(JournalEntryConstants.COMMENTS_COL,TemplatePopulateImportConstants.EXTRALARGE_COL_SIZE); + + writeString(JournalEntryConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(JournalEntryConstants.TRANSACION_ON_DATE_COL, rowHeader, "Transaction On *"); + writeString(JournalEntryConstants.CURRENCY_NAME_COL, rowHeader, "Currecy Type*"); + writeString(JournalEntryConstants.PAYMENT_TYPE_ID_COL, rowHeader, "Payment Type*"); + writeString(JournalEntryConstants.TRANSACTION_ID_COL, rowHeader, "Transaction Id*"); + writeString(JournalEntryConstants.GL_ACCOUNT_ID_CREDIT_COL, rowHeader, "Credit Account Type*"); + writeString(JournalEntryConstants.AMOUNT_CREDIT_COL, rowHeader, "Amount*"); + writeString(JournalEntryConstants.GL_ACCOUNT_ID_DEBIT_COL, rowHeader, "Debit Account Type*"); + writeString(JournalEntryConstants.AMOUNT_DEBIT_COL, rowHeader, "Amount*"); + writeString(JournalEntryConstants.ACCOUNT_NO_COL,rowHeader,"Account#"); + writeString(JournalEntryConstants.CHECK_NO_COL,rowHeader,"Cheque#"); + writeString(JournalEntryConstants.ROUTING_CODE_COL,rowHeader,"Routing code"); + writeString(JournalEntryConstants.RECEIPT_NO_COL,rowHeader,"Receipt#"); + writeString(JournalEntryConstants.BANK_NO_COL,rowHeader,"Bank#"); + writeString(JournalEntryConstants.COMMENTS_COL,rowHeader,"Comments"); + + // TODO Auto-generated method stub + + } + + private void setRules(Sheet worksheet) { + + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), + JournalEntryConstants.OFFICE_NAME_COL,JournalEntryConstants. OFFICE_NAME_COL); + + CellRangeAddressList currencyCodeRange = new CellRangeAddressList( + 1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + JournalEntryConstants.CURRENCY_NAME_COL, JournalEntryConstants.CURRENCY_NAME_COL); + + CellRangeAddressList paymenttypeRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), + JournalEntryConstants.PAYMENT_TYPE_ID_COL, JournalEntryConstants.PAYMENT_TYPE_ID_COL); + + CellRangeAddressList glaccountCreditRange = new CellRangeAddressList( + 1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + JournalEntryConstants.GL_ACCOUNT_ID_CREDIT_COL, JournalEntryConstants.GL_ACCOUNT_ID_CREDIT_COL); + + CellRangeAddressList glaccountDebitRange = new CellRangeAddressList( + 1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + JournalEntryConstants.GL_ACCOUNT_ID_DEBIT_COL, JournalEntryConstants.GL_ACCOUNT_ID_DEBIT_COL); + + DataValidationHelper validationHelper = new HSSFDataValidationHelper( + (HSSFSheet) worksheet); + + setNames(worksheet); + + DataValidationConstraint officeNameConstraint = validationHelper + .createFormulaListConstraint("Office"); + DataValidationConstraint currencyCodeConstraint = validationHelper + .createFormulaListConstraint("Currency"); + DataValidationConstraint paymentTypeConstraint = validationHelper + .createFormulaListConstraint("PaymentType"); + + DataValidationConstraint glaccountConstraint = validationHelper + .createFormulaListConstraint("GlAccounts"); + + DataValidation officeValidation = validationHelper + .createValidation(officeNameConstraint, officeNameRange); + DataValidation currencyCodeValidation = validationHelper + .createValidation(currencyCodeConstraint, currencyCodeRange); + DataValidation paymentTypeValidation = validationHelper + .createValidation(paymentTypeConstraint, paymenttypeRange); + + DataValidation glaccountCreditValidation = validationHelper + .createValidation(glaccountConstraint, glaccountCreditRange); + DataValidation glaccountDebitValidation = validationHelper + .createValidation(glaccountConstraint, glaccountDebitRange); + + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(currencyCodeValidation); + worksheet.addValidationData(paymentTypeValidation); + + worksheet.addValidationData(glaccountCreditValidation); + worksheet.addValidationData(glaccountDebitValidation); + } + + private void setNames(Sheet worksheet) { + Workbook addJournalEntriesWorkbook = worksheet.getWorkbook(); + ArrayList officeNames = new ArrayList<>(officeSheetPopulator.getOfficeNames()); + // Office Names + Name officeGroup = addJournalEntriesWorkbook.createName(); + officeGroup.setNameName("Office"); + officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + + (officeNames.size() + 1)); + // Payment Type Name + Name paymentTypeGroup = addJournalEntriesWorkbook.createName(); + paymentTypeGroup.setNameName("PaymentType"); + paymentTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME+"!$D$2:$D$" + + (extrasSheetPopulator.getPaymentTypesSize() + 1)); + // Currency Type Name + Name currencyGroup = addJournalEntriesWorkbook.createName(); + currencyGroup.setNameName("Currency"); + currencyGroup.setRefersToFormula(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME+"!$F$2:$F$" + + (extrasSheetPopulator.getCurrenciesSize() + 1)); + + // Account Name + Name glaccountGroup = addJournalEntriesWorkbook.createName(); + glaccountGroup.setNameName("GlAccounts"); + glaccountGroup.setRefersToFormula(TemplatePopulateImportConstants.GL_ACCOUNTS_SHEET_NAME+"!$B$2:$B$" + + (glAccountSheetPopulator.getGlAccountNamesSize() + 1)); + } + + private void setDefaults(Sheet worksheet) { + for (Integer rowNo = 1; rowNo < 1000; rowNo++) { + Row row = worksheet.createRow(rowNo); + } + + } + + + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loan/LoanWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loan/LoanWorkbookPopulator.java new file mode 100644 index 000000000..409eed58a --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loan/LoanWorkbookPopulator.java @@ -0,0 +1,565 @@ +/** + * 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.populator.loan; + +import org.apache.fineract.infrastructure.bulkimport.constants.LoanConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.*; +import org.apache.fineract.portfolio.client.data.ClientData; +import org.apache.fineract.portfolio.loanproduct.data.LoanProductData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.List; + +public class LoanWorkbookPopulator extends AbstractWorkbookPopulator { + + private OfficeSheetPopulator officeSheetPopulator; + private ClientSheetPopulator clientSheetPopulator; + private GroupSheetPopulator groupSheetPopulator; + private PersonnelSheetPopulator personnelSheetPopulator; + private LoanProductSheetPopulator productSheetPopulator; + private ExtrasSheetPopulator extrasSheetPopulator; + + + public LoanWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, ClientSheetPopulator clientSheetPopulator, + GroupSheetPopulator groupSheetPopulator, PersonnelSheetPopulator personnelSheetPopulator, + LoanProductSheetPopulator productSheetPopulator, ExtrasSheetPopulator extrasSheetPopulator) { + this.officeSheetPopulator = officeSheetPopulator; + this.clientSheetPopulator = clientSheetPopulator; + this.groupSheetPopulator = groupSheetPopulator; + this.personnelSheetPopulator = personnelSheetPopulator; + this.productSheetPopulator = productSheetPopulator; + this.extrasSheetPopulator = extrasSheetPopulator; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet loanSheet = workbook.createSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME); + officeSheetPopulator.populate(workbook,dateFormat); + clientSheetPopulator.populate(workbook,dateFormat); + groupSheetPopulator.populate(workbook,dateFormat); + personnelSheetPopulator.populate(workbook,dateFormat); + productSheetPopulator.populate(workbook,dateFormat); + extrasSheetPopulator.populate(workbook,dateFormat); + setLayout(loanSheet); + setRules(loanSheet,dateFormat); + setDefaults(loanSheet); + setClientAndGroupDateLookupTable(loanSheet, clientSheetPopulator.getClients(), groupSheetPopulator.getGroups(), + LoanConstants.LOOKUP_CLIENT_NAME_COL, LoanConstants.LOOKUP_ACTIVATION_DATE_COL, + TemplatePopulateImportConstants.CONTAINS_CLIENT_EXTERNAL_ID,dateFormat); + } + + private void setRules(Sheet worksheet,String dateFormat) { + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + LoanConstants.OFFICE_NAME_COL, LoanConstants.OFFICE_NAME_COL); + CellRangeAddressList loanTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + LoanConstants.LOAN_TYPE_COL, LoanConstants.LOAN_TYPE_COL); + CellRangeAddressList clientNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + LoanConstants.CLIENT_NAME_COL, LoanConstants.CLIENT_NAME_COL); + CellRangeAddressList productNameRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.PRODUCT_COL, LoanConstants.PRODUCT_COL); + CellRangeAddressList loanOfficerRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.LOAN_OFFICER_NAME_COL, LoanConstants.LOAN_OFFICER_NAME_COL); + CellRangeAddressList submittedDateRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.SUBMITTED_ON_DATE_COL,LoanConstants. SUBMITTED_ON_DATE_COL); + CellRangeAddressList fundNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + LoanConstants.FUND_NAME_COL, LoanConstants.FUND_NAME_COL); + CellRangeAddressList principalRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + LoanConstants.PRINCIPAL_COL,LoanConstants.PRINCIPAL_COL); + CellRangeAddressList noOfRepaymentsRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.NO_OF_REPAYMENTS_COL, LoanConstants.NO_OF_REPAYMENTS_COL); + CellRangeAddressList repaidFrequencyRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.REPAID_EVERY_FREQUENCY_COL, LoanConstants.REPAID_EVERY_FREQUENCY_COL); + CellRangeAddressList loanTermRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + LoanConstants.LOAN_TERM_COL, LoanConstants.LOAN_TERM_COL); + CellRangeAddressList loanTermFrequencyRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.LOAN_TERM_FREQUENCY_COL, LoanConstants.LOAN_TERM_FREQUENCY_COL); + CellRangeAddressList interestFrequencyRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(),LoanConstants.NOMINAL_INTEREST_RATE_FREQUENCY_COL, + LoanConstants.NOMINAL_INTEREST_RATE_FREQUENCY_COL); + CellRangeAddressList interestRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + LoanConstants.NOMINAL_INTEREST_RATE_COL, LoanConstants.NOMINAL_INTEREST_RATE_COL); + CellRangeAddressList amortizationRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.AMORTIZATION_COL, LoanConstants.AMORTIZATION_COL); + CellRangeAddressList interestMethodRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.INTEREST_METHOD_COL, LoanConstants.INTEREST_METHOD_COL); + CellRangeAddressList intrestCalculationPeriodRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.INTEREST_CALCULATION_PERIOD_COL, + LoanConstants.INTEREST_CALCULATION_PERIOD_COL); + CellRangeAddressList repaymentStrategyRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.REPAYMENT_STRATEGY_COL,LoanConstants. REPAYMENT_STRATEGY_COL); + CellRangeAddressList arrearsToleranceRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.ARREARS_TOLERANCE_COL,LoanConstants. ARREARS_TOLERANCE_COL); + CellRangeAddressList graceOnPrincipalPaymentRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.GRACE_ON_PRINCIPAL_PAYMENT_COL, + LoanConstants.GRACE_ON_PRINCIPAL_PAYMENT_COL); + CellRangeAddressList graceOnInterestPaymentRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.GRACE_ON_INTEREST_PAYMENT_COL, + LoanConstants.GRACE_ON_INTEREST_PAYMENT_COL); + CellRangeAddressList graceOnInterestChargedRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.GRACE_ON_INTEREST_CHARGED_COL, + LoanConstants.GRACE_ON_INTEREST_CHARGED_COL); + CellRangeAddressList approvedDateRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.APPROVED_DATE_COL, LoanConstants.APPROVED_DATE_COL); + CellRangeAddressList disbursedDateRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.DISBURSED_DATE_COL, LoanConstants.DISBURSED_DATE_COL); + CellRangeAddressList paymentTypeRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.DISBURSED_PAYMENT_TYPE_COL, LoanConstants.DISBURSED_PAYMENT_TYPE_COL); + CellRangeAddressList repaymentTypeRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.REPAYMENT_TYPE_COL,LoanConstants. REPAYMENT_TYPE_COL); + CellRangeAddressList lastrepaymentDateRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanConstants.LAST_REPAYMENT_DATE_COL, LoanConstants.LAST_REPAYMENT_DATE_COL); + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet) worksheet); + + setNames(worksheet); + + DataValidationConstraint officeNameConstraint = validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint loanTypeConstraint = validationHelper + .createExplicitListConstraint(new String[] { + LoanConstants.LOAN_TYPE_INDIVIDUAL, + LoanConstants.LOAN_TYPE_GROUP, + LoanConstants.LOAN_TYPE_JLG}); + DataValidationConstraint clientNameConstraint = validationHelper.createFormulaListConstraint( + "IF($B1=\"Group\",INDIRECT(CONCATENATE(\"Group_\",$A1)),INDIRECT(CONCATENATE(\"Client_\",$A1)))"); + DataValidationConstraint productNameConstraint = validationHelper.createFormulaListConstraint("Products"); + DataValidationConstraint loanOfficerNameConstraint = validationHelper + .createFormulaListConstraint("INDIRECT(CONCATENATE(\"Staff_\",$A1))"); + DataValidationConstraint submittedDateConstraint = validationHelper.createDateConstraint( + DataValidationConstraint.OperatorType.BETWEEN, + "=IF(INDIRECT(CONCATENATE(\"START_DATE_\",$E1))>VLOOKUP($C1,$AR$2:$AT$" + + (clientSheetPopulator.getClientsSize() + groupSheetPopulator.getGroupsSize() + 1) + + ",3,FALSE),INDIRECT(CONCATENATE(\"START_DATE_\",$E1)),VLOOKUP($C1,$AR$2:$AT$" + + (clientSheetPopulator.getClientsSize() + groupSheetPopulator.getGroupsSize() + 1) + + ",3,FALSE))", + "=TODAY()", dateFormat); + DataValidationConstraint approvalDateConstraint = validationHelper + .createDateConstraint(DataValidationConstraint.OperatorType.BETWEEN, "=$G1", "=TODAY()", dateFormat); + DataValidationConstraint disbursedDateConstraint = validationHelper + .createDateConstraint(DataValidationConstraint.OperatorType.BETWEEN, "=$H1", "=TODAY()", dateFormat); + DataValidationConstraint paymentTypeConstraint = validationHelper.createFormulaListConstraint("PaymentTypes"); + DataValidationConstraint fundNameConstraint = validationHelper.createFormulaListConstraint("Funds"); + DataValidationConstraint principalConstraint = validationHelper.createDecimalConstraint( + DataValidationConstraint.OperatorType.BETWEEN, "=INDIRECT(CONCATENATE(\"MIN_PRINCIPAL_\",$E1))", + "=INDIRECT(CONCATENATE(\"MAX_PRINCIPAL_\",$E1))"); + DataValidationConstraint noOfRepaymentsConstraint = validationHelper.createIntegerConstraint( + DataValidationConstraint.OperatorType.BETWEEN, "=INDIRECT(CONCATENATE(\"MIN_REPAYMENT_\",$E1))", + "=INDIRECT(CONCATENATE(\"MAX_REPAYMENT_\",$E1))"); + DataValidationConstraint frequencyConstraint = validationHelper + .createExplicitListConstraint(new String[] { "Days", "Weeks", "Months" }); + DataValidationConstraint loanTermConstraint = validationHelper + .createIntegerConstraint(DataValidationConstraint.OperatorType.GREATER_OR_EQUAL, "=$M1*$N1", null); + DataValidationConstraint interestFrequencyConstraint = validationHelper + .createFormulaListConstraint("INDIRECT(CONCATENATE(\"INTEREST_FREQUENCY_\",$E1))"); + DataValidationConstraint interestConstraint = validationHelper.createIntegerConstraint( + DataValidationConstraint.OperatorType.BETWEEN, "=INDIRECT(CONCATENATE(\"MIN_INTEREST_\",$E1))", + "=INDIRECT(CONCATENATE(\"MAX_INTEREST_\",$E1))"); + DataValidationConstraint amortizationConstraint = validationHelper + .createExplicitListConstraint(new String[] { "Equal principal payments", "Equal installments" }); + DataValidationConstraint interestMethodConstraint = validationHelper + .createExplicitListConstraint(new String[] { "Flat", "Declining Balance" }); + DataValidationConstraint interestCalculationPeriodConstraint = validationHelper + .createExplicitListConstraint(new String[] { "Daily", "Same as repayment period" }); + DataValidationConstraint repaymentStrategyConstraint = validationHelper.createExplicitListConstraint( + new String[] { "Penalties, Fees, Interest, Principal order", "HeavensFamily Unique", "Creocore Unique", + "Overdue/Due Fee/Int,Principal", "Principal, Interest, Penalties, Fees Order", + "Interest, Principal, Penalties, Fees Order", "Early Repayment Strategy" }); + DataValidationConstraint arrearsToleranceConstraint = validationHelper + .createIntegerConstraint(DataValidationConstraint.OperatorType.GREATER_OR_EQUAL, "0", null); + DataValidationConstraint graceOnPrincipalPaymentConstraint = validationHelper + .createIntegerConstraint(DataValidationConstraint.OperatorType.GREATER_OR_EQUAL, "0", null); + DataValidationConstraint graceOnInterestPaymentConstraint = validationHelper + .createIntegerConstraint(DataValidationConstraint.OperatorType.GREATER_OR_EQUAL, "0", null); + DataValidationConstraint graceOnInterestChargedConstraint = validationHelper + .createIntegerConstraint(DataValidationConstraint.OperatorType.GREATER_OR_EQUAL, "0", null); + DataValidationConstraint lastRepaymentDateConstraint = validationHelper + .createDateConstraint(DataValidationConstraint.OperatorType.BETWEEN, "=$I1", "=TODAY()", dateFormat); + + DataValidation officeValidation = validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation loanTypeValidation = validationHelper.createValidation(loanTypeConstraint, loanTypeRange); + DataValidation clientValidation = validationHelper.createValidation(clientNameConstraint, clientNameRange); + DataValidation productNameValidation = validationHelper.createValidation(productNameConstraint, + productNameRange); + DataValidation loanOfficerValidation = validationHelper.createValidation(loanOfficerNameConstraint, + loanOfficerRange); + DataValidation fundNameValidation = validationHelper.createValidation(fundNameConstraint, fundNameRange); + DataValidation repaidFrequencyValidation = validationHelper.createValidation(frequencyConstraint, + repaidFrequencyRange); + DataValidation loanTermFrequencyValidation = validationHelper.createValidation(frequencyConstraint, + loanTermFrequencyRange); + DataValidation amortizationValidation = validationHelper.createValidation(amortizationConstraint, + amortizationRange); + DataValidation interestMethodValidation = validationHelper.createValidation(interestMethodConstraint, + interestMethodRange); + DataValidation interestCalculationPeriodValidation = validationHelper + .createValidation(interestCalculationPeriodConstraint, intrestCalculationPeriodRange); + DataValidation repaymentStrategyValidation = validationHelper.createValidation(repaymentStrategyConstraint, + repaymentStrategyRange); + DataValidation paymentTypeValidation = validationHelper.createValidation(paymentTypeConstraint, + paymentTypeRange); + DataValidation repaymentTypeValidation = validationHelper.createValidation(paymentTypeConstraint, + repaymentTypeRange); + DataValidation submittedDateValidation = validationHelper.createValidation(submittedDateConstraint, + submittedDateRange); + DataValidation approvalDateValidation = validationHelper.createValidation(approvalDateConstraint, + approvedDateRange); + DataValidation disbursedDateValidation = validationHelper.createValidation(disbursedDateConstraint, + disbursedDateRange); + DataValidation lastRepaymentDateValidation = validationHelper.createValidation(lastRepaymentDateConstraint, + lastrepaymentDateRange); + DataValidation principalValidation = validationHelper.createValidation(principalConstraint, principalRange); + DataValidation loanTermValidation = validationHelper.createValidation(loanTermConstraint, loanTermRange); + DataValidation noOfRepaymentsValidation = validationHelper.createValidation(noOfRepaymentsConstraint, + noOfRepaymentsRange); + DataValidation interestValidation = validationHelper.createValidation(interestConstraint, interestRange); + DataValidation arrearsToleranceValidation = validationHelper.createValidation(arrearsToleranceConstraint, + arrearsToleranceRange); + DataValidation graceOnPrincipalPaymentValidation = validationHelper + .createValidation(graceOnPrincipalPaymentConstraint, graceOnPrincipalPaymentRange); + DataValidation graceOnInterestPaymentValidation = validationHelper + .createValidation(graceOnInterestPaymentConstraint, graceOnInterestPaymentRange); + DataValidation graceOnInterestChargedValidation = validationHelper + .createValidation(graceOnInterestChargedConstraint, graceOnInterestChargedRange); + DataValidation interestFrequencyValidation = validationHelper.createValidation(interestFrequencyConstraint, + interestFrequencyRange); + + interestFrequencyValidation.setSuppressDropDownArrow(true); + + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(loanTypeValidation); + worksheet.addValidationData(clientValidation); + worksheet.addValidationData(productNameValidation); + worksheet.addValidationData(loanOfficerValidation); + worksheet.addValidationData(submittedDateValidation); + worksheet.addValidationData(approvalDateValidation); + worksheet.addValidationData(disbursedDateValidation); + worksheet.addValidationData(paymentTypeValidation); + worksheet.addValidationData(fundNameValidation); + worksheet.addValidationData(principalValidation); + worksheet.addValidationData(repaidFrequencyValidation); + worksheet.addValidationData(loanTermFrequencyValidation); + worksheet.addValidationData(noOfRepaymentsValidation); + worksheet.addValidationData(loanTermValidation); + worksheet.addValidationData(interestValidation); + worksheet.addValidationData(interestFrequencyValidation); + worksheet.addValidationData(amortizationValidation); + worksheet.addValidationData(interestMethodValidation); + worksheet.addValidationData(interestCalculationPeriodValidation); + worksheet.addValidationData(repaymentStrategyValidation); + worksheet.addValidationData(arrearsToleranceValidation); + worksheet.addValidationData(graceOnPrincipalPaymentValidation); + worksheet.addValidationData(graceOnInterestPaymentValidation); + worksheet.addValidationData(graceOnInterestChargedValidation); + worksheet.addValidationData(lastRepaymentDateValidation); + worksheet.addValidationData(repaymentTypeValidation); + + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(LoanConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.LOAN_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.CLIENT_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.CLIENT_EXTERNAL_ID,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.PRODUCT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.LOAN_OFFICER_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.SUBMITTED_ON_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.APPROVED_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.DISBURSED_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.DISBURSED_PAYMENT_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.FUND_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.PRINCIPAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.LOAN_TERM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.LOAN_TERM_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.NO_OF_REPAYMENTS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.REPAID_EVERY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.REPAID_EVERY_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.NOMINAL_INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.NOMINAL_INTEREST_RATE_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.AMORTIZATION_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.INTEREST_METHOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.INTEREST_CALCULATION_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.ARREARS_TOLERANCE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.REPAYMENT_STRATEGY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.GRACE_ON_PRINCIPAL_PAYMENT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.GRACE_ON_INTEREST_PAYMENT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.GRACE_ON_INTEREST_CHARGED_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.INTEREST_CHARGED_FROM_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.FIRST_REPAYMENT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.TOTAL_AMOUNT_REPAID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.LAST_REPAYMENT_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.REPAYMENT_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.LOOKUP_CLIENT_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.LOOKUP_CLIENT_EXTERNAL_ID,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.LOOKUP_ACTIVATION_DATE_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.EXTERNAL_ID_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.CHARGE_ID_1, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.CHARGE_AMOUNT_1, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.CHARGE_DUE_DATE_1, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.CHARGE_ID_2, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.CHARGE_AMOUNT_2, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.CHARGE_DUE_DATE_2, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.GROUP_ID, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanConstants.LINK_ACCOUNT_ID, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + + writeString(LoanConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(LoanConstants.LOAN_TYPE_COL, rowHeader, "Loan Type*"); + writeString(LoanConstants.CLIENT_NAME_COL, rowHeader, "Client/Group Name*"); + writeString(LoanConstants.CLIENT_EXTERNAL_ID,rowHeader,"Client ExternalID"); + writeString(LoanConstants.PRODUCT_COL, rowHeader, "Product*"); + writeString(LoanConstants.LOAN_OFFICER_NAME_COL, rowHeader, "Loan Officer*"); + writeString(LoanConstants.SUBMITTED_ON_DATE_COL, rowHeader, "Submitted On*"); + writeString(LoanConstants.APPROVED_DATE_COL, rowHeader, "Approved On"); + writeString(LoanConstants.DISBURSED_DATE_COL, rowHeader, "Disbursed Date"); + writeString(LoanConstants.DISBURSED_PAYMENT_TYPE_COL, rowHeader, "Payment Type*"); + writeString(LoanConstants.FUND_NAME_COL, rowHeader, "Fund Name"); + writeString(LoanConstants.PRINCIPAL_COL, rowHeader, "Principal*"); + writeString(LoanConstants.LOAN_TERM_COL, rowHeader, "Loan Term*"); + writeString(LoanConstants.NO_OF_REPAYMENTS_COL, rowHeader, "# of Repayments*"); + writeString(LoanConstants.REPAID_EVERY_COL, rowHeader, "Repaid Every*"); + writeString(LoanConstants.NOMINAL_INTEREST_RATE_COL, rowHeader, "Nominal Interest %*"); + writeString(LoanConstants.AMORTIZATION_COL, rowHeader, "Amortization*"); + writeString(LoanConstants.INTEREST_METHOD_COL, rowHeader, "Interest Method*"); + writeString(LoanConstants.INTEREST_CALCULATION_PERIOD_COL, rowHeader, "Interest Calculation Period*"); + writeString(LoanConstants.ARREARS_TOLERANCE_COL, rowHeader, "Arrears Tolerance"); + writeString(LoanConstants.REPAYMENT_STRATEGY_COL, rowHeader, "Repayment Strategy*"); + writeString(LoanConstants.GRACE_ON_PRINCIPAL_PAYMENT_COL, rowHeader, "Grace-Principal Payment"); + writeString(LoanConstants.GRACE_ON_INTEREST_PAYMENT_COL, rowHeader, "Grace-Interest Payment"); + writeString(LoanConstants.GRACE_ON_INTEREST_CHARGED_COL, rowHeader, "Interest-Free Period(s)"); + writeString(LoanConstants.INTEREST_CHARGED_FROM_COL, rowHeader, "Interest Charged From"); + writeString(LoanConstants.FIRST_REPAYMENT_COL, rowHeader, "First Repayment On"); + writeString(LoanConstants.TOTAL_AMOUNT_REPAID_COL, rowHeader, "Amount Repaid"); + writeString(LoanConstants.LAST_REPAYMENT_DATE_COL, rowHeader, "Date-Last Repayment"); + writeString(LoanConstants.REPAYMENT_TYPE_COL, rowHeader, "Repayment Type"); + writeString(LoanConstants.LOOKUP_CLIENT_NAME_COL, rowHeader, "Client Name"); + writeString(LoanConstants.LOOKUP_CLIENT_EXTERNAL_ID,rowHeader,"Lookup Client ExternalID"); + writeString(LoanConstants.LOOKUP_ACTIVATION_DATE_COL, rowHeader, "Client Activation Date"); + writeString(LoanConstants.EXTERNAL_ID_COL, rowHeader, "External Id"); + writeString(LoanConstants.CHARGE_ID_1, rowHeader, "Charge Id"); + writeString(LoanConstants.CHARGE_AMOUNT_1, rowHeader, "Charged Amount"); + writeString(LoanConstants.CHARGE_DUE_DATE_1, rowHeader, "Charged On Date"); + writeString(LoanConstants.CHARGE_ID_2, rowHeader, "Charge Id"); + writeString(LoanConstants.CHARGE_AMOUNT_2, rowHeader, "Charged Amount"); + writeString(LoanConstants.CHARGE_DUE_DATE_2, rowHeader, "Charged On Date"); + writeString(LoanConstants.GROUP_ID, rowHeader, "GROUP ID"); + writeString(LoanConstants.LINK_ACCOUNT_ID, rowHeader, "Linked Account No."); + + CellStyle borderStyle = worksheet.getWorkbook().createCellStyle(); + CellStyle doubleBorderStyle = worksheet.getWorkbook().createCellStyle(); + borderStyle.setBorderBottom(CellStyle.BORDER_THIN); + doubleBorderStyle.setBorderBottom(CellStyle.BORDER_THIN); + doubleBorderStyle.setBorderRight(CellStyle.BORDER_THICK); + for (int colNo = 0; colNo < 35; colNo++) { + Cell cell = rowHeader.getCell(colNo); + if (cell == null) + rowHeader.createCell(colNo); + rowHeader.getCell(colNo).setCellStyle(borderStyle); + } + rowHeader.getCell(LoanConstants.FIRST_REPAYMENT_COL).setCellStyle(doubleBorderStyle); + rowHeader.getCell(LoanConstants.REPAYMENT_TYPE_COL).setCellStyle(doubleBorderStyle); + } + + private void setDefaults(Sheet worksheet) { + + for (Integer rowNo = 1; rowNo < 1000; rowNo++) { + Row row = worksheet.createRow(rowNo); + writeFormula(LoanConstants.CLIENT_EXTERNAL_ID, row, + "IF(ISERROR(VLOOKUP($C"+(rowNo+1)+",$AR$2:$AS$"+(clientSheetPopulator.getClients().size()+1)+",2,FALSE))," + + "\"\",(VLOOKUP($C"+(rowNo+1)+",$AR$2:$AS$"+(clientSheetPopulator.getClients().size()+1)+",2,FALSE)))"); + writeFormula(LoanConstants.FUND_NAME_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"FUND_\",$E" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"FUND_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.PRINCIPAL_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"PRINCIPAL_\",$E" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"PRINCIPAL_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.REPAID_EVERY_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"REPAYMENT_EVERY_\",$E" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"REPAYMENT_EVERY_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.REPAID_EVERY_FREQUENCY_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"REPAYMENT_FREQUENCY_\",$E" + + (rowNo + 1) + "))),\"\",INDIRECT(CONCATENATE(\"REPAYMENT_FREQUENCY_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.NO_OF_REPAYMENTS_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"NO_REPAYMENT_\",$E" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"NO_REPAYMENT_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.LOAN_TERM_COL, row, "IF(ISERROR($M" + (rowNo + 1) + "*$N" + (rowNo + 1) + "),\"\",$M" + + (rowNo + 1) + "*$N" + (rowNo + 1) + ")"); + writeFormula(LoanConstants.LOAN_TERM_FREQUENCY_COL, row, "$O" + (rowNo + 1)); + writeFormula(LoanConstants.NOMINAL_INTEREST_RATE_FREQUENCY_COL, row, + "IF(ISERROR(INDIRECT(CONCATENATE(\"INTEREST_FREQUENCY_\",$E" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"INTEREST_FREQUENCY_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.NOMINAL_INTEREST_RATE_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"INTEREST_\",$E" + + (rowNo + 1) + "))),\"\",INDIRECT(CONCATENATE(\"INTEREST_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.AMORTIZATION_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"AMORTIZATION_\",$E" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"AMORTIZATION_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.INTEREST_METHOD_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"INTEREST_TYPE_\",$E" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"INTEREST_TYPE_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.INTEREST_CALCULATION_PERIOD_COL, row, + "IF(ISERROR(INDIRECT(CONCATENATE(\"INTEREST_CALCULATION_\",$E" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"INTEREST_CALCULATION_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.ARREARS_TOLERANCE_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"ARREARS_TOLERANCE_\",$E" + + (rowNo + 1) + "))),\"\",INDIRECT(CONCATENATE(\"ARREARS_TOLERANCE_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.REPAYMENT_STRATEGY_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"STRATEGY_\",$E" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"STRATEGY_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.GRACE_ON_PRINCIPAL_PAYMENT_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"GRACE_PRINCIPAL_\",$E" + + (rowNo + 1) + "))),\"\",INDIRECT(CONCATENATE(\"GRACE_PRINCIPAL_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.GRACE_ON_INTEREST_PAYMENT_COL, row, + "IF(ISERROR(INDIRECT(CONCATENATE(\"GRACE_INTEREST_PAYMENT_\",$E" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"GRACE_INTEREST_PAYMENT_\",$E" + (rowNo + 1) + ")))"); + writeFormula(LoanConstants.GRACE_ON_INTEREST_CHARGED_COL, row, + "IF(ISERROR(INDIRECT(CONCATENATE(\"GRACE_INTEREST_CHARGED_\",$E" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"GRACE_INTEREST_CHARGED_\",$E" + (rowNo + 1) + ")))"); + + } + } + + private void setNames(Sheet worksheet) { + Workbook loanWorkbook = worksheet.getWorkbook(); + List officeNames = officeSheetPopulator.getOfficeNames(); + List products = productSheetPopulator.getProducts(); + + // Office Names + Name officeGroup = loanWorkbook.createName(); + officeGroup.setNameName("Office"); + officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (officeNames.size() + 1)); + + // Client and Loan Officer Names for each office + for (Integer i = 0; i < officeNames.size(); i++) { + Integer[] officeNameToBeginEndIndexesOfClients = clientSheetPopulator + .getOfficeNameToBeginEndIndexesOfClients().get(i); + Integer[] officeNameToBeginEndIndexesOfStaff = personnelSheetPopulator + .getOfficeNameToBeginEndIndexesOfStaff().get(i); + Integer[] officeNameToBeginEndIndexesOfGroups = groupSheetPopulator.getOfficeNameToBeginEndIndexesOfGroups() + .get(i); + Name clientName = loanWorkbook.createName(); + Name loanOfficerName = loanWorkbook.createName(); + Name groupName = loanWorkbook.createName(); + + if (officeNameToBeginEndIndexesOfStaff != null) { + loanOfficerName.setNameName("Staff_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + loanOfficerName.setRefersToFormula(TemplatePopulateImportConstants.STAFF_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfStaff[0] + ":$B$" + + officeNameToBeginEndIndexesOfStaff[1]); + } + if (officeNameToBeginEndIndexesOfClients != null) { + clientName.setNameName("Client_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + clientName.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfClients[0] + ":$B$" + + officeNameToBeginEndIndexesOfClients[1]); + } + if (officeNameToBeginEndIndexesOfGroups != null) { + groupName.setNameName("Group_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + groupName.setRefersToFormula(TemplatePopulateImportConstants.GROUP_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfGroups[0] + ":$B$" + + officeNameToBeginEndIndexesOfGroups[1]); + } + + } + + // Product Name + Name productGroup = loanWorkbook.createName(); + productGroup.setNameName("Products"); + productGroup.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$B$2:$B$" + (productSheetPopulator.getProductsSize() + 1)); + + // Fund Name + Name fundGroup = loanWorkbook.createName(); + fundGroup.setNameName("Funds"); + fundGroup.setRefersToFormula(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME+"!$B$2:$B$" + (extrasSheetPopulator.getFundsSize() + 1)); + + // Payment Type Name + Name paymentTypeGroup = loanWorkbook.createName(); + paymentTypeGroup.setNameName("PaymentTypes"); + paymentTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME+"!$D$2:$D$" + (extrasSheetPopulator.getPaymentTypesSize() + 1)); + + // Default Fund, Default Principal, Min Principal, Max Principal, + // Default No. of Repayments, Min Repayments, Max Repayments, Repayment + // Every, + // Repayment Every Frequency, Interest Rate, Min Interest Rate, Max + // Interest Rate, Interest Frequency, Amortization, Interest Type, + // Interest Calculation Period, Transaction Processing Strategy, Arrears + // Tolerance, GraceOnPrincipalPayment, GraceOnInterestPayment, + // GraceOnInterestCharged, StartDate Names for each loan product + for (Integer i = 0; i < products.size(); i++) { + Name fundName = loanWorkbook.createName(); + Name principalName = loanWorkbook.createName(); + Name minPrincipalName = loanWorkbook.createName(); + Name maxPrincipalName = loanWorkbook.createName(); + Name noOfRepaymentName = loanWorkbook.createName(); + Name minNoOfRepayment = loanWorkbook.createName(); + Name maxNoOfRepaymentName = loanWorkbook.createName(); + Name repaymentEveryName = loanWorkbook.createName(); + Name repaymentFrequencyName = loanWorkbook.createName(); + Name interestName = loanWorkbook.createName(); + Name minInterestName = loanWorkbook.createName(); + Name maxInterestName = loanWorkbook.createName(); + Name interestFrequencyName = loanWorkbook.createName(); + Name amortizationName = loanWorkbook.createName(); + Name interestTypeName = loanWorkbook.createName(); + Name interestCalculationPeriodName = loanWorkbook.createName(); + Name transactionProcessingStrategyName = loanWorkbook.createName(); + Name arrearsToleranceName = loanWorkbook.createName(); + Name graceOnPrincipalPaymentName = loanWorkbook.createName(); + Name graceOnInterestPaymentName = loanWorkbook.createName(); + Name graceOnInterestChargedName = loanWorkbook.createName(); + Name startDateName = loanWorkbook.createName(); + String productName = products.get(i).getName().replaceAll("[ ]", "_"); + fundName.setNameName("FUND_" + productName); + principalName.setNameName("PRINCIPAL_" + productName); + minPrincipalName.setNameName("MIN_PRINCIPAL_" + productName); + maxPrincipalName.setNameName("MAX_PRINCIPAL_" + productName); + noOfRepaymentName.setNameName("NO_REPAYMENT_" + productName); + minNoOfRepayment.setNameName("MIN_REPAYMENT_" + productName); + maxNoOfRepaymentName.setNameName("MAX_REPAYMENT_" + productName); + repaymentEveryName.setNameName("REPAYMENT_EVERY_" + productName); + repaymentFrequencyName.setNameName("REPAYMENT_FREQUENCY_" + productName); + interestName.setNameName("INTEREST_" + productName); + minInterestName.setNameName("MIN_INTEREST_" + productName); + maxInterestName.setNameName("MAX_INTEREST_" + productName); + interestFrequencyName.setNameName("INTEREST_FREQUENCY_" + productName); + amortizationName.setNameName("AMORTIZATION_" + productName); + interestTypeName.setNameName("INTEREST_TYPE_" + productName); + interestCalculationPeriodName.setNameName("INTEREST_CALCULATION_" + productName); + transactionProcessingStrategyName.setNameName("STRATEGY_" + productName); + arrearsToleranceName.setNameName("ARREARS_TOLERANCE_" + productName); + graceOnPrincipalPaymentName.setNameName("GRACE_PRINCIPAL_" + productName); + graceOnInterestPaymentName.setNameName("GRACE_INTEREST_PAYMENT_" + productName); + graceOnInterestChargedName.setNameName("GRACE_INTEREST_CHARGED_" + productName); + startDateName.setNameName("START_DATE_" + productName); + if (products.get(i).getFundName() != null) + fundName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$C$" + (i + 2)); + principalName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$D$" + (i + 2)); + minPrincipalName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$E$" + (i + 2)); + maxPrincipalName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$F$" + (i + 2)); + noOfRepaymentName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$G$" + (i + 2)); + minNoOfRepayment.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$H$" + (i + 2)); + maxNoOfRepaymentName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$I$" + (i + 2)); + repaymentEveryName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$J$" + (i + 2)); + repaymentFrequencyName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$K$" + (i + 2)); + interestName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$L$" + (i + 2)); + minInterestName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$M$" + (i + 2)); + maxInterestName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$N$" + (i + 2)); + interestFrequencyName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$O$" + (i + 2)); + amortizationName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$P$" + (i + 2)); + interestTypeName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$Q$" + (i + 2)); + interestCalculationPeriodName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$R$" + (i + 2)); + transactionProcessingStrategyName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$T$" + (i + 2)); + arrearsToleranceName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$S$" + (i + 2)); + graceOnPrincipalPaymentName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$U$" + (i + 2)); + graceOnInterestPaymentName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$V$" + (i + 2)); + graceOnInterestChargedName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$W$" + (i + 2)); + startDateName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$X$" + (i + 2)); + } + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loanrepayment/LoanRepaymentWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loanrepayment/LoanRepaymentWorkbookPopulator.java new file mode 100644 index 000000000..04646fbcc --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/loanrepayment/LoanRepaymentWorkbookPopulator.java @@ -0,0 +1,277 @@ +/** + * 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.populator.loanrepayment; + +import org.apache.fineract.infrastructure.bulkimport.constants.LoanRepaymentConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.ClientSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.ExtrasSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.OfficeSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.comparator.LoanComparatorByStatusActive; +import org.apache.fineract.portfolio.client.data.ClientData; +import org.apache.fineract.portfolio.loanaccount.data.LoanAccountData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +public class LoanRepaymentWorkbookPopulator extends AbstractWorkbookPopulator { + private OfficeSheetPopulator officeSheetPopulator; + private ClientSheetPopulator clientSheetPopulator; + private ExtrasSheetPopulator extrasSheetPopulator; + private List allloans; + private Map clientIdToClientExternalId; + + public LoanRepaymentWorkbookPopulator(List loans, OfficeSheetPopulator officeSheetPopulator, + ClientSheetPopulator clientSheetPopulator, ExtrasSheetPopulator extrasSheetPopulator) { + this.allloans = loans; + this.officeSheetPopulator = officeSheetPopulator; + this.clientSheetPopulator = clientSheetPopulator; + this.extrasSheetPopulator = extrasSheetPopulator; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet loanRepaymentSheet = workbook.createSheet(TemplatePopulateImportConstants.LOAN_REPAYMENT_SHEET_NAME); + setLayout(loanRepaymentSheet); + officeSheetPopulator.populate(workbook,dateFormat); + clientSheetPopulator.populate(workbook,dateFormat); + extrasSheetPopulator.populate(workbook,dateFormat); + setClientIdToClientExternalId(); + populateLoansTable(loanRepaymentSheet,dateFormat); + setRules(loanRepaymentSheet,dateFormat); + setDefaults(loanRepaymentSheet); + } + + private void setClientIdToClientExternalId() { + clientIdToClientExternalId =new HashMap<>(); + Listallclients=clientSheetPopulator.getClients(); + for (ClientData client: allclients) { + if (client.getExternalId()!=null) + clientIdToClientExternalId.put(client.getId(),client.getExternalId()); + } + } + + private void setDefaults(Sheet worksheet) { + for (Integer rowNo = 1; rowNo < 3000; rowNo++) { + Row row = worksheet.getRow(rowNo); + if (row == null) + row = worksheet.createRow(rowNo); + writeFormula(LoanRepaymentConstants.CLIENT_EXTERNAL_ID, row, + "IF(ISERROR(VLOOKUP($B"+(rowNo+1)+",$P$2:$Q$"+(allloans.size()+1)+",2,FALSE))," + + "\"\",(VLOOKUP($B"+(rowNo+1)+",$P$2:$Q$"+(allloans.size()+1)+",2,FALSE)))"); + writeFormula(LoanRepaymentConstants.PRODUCT_COL, row, + "IF(ISERROR(VLOOKUP($D" + (rowNo + 1) + ",$R$2:$T$" + (allloans.size() + 1) + + ",2,FALSE)),\"\",VLOOKUP($D" + (rowNo + 1) + ",$R$2:$T$" + (allloans.size() + 1) + + ",2,FALSE))"); + writeFormula(LoanRepaymentConstants.PRINCIPAL_COL, row, + "IF(ISERROR(VLOOKUP($D" + (rowNo + 1) + ",$R$2:$T$" + (allloans.size() + 1) + + ",3,FALSE)),\"\",VLOOKUP($D" + (rowNo + 1) + ",$R$2:$T$" + (allloans.size() + 1) + + ",3,FALSE))"); + } + } + + private void setRules(Sheet worksheet,String dateFormat) { + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + LoanRepaymentConstants.OFFICE_NAME_COL, LoanRepaymentConstants.OFFICE_NAME_COL); + CellRangeAddressList clientNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + LoanRepaymentConstants.CLIENT_NAME_COL, LoanRepaymentConstants.CLIENT_NAME_COL); + CellRangeAddressList accountNumberRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanRepaymentConstants.LOAN_ACCOUNT_NO_COL, LoanRepaymentConstants.LOAN_ACCOUNT_NO_COL); + CellRangeAddressList repaymentTypeRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanRepaymentConstants.REPAYMENT_TYPE_COL, LoanRepaymentConstants.REPAYMENT_TYPE_COL); + CellRangeAddressList repaymentDateRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), LoanRepaymentConstants.REPAID_ON_DATE_COL, LoanRepaymentConstants.REPAID_ON_DATE_COL); + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet) worksheet); + + setNames(worksheet); + + DataValidationConstraint officeNameConstraint = validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint clientNameConstraint = validationHelper + .createFormulaListConstraint("INDIRECT(CONCATENATE(\"Client_\",$A1))"); + DataValidationConstraint accountNumberConstraint = validationHelper.createFormulaListConstraint( + "INDIRECT(CONCATENATE(\"Account_\",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($B1,\" \",\"_\"),\"(\",\"_\"),\")\",\"_\")))"); + DataValidationConstraint paymentTypeConstraint = validationHelper.createFormulaListConstraint("PaymentTypes"); + DataValidationConstraint repaymentDateConstraint = validationHelper.createDateConstraint( + DataValidationConstraint.OperatorType.BETWEEN, + "=VLOOKUP($D1,$R$2:$U$" + (allloans.size() + 1) + ",4,FALSE)", "=TODAY()", dateFormat); + + DataValidation officeValidation = validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation clientValidation = validationHelper.createValidation(clientNameConstraint, clientNameRange); + DataValidation accountNumberValidation = validationHelper.createValidation(accountNumberConstraint, + accountNumberRange); + DataValidation repaymentTypeValidation = validationHelper.createValidation(paymentTypeConstraint, + repaymentTypeRange); + DataValidation repaymentDateValidation = validationHelper.createValidation(repaymentDateConstraint, + repaymentDateRange); + + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(clientValidation); + worksheet.addValidationData(accountNumberValidation); + worksheet.addValidationData(repaymentTypeValidation); + worksheet.addValidationData(repaymentDateValidation); + + } + + private void setNames(Sheet worksheet) { + ArrayList officeNames = new ArrayList<>(officeSheetPopulator.getOfficeNames()); + Workbook loanRepaymentWorkbook = worksheet.getWorkbook(); + // Office Names + Name officeGroup = loanRepaymentWorkbook.createName(); + officeGroup.setNameName("Office"); + officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (officeNames.size() + 1)); + + // Clients Named after Offices + for (Integer i = 0; i < officeNames.size(); i++) { + Integer[] officeNameToBeginEndIndexesOfClients = clientSheetPopulator + .getOfficeNameToBeginEndIndexesOfClients().get(i); + Name name = loanRepaymentWorkbook.createName(); + if (officeNameToBeginEndIndexesOfClients != null) { + name.setNameName("Client_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + name.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfClients[0] + ":$B$" + + officeNameToBeginEndIndexesOfClients[1]); + } + } + + // Counting clients with active loans and starting and end addresses of + // cells + HashMap clientNameToBeginEndIndexes = new HashMap(); + ArrayList clientsWithActiveLoans = new ArrayList(); + ArrayList clientIdsWithActiveLoans = new ArrayList(); + int startIndex = 1, endIndex = 1; + String clientName = ""; + String clientId = ""; + for (int i = 0; i < allloans.size(); i++) { + if (!clientName.equals(allloans.get(i).getClientName())) { + endIndex = i + 1; + clientNameToBeginEndIndexes.put(clientName, new Integer[] { startIndex, endIndex }); + startIndex = i + 2; + clientName = allloans.get(i).getClientName(); + clientId = allloans.get(i).getClientId().toString(); + if (!clientsWithActiveLoans.contains(clientName)) { + clientsWithActiveLoans.add(clientName); + clientIdsWithActiveLoans.add(clientId); + } + } + if (i == allloans.size() - 1) { + endIndex = i + 2; + clientNameToBeginEndIndexes.put(clientName, new Integer[] { startIndex, endIndex }); + } + } + + // Account Number Named after Clients + for (int j = 0; j < clientsWithActiveLoans.size(); j++) { + Name name = loanRepaymentWorkbook.createName(); + name.setNameName("Account_" + clientsWithActiveLoans.get(j).replaceAll(" ", "_") + "_" + + clientIdsWithActiveLoans.get(j) + "_"); + name.setRefersToFormula( + TemplatePopulateImportConstants.LOAN_REPAYMENT_SHEET_NAME+"!$R$" + clientNameToBeginEndIndexes.get(clientsWithActiveLoans.get(j))[0] + ":$R$" + + clientNameToBeginEndIndexes.get(clientsWithActiveLoans.get(j))[1]); + } + + // Payment Type Name + Name paymentTypeGroup = loanRepaymentWorkbook.createName(); + paymentTypeGroup.setNameName("PaymentTypes"); + paymentTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME+"!$D$2:$D$" + (extrasSheetPopulator.getPaymentTypesSize() + 1)); + } + + private void populateLoansTable(Sheet loanRepaymentSheet,String dateFormat) { + int rowIndex = 1; + Row row; + Workbook workbook = loanRepaymentSheet.getWorkbook(); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + SimpleDateFormat outputFormat = new SimpleDateFormat(dateFormat); + SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date date = null; + Collections.sort(allloans,new LoanComparatorByStatusActive()); + for (LoanAccountData loan : allloans) { + row = loanRepaymentSheet.createRow(rowIndex++); + writeString(LoanRepaymentConstants.LOOKUP_CLIENT_NAME_COL, row, loan.getClientName() + "(" + loan.getClientId() + ")"); + writeString(LoanRepaymentConstants.LOOKUP_CLIENT_EXTERNAL_ID,row, clientIdToClientExternalId.get(loan.getClientId())); + writeString(LoanRepaymentConstants.LOOKUP_ACCOUNT_NO_COL, row, Long.parseLong(loan.getAccountNo())+"-"+loan.getStatusStringValue()); + writeString(LoanRepaymentConstants.LOOKUP_PRODUCT_COL, row, loan.getLoanProductName()); + writeDouble(LoanRepaymentConstants.LOOKUP_PRINCIPAL_COL, row, loan.getPrincipal().doubleValue()); + if (loan.getDisbursementDate() != null) { + try { + date = inputFormat.parse(loan.getDisbursementDate().toString()); + } catch (ParseException e) { + e.printStackTrace(); + } + writeDate(LoanRepaymentConstants.LOOKUP_LOAN_DISBURSEMENT_DATE_COL, row, + outputFormat.format(date), dateCellStyle,dateFormat); + } + } + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(LoanRepaymentConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.CLIENT_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.CLIENT_EXTERNAL_ID,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.LOAN_ACCOUNT_NO_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.PRODUCT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.PRINCIPAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.AMOUNT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.REPAID_ON_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.REPAYMENT_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.ACCOUNT_NO_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.CHECK_NO_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.RECEIPT_NO_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.ROUTING_CODE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.BANK_NO_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.LOOKUP_CLIENT_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.LOOKUP_CLIENT_EXTERNAL_ID,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.LOOKUP_ACCOUNT_NO_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.LOOKUP_PRODUCT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.LOOKUP_PRINCIPAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(LoanRepaymentConstants.LOOKUP_LOAN_DISBURSEMENT_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(LoanRepaymentConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(LoanRepaymentConstants.CLIENT_NAME_COL, rowHeader, "Client Name*"); + writeString(LoanRepaymentConstants.CLIENT_EXTERNAL_ID,rowHeader,"Client Ext.Id"); + writeString(LoanRepaymentConstants.LOAN_ACCOUNT_NO_COL, rowHeader, "Loan Account No.*"); + writeString(LoanRepaymentConstants.PRODUCT_COL, rowHeader, "Product Name"); + writeString(LoanRepaymentConstants.PRINCIPAL_COL, rowHeader, "Principal"); + writeString(LoanRepaymentConstants.AMOUNT_COL, rowHeader, "Amount Repaid*"); + writeString(LoanRepaymentConstants.REPAID_ON_DATE_COL, rowHeader, "Date*"); + writeString(LoanRepaymentConstants.REPAYMENT_TYPE_COL, rowHeader, "Type*"); + writeString(LoanRepaymentConstants.ACCOUNT_NO_COL, rowHeader, "Account No"); + writeString(LoanRepaymentConstants.CHECK_NO_COL, rowHeader, "Check No"); + writeString(LoanRepaymentConstants.RECEIPT_NO_COL, rowHeader, "Receipt No"); + writeString(LoanRepaymentConstants.ROUTING_CODE_COL, rowHeader, "Routing Code"); + writeString(LoanRepaymentConstants.BANK_NO_COL, rowHeader, "Bank No"); + writeString(LoanRepaymentConstants.LOOKUP_CLIENT_NAME_COL, rowHeader, "Lookup Client"); + writeString(LoanRepaymentConstants.LOOKUP_CLIENT_EXTERNAL_ID,rowHeader,"Lookup ClientExtId"); + writeString(LoanRepaymentConstants.LOOKUP_ACCOUNT_NO_COL, rowHeader, "Lookup Account"); + writeString(LoanRepaymentConstants.LOOKUP_PRODUCT_COL, rowHeader, "Lookup Product"); + writeString(LoanRepaymentConstants.LOOKUP_PRINCIPAL_COL, rowHeader, "Lookup Principal"); + writeString(LoanRepaymentConstants.LOOKUP_LOAN_DISBURSEMENT_DATE_COL, rowHeader, "Lookup Loan Disbursement Date"); + + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/office/OfficeWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/office/OfficeWorkbookPopulator.java new file mode 100644 index 000000000..977a23ad8 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/office/OfficeWorkbookPopulator.java @@ -0,0 +1,114 @@ +/** + * 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.populator.office; + +import org.apache.fineract.infrastructure.bulkimport.constants.OfficeConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator; +import org.apache.fineract.organisation.office.data.OfficeData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.List; + +public class OfficeWorkbookPopulator extends AbstractWorkbookPopulator { + private List offices; + + public OfficeWorkbookPopulator(List offices) { + this.offices=offices; + } + + @Override + public void populate(final Workbook workbook,final String dateFormat) { + Sheet officeSheet=workbook.createSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + setLayout(officeSheet); + setLookupTable(officeSheet); + setRules(officeSheet,dateFormat); + setDefaults(officeSheet); + } + + private void setLookupTable(final Sheet officeSheet) { + int rowIndex=1; + for (OfficeData office:offices) { + Row row=officeSheet.createRow(rowIndex); + writeString(OfficeConstants.LOOKUP_OFFICE_COL,row,office.name()); + writeLong(OfficeConstants.LOOKUP_OFFICE_ID_COL,row,office.getId()); + rowIndex++; + } + } + + private void setLayout(final Sheet worksheet){ + Row rowHeader=worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + worksheet.setColumnWidth(OfficeConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(OfficeConstants.PARENT_OFFICE_NAME_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(OfficeConstants.PARENT_OFFICE_ID_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(OfficeConstants.OPENED_ON_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(OfficeConstants.EXTERNAL_ID_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(OfficeConstants.LOOKUP_OFFICE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(OfficeConstants.LOOKUP_OFFICE_ID_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + + writeString(OfficeConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(OfficeConstants.PARENT_OFFICE_NAME_COL, rowHeader, "Parent Office*"); + writeString(OfficeConstants.PARENT_OFFICE_ID_COL,rowHeader,"Parent OfficeId*"); + writeString(OfficeConstants.OPENED_ON_COL, rowHeader, "Opened On Date*"); + writeString(OfficeConstants.EXTERNAL_ID_COL, rowHeader, "External Id*"); + writeString(OfficeConstants.LOOKUP_OFFICE_COL, rowHeader, "Lookup Offices"); + writeString(OfficeConstants.LOOKUP_OFFICE_ID_COL,rowHeader, "Lookup OfficeId*"); + } + + private void setRules(Sheet workSheet, final String dateFormat){ + CellRangeAddressList parentOfficeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + OfficeConstants.PARENT_OFFICE_NAME_COL, OfficeConstants.PARENT_OFFICE_NAME_COL); + CellRangeAddressList OpenedOndateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + OfficeConstants.OPENED_ON_COL,OfficeConstants.OPENED_ON_COL); + + DataValidationHelper validationHelper=new HSSFDataValidationHelper((HSSFSheet) workSheet); + setNames(workSheet); + + DataValidationConstraint parentOfficeNameConstraint=validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint openDateConstraint=validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.LESS_OR_EQUAL,"=TODAY()",null,dateFormat); + + DataValidation parentOfficeValidation=validationHelper.createValidation(parentOfficeNameConstraint,parentOfficeNameRange); + DataValidation openDateValidation=validationHelper.createValidation(openDateConstraint,OpenedOndateRange); + + workSheet.addValidationData(parentOfficeValidation); + workSheet.addValidationData(openDateValidation); + } + + private void setNames(final Sheet workSheet) { + Workbook officeWorkbook=workSheet.getWorkbook(); + Name parentOffice=officeWorkbook.createName(); + parentOffice.setNameName("Office"); + parentOffice.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$H$2:$H$"+(offices.size()+1)); + } + + private void setDefaults(final Sheet worksheet) { + for (Integer rowNo = 1; rowNo < 3000; rowNo++) { + Row row = worksheet.getRow(rowNo); + if (row == null) + row = worksheet.createRow(rowNo); + writeFormula(OfficeConstants.PARENT_OFFICE_ID_COL, row, + "IF(ISERROR(VLOOKUP($B"+(rowNo+1)+",$H$2:$I$"+(offices.size()+1)+",2,FALSE)),\"\",(VLOOKUP($B"+(rowNo+1)+",$H$2:$I$"+(offices.size()+1)+",2,FALSE)))"); + } + + } +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/recurringdeposit/RecurringDepositTransactionWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/recurringdeposit/RecurringDepositTransactionWorkbookPopulator.java new file mode 100644 index 000000000..d462b5f65 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/recurringdeposit/RecurringDepositTransactionWorkbookPopulator.java @@ -0,0 +1,242 @@ +/** + * 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.populator.recurringdeposit; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TransactionConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.ClientSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.ExtrasSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.OfficeSheetPopulator; +import org.apache.fineract.portfolio.savings.data.SavingsAccountData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; + +public class RecurringDepositTransactionWorkbookPopulator extends AbstractWorkbookPopulator { + + private OfficeSheetPopulator officeSheetPopulator; + private ClientSheetPopulator clientSheetPopulator; + private ExtrasSheetPopulator extrasSheetPopulator; + + private ListsavingsAccounts; + + public RecurringDepositTransactionWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, + ClientSheetPopulator clientSheetPopulator, ExtrasSheetPopulator extrasSheetPopulator, + List savingsAccounts) { + this.officeSheetPopulator = officeSheetPopulator; + this.clientSheetPopulator = clientSheetPopulator; + this.extrasSheetPopulator = extrasSheetPopulator; + this.savingsAccounts=savingsAccounts; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet savingsTransactionSheet = workbook.createSheet(TemplatePopulateImportConstants.SAVINGS_TRANSACTION_SHEET_NAME); + setLayout(savingsTransactionSheet); + officeSheetPopulator.populate(workbook,dateFormat); + clientSheetPopulator.populate(workbook,dateFormat); + extrasSheetPopulator.populate(workbook,dateFormat); + populateSavingsTable(savingsTransactionSheet,dateFormat); + setRules(savingsTransactionSheet,dateFormat); + setDefaults(savingsTransactionSheet); + } + + private void setDefaults(Sheet worksheet) { + for(Integer rowNo = 1; rowNo < 3000; rowNo++) + { + Row row = worksheet.getRow(rowNo); + if(row == null) + row = worksheet.createRow(rowNo); + writeFormula(TransactionConstants.PRODUCT_COL, row, "IF(ISERROR(VLOOKUP($C"+ (rowNo+1) +",$Q$2:$S$" + (savingsAccounts.size() + 1) + ",2,FALSE)),\"\",VLOOKUP($C"+ (rowNo+1) +",$Q$2:$S$" + (savingsAccounts.size() + 1) + ",2,FALSE))"); + writeFormula(TransactionConstants.OPENING_BALANCE_COL, row, "IF(ISERROR(VLOOKUP($C"+ (rowNo+1) +",$Q$2:$S$" + (savingsAccounts.size() + 1) + ",3,FALSE)),\"\",VLOOKUP($C"+ (rowNo+1) +",$Q$2:$S$" + (savingsAccounts.size() + 1) + ",3,FALSE))"); + } + } + + + private void setRules(Sheet worksheet,String dateFormat) { + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.OFFICE_NAME_COL, TransactionConstants.OFFICE_NAME_COL); + CellRangeAddressList clientNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.CLIENT_NAME_COL, TransactionConstants.CLIENT_NAME_COL); + CellRangeAddressList accountNumberRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.SAVINGS_ACCOUNT_NO_COL, TransactionConstants.SAVINGS_ACCOUNT_NO_COL); + CellRangeAddressList transactionTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.TRANSACTION_TYPE_COL, TransactionConstants.TRANSACTION_TYPE_COL); + CellRangeAddressList paymentTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.PAYMENT_TYPE_COL, TransactionConstants.PAYMENT_TYPE_COL); + CellRangeAddressList transactionDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.TRANSACTION_DATE_COL, TransactionConstants.TRANSACTION_DATE_COL); + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet)worksheet); + + setNames(worksheet); + + DataValidationConstraint officeNameConstraint = validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint clientNameConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Client_\",$A1))"); + DataValidationConstraint accountNumberConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Account_\",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($B1,\" \",\"_\"),\"(\",\"_\"),\")\",\"_\")))"); + DataValidationConstraint transactionTypeConstraint = validationHelper.createExplicitListConstraint(new String[] {"Withdrawal","Deposit"}); + DataValidationConstraint paymentTypeConstraint = validationHelper.createFormulaListConstraint("PaymentTypes"); + DataValidationConstraint transactionDateConstraint = validationHelper.createDateConstraint + (DataValidationConstraint.OperatorType.BETWEEN, "=VLOOKUP($C1,$Q$2:$T$" + + (savingsAccounts.size() + 1) + ",4,FALSE)", "=TODAY()", dateFormat); + + DataValidation officeValidation = validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation clientValidation = validationHelper.createValidation(clientNameConstraint, clientNameRange); + DataValidation accountNumberValidation = validationHelper.createValidation(accountNumberConstraint, accountNumberRange); + DataValidation transactionTypeValidation = validationHelper.createValidation(transactionTypeConstraint, transactionTypeRange); + DataValidation paymentTypeValidation = validationHelper.createValidation(paymentTypeConstraint, paymentTypeRange); + DataValidation transactionDateValidation = validationHelper.createValidation(transactionDateConstraint, transactionDateRange); + + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(clientValidation); + worksheet.addValidationData(accountNumberValidation); + worksheet.addValidationData(transactionTypeValidation); + worksheet.addValidationData(paymentTypeValidation); + worksheet.addValidationData(transactionDateValidation); + } + + private void setNames(Sheet worksheet) { + Workbook savingsTransactionWorkbook = worksheet.getWorkbook(); + List officeNames = officeSheetPopulator.getOfficeNames(); + + //Office Names + Name officeGroup = savingsTransactionWorkbook.createName(); + officeGroup.setNameName("Office"); + officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (officeNames.size() + 1)); + + //Clients Named after Offices + for(Integer i = 0; i < officeNames.size(); i++) { + Integer[] officeNameToBeginEndIndexesOfClients = clientSheetPopulator.getOfficeNameToBeginEndIndexesOfClients().get(i); + Name name = savingsTransactionWorkbook.createName(); + if(officeNameToBeginEndIndexesOfClients != null) { + name.setNameName("Client_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + name.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfClients[0] + ":$B$" + officeNameToBeginEndIndexesOfClients[1]); + } + } + + //Counting clients with active savings and starting and end addresses of cells for naming + HashMap clientNameToBeginEndIndexes = new HashMap<>(); + ArrayList clientsWithActiveSavings = new ArrayList<>(); + ArrayList clientIdsWithActiveSavings = new ArrayList<>(); + int startIndex = 1, endIndex = 1; + String clientName = ""; + Long clientId = null; + for(int i = 0; i < savingsAccounts.size(); i++){ + if(!clientName.equals(savingsAccounts.get(i).getClientName())) { + endIndex = i + 1; + clientNameToBeginEndIndexes.put(clientName, new Integer[]{startIndex, endIndex}); + startIndex = i + 2; + clientName = savingsAccounts.get(i).getClientName(); + clientId = savingsAccounts.get(i).getClientId(); + clientsWithActiveSavings.add(clientName); + clientIdsWithActiveSavings.add(clientId); + } + if(i == savingsAccounts.size()-1) { + endIndex = i + 2; + clientNameToBeginEndIndexes.put(clientName, new Integer[]{startIndex, endIndex}); + } + } + + //Account Number Named after Clients + for(int j = 0; j < clientsWithActiveSavings.size(); j++) { + Name name = savingsTransactionWorkbook.createName(); + name.setNameName("Account_" + clientsWithActiveSavings.get(j).replaceAll(" ", "_") + "_" + clientIdsWithActiveSavings.get(j) + "_"); + name.setRefersToFormula(TemplatePopulateImportConstants.SAVINGS_TRANSACTION_SHEET_NAME+"!$Q$" + clientNameToBeginEndIndexes.get(clientsWithActiveSavings.get(j))[0] + ":$Q$" + clientNameToBeginEndIndexes.get(clientsWithActiveSavings.get(j))[1]); + } + + //Payment Type Name + Name paymentTypeGroup = savingsTransactionWorkbook.createName(); + paymentTypeGroup.setNameName("PaymentTypes"); + paymentTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME+"!$D$2:$D$" + (extrasSheetPopulator.getPaymentTypesSize() + 1)); + } + + private void populateSavingsTable(Sheet savingsTransactionSheet,String dateFormat) { + Workbook workbook = savingsTransactionSheet.getWorkbook(); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + int rowIndex = 1; + Row row; + Collections.sort(savingsAccounts, SavingsAccountData.ClientNameComparator); + for(SavingsAccountData savingsAccount : savingsAccounts) { + row = savingsTransactionSheet.createRow(rowIndex++); + writeString(TransactionConstants.LOOKUP_CLIENT_NAME_COL, row, savingsAccount.getClientName() + "(" + savingsAccount.getClientId() + ")"); + writeLong(TransactionConstants.LOOKUP_ACCOUNT_NO_COL, row, Long.parseLong(savingsAccount.getAccountNo())); + writeString(TransactionConstants.LOOKUP_PRODUCT_COL, row, savingsAccount.getSavingsProductName()); + if(savingsAccount.getMinRequiredOpeningBalance() != null) + writeBigDecimal(TransactionConstants.LOOKUP_OPENING_BALANCE_COL, row, savingsAccount.getMinRequiredOpeningBalance()); + writeDate(TransactionConstants.LOOKUP_SAVINGS_ACTIVATION_DATE_COL, row,"" + + savingsAccount.getTimeline().getActivatedOnDate().getDayOfMonth() + "/" + + savingsAccount.getTimeline().getActivatedOnDate().getMonthOfYear() + "/" + + savingsAccount.getTimeline().getActivatedOnDate().getYear() , dateCellStyle,dateFormat); + } + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(TransactionConstants.OFFICE_NAME_COL, 4000); + worksheet.setColumnWidth(TransactionConstants.CLIENT_NAME_COL, 5000); + worksheet.setColumnWidth(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.PRODUCT_COL, 4000); + worksheet.setColumnWidth(TransactionConstants.OPENING_BALANCE_COL, 4000); + worksheet.setColumnWidth(TransactionConstants.TRANSACTION_TYPE_COL, 3300); + worksheet.setColumnWidth(TransactionConstants.AMOUNT_COL, 4000); + worksheet.setColumnWidth(TransactionConstants.TRANSACTION_DATE_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.PAYMENT_TYPE_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.ACCOUNT_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.CHECK_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.RECEIPT_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.ROUTING_CODE_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.BANK_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_CLIENT_NAME_COL, 5000); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_ACCOUNT_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_PRODUCT_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_OPENING_BALANCE_COL, 3700); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_SAVINGS_ACTIVATION_DATE_COL, 3500); + writeString(TransactionConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(TransactionConstants.CLIENT_NAME_COL, rowHeader, "Client Name*"); + writeString(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, rowHeader, "Account No.*"); + writeString(TransactionConstants.PRODUCT_COL, rowHeader, "Product Name"); + writeString(TransactionConstants.OPENING_BALANCE_COL, rowHeader, "Opening Balance"); + writeString(TransactionConstants.TRANSACTION_TYPE_COL, rowHeader, "Transaction Type*"); + writeString(TransactionConstants.AMOUNT_COL, rowHeader, "Amount*"); + writeString(TransactionConstants.TRANSACTION_DATE_COL, rowHeader, "Date*"); + writeString(TransactionConstants.PAYMENT_TYPE_COL, rowHeader, "Type*"); + writeString(TransactionConstants.ACCOUNT_NO_COL, rowHeader, "Account No"); + writeString(TransactionConstants.CHECK_NO_COL, rowHeader, "Check No"); + writeString(TransactionConstants.RECEIPT_NO_COL, rowHeader, "Receipt No"); + writeString(TransactionConstants.ROUTING_CODE_COL, rowHeader, "Routing Code"); + writeString(TransactionConstants.BANK_NO_COL, rowHeader, "Bank No"); + writeString(TransactionConstants.LOOKUP_CLIENT_NAME_COL, rowHeader, "Lookup Client"); + writeString(TransactionConstants.LOOKUP_ACCOUNT_NO_COL, rowHeader, "Lookup Account"); + writeString(TransactionConstants.LOOKUP_PRODUCT_COL, rowHeader, "Lookup Product"); + writeString(TransactionConstants.LOOKUP_OPENING_BALANCE_COL, rowHeader, "Lookup Opening Balance"); + writeString(TransactionConstants.LOOKUP_SAVINGS_ACTIVATION_DATE_COL, rowHeader, "Lookup Savings Activation Date"); + } + } + diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/recurringdeposit/RecurringDepositWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/recurringdeposit/RecurringDepositWorkbookPopulator.java new file mode 100644 index 000000000..a034eeca6 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/recurringdeposit/RecurringDepositWorkbookPopulator.java @@ -0,0 +1,404 @@ +/** + * 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.populator.recurringdeposit; + +import org.apache.fineract.infrastructure.bulkimport.constants.RecurringDepositConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.*; +import org.apache.fineract.portfolio.savings.data.RecurringDepositProductData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.List; + +public class RecurringDepositWorkbookPopulator extends AbstractWorkbookPopulator { + + private OfficeSheetPopulator officeSheetPopulator; + private ClientSheetPopulator clientSheetPopulator; + private PersonnelSheetPopulator personnelSheetPopulator; + private RecurringDepositProductSheetPopulator productSheetPopulator; + + + public RecurringDepositWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, + ClientSheetPopulator clientSheetPopulator, PersonnelSheetPopulator personnelSheetPopulator, + RecurringDepositProductSheetPopulator recurringDepositProductSheetPopulator) { + + this.officeSheetPopulator = officeSheetPopulator; + this.clientSheetPopulator = clientSheetPopulator; + this.personnelSheetPopulator = personnelSheetPopulator; + this.productSheetPopulator = recurringDepositProductSheetPopulator; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet recurringDepositSheet = workbook.createSheet(TemplatePopulateImportConstants.RECURRING_DEPOSIT_SHEET_NAME); + officeSheetPopulator.populate(workbook,dateFormat); + clientSheetPopulator.populate(workbook,dateFormat); + personnelSheetPopulator.populate(workbook,dateFormat); + productSheetPopulator.populate(workbook,dateFormat); + setRules(recurringDepositSheet,dateFormat); + setDefaults(recurringDepositSheet,dateFormat); + setClientAndGroupDateLookupTable(recurringDepositSheet, clientSheetPopulator.getClients(), null, + RecurringDepositConstants.LOOKUP_CLIENT_NAME_COL, RecurringDepositConstants.LOOKUP_ACTIVATION_DATE_COL,!TemplatePopulateImportConstants.CONTAINS_CLIENT_EXTERNAL_ID,dateFormat); + setLayout(recurringDepositSheet); + + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(RecurringDepositConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.CLIENT_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.PRODUCT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.FIELD_OFFICER_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.SUBMITTED_ON_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.APPROVED_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.ACTIVATION_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.INTEREST_POSTING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.INTEREST_CALCULATION_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.LOCKIN_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.LOCKIN_PERIOD_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.RECURRING_DEPOSIT_AMOUNT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.DEPOSIT_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.DEPOSIT_PERIOD_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.DEPOSIT_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.DEPOSIT_FREQUENCY_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.DEPOSIT_START_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.IS_MANDATORY_DEPOSIT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.ALLOW_WITHDRAWAL_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.ADJUST_ADVANCE_PAYMENTS_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.FREQ_SAME_AS_GROUP_CENTER_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.EXTERNAL_ID_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + + worksheet.setColumnWidth(RecurringDepositConstants.CHARGE_ID_1, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.CHARGE_AMOUNT_1, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.CHARGE_DUE_DATE_1, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.CHARGE_ID_2, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.CHARGE_AMOUNT_2, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.CHARGE_DUE_DATE_2, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + + worksheet.setColumnWidth(RecurringDepositConstants.LOOKUP_CLIENT_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(RecurringDepositConstants.LOOKUP_ACTIVATION_DATE_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + + writeString(RecurringDepositConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(RecurringDepositConstants.CLIENT_NAME_COL, rowHeader, "Client Name*"); + writeString(RecurringDepositConstants.PRODUCT_COL, rowHeader, "Product*"); + writeString(RecurringDepositConstants.FIELD_OFFICER_NAME_COL, rowHeader, "Field Officer*"); + writeString(RecurringDepositConstants.SUBMITTED_ON_DATE_COL, rowHeader, "Submitted On*"); + writeString(RecurringDepositConstants.APPROVED_DATE_COL, rowHeader, "Approved On*"); + writeString(RecurringDepositConstants.ACTIVATION_DATE_COL, rowHeader, "Activation Date*"); + writeString(RecurringDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL, rowHeader, "Interest Compounding Period*"); + writeString(RecurringDepositConstants.INTEREST_POSTING_PERIOD_COL, rowHeader, "Interest Posting Period*"); + writeString(RecurringDepositConstants.INTEREST_CALCULATION_COL, rowHeader, "Interest Calculated*"); + writeString(RecurringDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, rowHeader, "# Days in Year*"); + writeString(RecurringDepositConstants.LOCKIN_PERIOD_COL, rowHeader, "Locked In For"); + writeString(RecurringDepositConstants.RECURRING_DEPOSIT_AMOUNT_COL, rowHeader, "Recurring Deposit Amount"); + writeString(RecurringDepositConstants.DEPOSIT_PERIOD_COL, rowHeader, "Deposit Period"); + writeString(RecurringDepositConstants.DEPOSIT_FREQUENCY_COL, rowHeader, "Deposit Frequency"); + writeString(RecurringDepositConstants.DEPOSIT_START_DATE_COL, rowHeader, "Deposit Start Date"); + writeString(RecurringDepositConstants.IS_MANDATORY_DEPOSIT_COL, rowHeader, "Is Mandatory Deposit?"); + writeString(RecurringDepositConstants.ALLOW_WITHDRAWAL_COL, rowHeader, "Allow Withdrawal?"); + writeString(RecurringDepositConstants.ADJUST_ADVANCE_PAYMENTS_COL, rowHeader, "Adjust Advance Payments Toward Future Installments "); + writeString(RecurringDepositConstants.FREQ_SAME_AS_GROUP_CENTER_COL, rowHeader, "Deposit Frequency Same as Group/Center meeting"); + writeString(RecurringDepositConstants.EXTERNAL_ID_COL, rowHeader, "External Id"); + + writeString(RecurringDepositConstants.CHARGE_ID_1,rowHeader,"Charge Id"); + writeString(RecurringDepositConstants.CHARGE_AMOUNT_1, rowHeader, "Charged Amount"); + writeString(RecurringDepositConstants.CHARGE_DUE_DATE_1, rowHeader, "Charged On Date"); + writeString(RecurringDepositConstants.CHARGE_ID_2,rowHeader,"Charge Id"); + writeString(RecurringDepositConstants.CHARGE_AMOUNT_2, rowHeader, "Charged Amount"); + writeString(RecurringDepositConstants.CHARGE_DUE_DATE_2, rowHeader, "Charged On Date"); + + writeString(RecurringDepositConstants.LOOKUP_CLIENT_NAME_COL, rowHeader, "Client Name"); + writeString(RecurringDepositConstants.LOOKUP_ACTIVATION_DATE_COL, rowHeader, "Client Activation Date"); + } + + private void setDefaults(Sheet worksheet,String dateFormat) { + Workbook workbook = worksheet.getWorkbook(); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + for (Integer rowNo = 1; rowNo < 1000; rowNo++) { + Row row = worksheet.createRow(rowNo); + writeFormula(RecurringDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Interest_Compouding_\",$C" + + (rowNo + 1) + "))),\"\",INDIRECT(CONCATENATE(\"Interest_Compouding_\",$C" + (rowNo + 1) + ")))"); + writeFormula(RecurringDepositConstants.INTEREST_POSTING_PERIOD_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Interest_Posting_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Interest_Posting_\",$C" + (rowNo + 1) + ")))"); + writeFormula(RecurringDepositConstants.INTEREST_CALCULATION_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Interest_Calculation_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Interest_Calculation_\",$C" + (rowNo + 1) + ")))"); + writeFormula(RecurringDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Days_In_Year_\",$C" + + (rowNo + 1) + "))),\"\",INDIRECT(CONCATENATE(\"Days_In_Year_\",$C" + (rowNo + 1) + ")))"); + writeFormula(RecurringDepositConstants.LOCKIN_PERIOD_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Lockin_Period_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Lockin_Period_\",$C" + (rowNo + 1) + ")))"); + writeFormula(RecurringDepositConstants.LOCKIN_PERIOD_FREQUENCY_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Lockin_Frequency_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Lockin_Frequency_\",$C" + (rowNo + 1) + ")))"); + writeFormula(RecurringDepositConstants.RECURRING_DEPOSIT_AMOUNT_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Deposit_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Deposit_\",$C" + (rowNo + 1) + ")))"); + writeFormula(RecurringDepositConstants.DEPOSIT_PERIOD_FREQUENCY_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Term_Type_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Term_Type_\",$C" + (rowNo + 1) + ")))"); + writeFormula(RecurringDepositConstants.IS_MANDATORY_DEPOSIT_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Mandatory_Deposit_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Mandatory_Deposit_\",$C" + (rowNo + 1) + ")))"); + writeFormula(RecurringDepositConstants.ALLOW_WITHDRAWAL_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Allow_Withdrawal_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Allow_Withdrawal_\",$C" + (rowNo + 1) + ")))"); + writeFormula(RecurringDepositConstants.ADJUST_ADVANCE_PAYMENTS_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Adjust_Advance_\",$C" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Adjust_Advance_\",$C" + (rowNo + 1) + ")))"); + } + } + + private void setRules(Sheet worksheet,String dateFormat) { + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.OFFICE_NAME_COL, RecurringDepositConstants.OFFICE_NAME_COL); + CellRangeAddressList clientNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.CLIENT_NAME_COL, RecurringDepositConstants.CLIENT_NAME_COL); + CellRangeAddressList productNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.PRODUCT_COL, RecurringDepositConstants.PRODUCT_COL); + CellRangeAddressList fieldOfficerRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.FIELD_OFFICER_NAME_COL, RecurringDepositConstants.FIELD_OFFICER_NAME_COL); + CellRangeAddressList submittedDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.SUBMITTED_ON_DATE_COL, RecurringDepositConstants.SUBMITTED_ON_DATE_COL); + CellRangeAddressList approvedDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.APPROVED_DATE_COL, RecurringDepositConstants.APPROVED_DATE_COL); + CellRangeAddressList activationDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.ACTIVATION_DATE_COL, RecurringDepositConstants.ACTIVATION_DATE_COL); + CellRangeAddressList interestCompudingPeriodRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL, RecurringDepositConstants.INTEREST_COMPOUNDING_PERIOD_COL); + CellRangeAddressList interestPostingPeriodRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.INTEREST_POSTING_PERIOD_COL, RecurringDepositConstants.INTEREST_POSTING_PERIOD_COL); + CellRangeAddressList interestCalculationRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.INTEREST_CALCULATION_COL, RecurringDepositConstants.INTEREST_CALCULATION_COL); + CellRangeAddressList interestCalculationDaysInYearRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), RecurringDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, + RecurringDepositConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL); + CellRangeAddressList lockinPeriodFrequencyRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.LOCKIN_PERIOD_FREQUENCY_COL, RecurringDepositConstants.LOCKIN_PERIOD_FREQUENCY_COL); + CellRangeAddressList depositAmountRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.RECURRING_DEPOSIT_AMOUNT_COL,RecurringDepositConstants. RECURRING_DEPOSIT_AMOUNT_COL); + CellRangeAddressList depositPeriodTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.DEPOSIT_PERIOD_FREQUENCY_COL, RecurringDepositConstants.DEPOSIT_PERIOD_FREQUENCY_COL); + CellRangeAddressList depositFrequencyTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.DEPOSIT_FREQUENCY_TYPE_COL, RecurringDepositConstants.DEPOSIT_FREQUENCY_TYPE_COL); + CellRangeAddressList isMandatoryDepositRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants. IS_MANDATORY_DEPOSIT_COL, RecurringDepositConstants.IS_MANDATORY_DEPOSIT_COL); + CellRangeAddressList allowWithdrawalRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.ALLOW_WITHDRAWAL_COL, RecurringDepositConstants.ALLOW_WITHDRAWAL_COL); + CellRangeAddressList adjustAdvancePaymentRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants. ADJUST_ADVANCE_PAYMENTS_COL, RecurringDepositConstants.ADJUST_ADVANCE_PAYMENTS_COL); + CellRangeAddressList sameFreqAsGroupRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.FREQ_SAME_AS_GROUP_CENTER_COL, RecurringDepositConstants.FREQ_SAME_AS_GROUP_CENTER_COL); + CellRangeAddressList depositStartDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + RecurringDepositConstants.DEPOSIT_START_DATE_COL, RecurringDepositConstants.DEPOSIT_START_DATE_COL); + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet) worksheet); + + setNames(worksheet); + + DataValidationConstraint officeNameConstraint = validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint clientNameConstraint = validationHelper + .createFormulaListConstraint("INDIRECT(CONCATENATE(\"Client_\",$A1))"); + DataValidationConstraint productNameConstraint = validationHelper.createFormulaListConstraint("Products"); + DataValidationConstraint fieldOfficerNameConstraint = validationHelper + .createFormulaListConstraint("INDIRECT(CONCATENATE(\"Staff_\",$A1))"); + DataValidationConstraint submittedDateConstraint = validationHelper.createDateConstraint( + DataValidationConstraint.OperatorType.BETWEEN, "=VLOOKUP($B1,$AF$2:$AG$" + + (clientSheetPopulator.getClientsSize() + 1) + ",2,FALSE)", "=TODAY()", + dateFormat); + DataValidationConstraint approvalDateConstraint = validationHelper.createDateConstraint( + DataValidationConstraint.OperatorType.BETWEEN, "=$E1", "=TODAY()", dateFormat); + DataValidationConstraint activationDateConstraint = validationHelper.createDateConstraint( + DataValidationConstraint.OperatorType.BETWEEN, "=$F1", "=TODAY()", dateFormat); + DataValidationConstraint interestCompudingPeriodConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_DAILY , + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_MONTHLY, + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_QUARTERLY, + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_SEMI_ANNUALLY, + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_ANNUALLY}); + DataValidationConstraint interestPostingPeriodConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_MONTHLY , + TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_QUARTERLY, + TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_BIANUALLY, + TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_ANNUALLY }); + DataValidationConstraint interestCalculationConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.INTEREST_CAL_DAILY_BALANCE, + TemplatePopulateImportConstants.INTEREST_CAL_AVG_BALANCE}); + + DataValidationConstraint interestCalculationDaysInYearConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.INTEREST_CAL_DAYS_IN_YEAR_360, + TemplatePopulateImportConstants.INTEREST_CAL_DAYS_IN_YEAR_365}); + DataValidationConstraint frequency = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.FREQUENCY_DAYS, + TemplatePopulateImportConstants.FREQUENCY_WEEKS, + TemplatePopulateImportConstants.FREQUENCY_MONTHS, + TemplatePopulateImportConstants.FREQUENCY_YEARS}); + DataValidationConstraint depositConstraint = validationHelper.createDecimalConstraint(DataValidationConstraint.OperatorType.GREATER_OR_EQUAL, "=INDIRECT(CONCATENATE(\"Min_Deposit_\",$C1))", null); + DataValidationConstraint booleanConstraint = validationHelper.createExplicitListConstraint(new String[] { + "True", "False" }); + DataValidationConstraint depositStartDateConstraint = validationHelper.createDateConstraint( + DataValidationConstraint.OperatorType.BETWEEN, "=$G1", "=TODAY()", "dd/mm/yy"); + + DataValidation officeValidation = validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation clientValidation = validationHelper.createValidation(clientNameConstraint, clientNameRange); + DataValidation productNameValidation = validationHelper.createValidation(productNameConstraint, productNameRange); + DataValidation fieldOfficerValidation = validationHelper.createValidation(fieldOfficerNameConstraint, fieldOfficerRange); + DataValidation interestCompudingPeriodValidation = validationHelper.createValidation(interestCompudingPeriodConstraint, + interestCompudingPeriodRange); + DataValidation interestPostingPeriodValidation = validationHelper.createValidation(interestPostingPeriodConstraint, + interestPostingPeriodRange); + DataValidation interestCalculationValidation = validationHelper.createValidation(interestCalculationConstraint, + interestCalculationRange); + DataValidation interestCalculationDaysInYearValidation = validationHelper.createValidation( + interestCalculationDaysInYearConstraint, interestCalculationDaysInYearRange); + DataValidation lockinPeriodFrequencyValidation = validationHelper.createValidation(frequency, + lockinPeriodFrequencyRange); + DataValidation depositPeriodTypeValidation = validationHelper.createValidation(frequency, + depositPeriodTypeRange); + DataValidation depositFrequencyTypeValidation = validationHelper.createValidation(frequency, + depositFrequencyTypeRange); + DataValidation submittedDateValidation = validationHelper.createValidation(submittedDateConstraint, submittedDateRange); + DataValidation approvalDateValidation = validationHelper.createValidation(approvalDateConstraint, approvedDateRange); + DataValidation activationDateValidation = validationHelper.createValidation(activationDateConstraint, activationDateRange); + DataValidation depositAmountValidation = validationHelper.createValidation(depositConstraint, depositAmountRange); + DataValidation isMandatoryDepositValidation = validationHelper.createValidation( + booleanConstraint, isMandatoryDepositRange); + DataValidation allowWithdrawalValidation = validationHelper.createValidation( + booleanConstraint, allowWithdrawalRange); + DataValidation adjustAdvancePaymentValidation = validationHelper.createValidation( + booleanConstraint, adjustAdvancePaymentRange); + DataValidation sameFreqAsGroupValidation = validationHelper.createValidation( + booleanConstraint, sameFreqAsGroupRange); + DataValidation depositStartDateValidation = validationHelper.createValidation( + depositStartDateConstraint, depositStartDateRange); + + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(clientValidation); + worksheet.addValidationData(productNameValidation); + worksheet.addValidationData(fieldOfficerValidation); + worksheet.addValidationData(submittedDateValidation); + worksheet.addValidationData(approvalDateValidation); + worksheet.addValidationData(activationDateValidation); + worksheet.addValidationData(interestCompudingPeriodValidation); + worksheet.addValidationData(interestPostingPeriodValidation); + worksheet.addValidationData(interestCalculationValidation); + worksheet.addValidationData(interestCalculationDaysInYearValidation); + worksheet.addValidationData(lockinPeriodFrequencyValidation); + worksheet.addValidationData(depositPeriodTypeValidation); + worksheet.addValidationData(depositAmountValidation); + worksheet.addValidationData(depositFrequencyTypeValidation); + worksheet.addValidationData(isMandatoryDepositValidation); + worksheet.addValidationData(allowWithdrawalValidation); + worksheet.addValidationData(adjustAdvancePaymentValidation); + worksheet.addValidationData(sameFreqAsGroupValidation); + worksheet.addValidationData(depositStartDateValidation); + } + + private void setNames(Sheet worksheet) { + Workbook savingsWorkbook = worksheet.getWorkbook(); + List officeNames = officeSheetPopulator.getOfficeNames(); + List products = productSheetPopulator.getProducts(); + + // Office Names + Name officeGroup = savingsWorkbook.createName(); + officeGroup.setNameName("Office"); + officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (officeNames.size() + 1)); + + // Client and Loan Officer Names for each office + for (Integer i = 0; i < officeNames.size(); i++) { + Integer[] officeNameToBeginEndIndexesOfClients = clientSheetPopulator.getOfficeNameToBeginEndIndexesOfClients().get(i); + Integer[] officeNameToBeginEndIndexesOfStaff = personnelSheetPopulator.getOfficeNameToBeginEndIndexesOfStaff().get(i); + Name clientName = savingsWorkbook.createName(); + Name fieldOfficerName = savingsWorkbook.createName(); + if (officeNameToBeginEndIndexesOfStaff != null) { + fieldOfficerName.setNameName("Staff_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + fieldOfficerName.setRefersToFormula(TemplatePopulateImportConstants.STAFF_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfStaff[0] + ":$B$" + + officeNameToBeginEndIndexesOfStaff[1]); + } + if (officeNameToBeginEndIndexesOfClients != null) { + clientName.setNameName("Client_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + clientName.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfClients[0] + ":$B$" + + officeNameToBeginEndIndexesOfClients[1]); + } + } + + // Product Name + Name productGroup = savingsWorkbook.createName(); + productGroup.setNameName("Products"); + productGroup.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$B$2:$B$" + (productSheetPopulator.getProductsSize() + 1)); + + // Default Interest Rate, Interest Compounding Period, Interest Posting + // Period, Interest Calculation, Interest Calculation Days In Year, + // Minimum Deposit, Lockin Period, Lockin Period Frequency + // Names for each product + for (Integer i = 0; i < products.size(); i++) { + Name interestCompoundingPeriodName = savingsWorkbook.createName(); + Name interestPostingPeriodName = savingsWorkbook.createName(); + Name interestCalculationName = savingsWorkbook.createName(); + Name daysInYearName = savingsWorkbook.createName(); + Name lockinPeriodName = savingsWorkbook.createName(); + Name lockinPeriodFrequencyName = savingsWorkbook.createName(); + Name depositName = savingsWorkbook.createName(); + Name minDepositName = savingsWorkbook.createName(); + Name maxDepositName = savingsWorkbook.createName(); + Name minDepositTermTypeName = savingsWorkbook.createName(); + Name allowWithdrawalName = savingsWorkbook.createName(); + Name mandatoryDepositName = savingsWorkbook.createName(); + Name adjustAdvancePaymentsName = savingsWorkbook.createName(); + + RecurringDepositProductData product = products.get(i); + String productName = product.getName().replaceAll("[ ]", "_"); + + interestCompoundingPeriodName.setNameName("Interest_Compouding_" + productName); + interestPostingPeriodName.setNameName("Interest_Posting_" + productName); + interestCalculationName.setNameName("Interest_Calculation_" + productName); + daysInYearName.setNameName("Days_In_Year_" + productName); + minDepositName.setNameName("Min_Deposit_" + productName); + maxDepositName.setNameName("Max_Deposit_" + productName); + depositName.setNameName("Deposit_" + productName); + allowWithdrawalName.setNameName("Allow_Withdrawal_" + productName); + mandatoryDepositName.setNameName("Mandatory_Deposit_" + productName); + adjustAdvancePaymentsName.setNameName("Adjust_Advance_" + productName); + interestCompoundingPeriodName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$E$" + (i + 2)); + interestPostingPeriodName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$F$" + (i + 2)); + interestCalculationName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$G$" + (i + 2)); + daysInYearName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$H$" + (i + 2)); + depositName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$N$" + (i + 2)); + minDepositName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$L$" + (i + 2)); + maxDepositName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$M$" + (i + 2)); + allowWithdrawalName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$Y$" + (i + 2)); + mandatoryDepositName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$X$" + (i + 2)); + adjustAdvancePaymentsName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$Z$" + (i + 2)); + + if(product.getMinDepositTermType() != null) { + minDepositTermTypeName.setNameName("Term_Type_" + productName); + minDepositTermTypeName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$P$" + (i + 2)); + } + if (product.getLockinPeriodFrequency() != null) { + lockinPeriodName.setNameName("Lockin_Period_" + productName); + lockinPeriodName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$I$" + (i + 2)); + } + if (product.getLockinPeriodFrequencyType() != null) { + lockinPeriodFrequencyName.setNameName("Lockin_Frequency_" + productName); + lockinPeriodFrequencyName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$J$" + (i + 2)); + } + } + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/savings/SavingsTransactionsWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/savings/SavingsTransactionsWorkbookPopulator.java new file mode 100644 index 000000000..2573b7106 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/savings/SavingsTransactionsWorkbookPopulator.java @@ -0,0 +1,240 @@ +/** + * 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.populator.savings; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TransactionConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.ClientSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.ExtrasSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.OfficeSheetPopulator; +import org.apache.fineract.portfolio.savings.data.SavingsAccountData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; + +public class SavingsTransactionsWorkbookPopulator extends AbstractWorkbookPopulator { + private OfficeSheetPopulator officeSheetPopulator; + private ClientSheetPopulator clientSheetPopulator; + private ExtrasSheetPopulator extrasSheetPopulator; + + private ListsavingsAccounts; + + public SavingsTransactionsWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, + ClientSheetPopulator clientSheetPopulator, ExtrasSheetPopulator extrasSheetPopulator, + List savingsAccounts) { + this.officeSheetPopulator = officeSheetPopulator; + this.clientSheetPopulator = clientSheetPopulator; + this.extrasSheetPopulator = extrasSheetPopulator; + this.savingsAccounts=savingsAccounts; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet savingsTransactionSheet = workbook.createSheet(TemplatePopulateImportConstants.SAVINGS_TRANSACTION_SHEET_NAME); + setLayout(savingsTransactionSheet); + officeSheetPopulator.populate(workbook,dateFormat); + clientSheetPopulator.populate(workbook,dateFormat); + extrasSheetPopulator.populate(workbook,dateFormat); + populateSavingsTable(savingsTransactionSheet,dateFormat); + setRules(savingsTransactionSheet,dateFormat); + setDefaults(savingsTransactionSheet); + } + + private void setDefaults(Sheet worksheet) { + for(Integer rowNo = 1; rowNo < 3000; rowNo++) + { + Row row = worksheet.getRow(rowNo); + if(row == null) + row = worksheet.createRow(rowNo); + writeFormula(TransactionConstants.PRODUCT_COL, row, "IF(ISERROR(VLOOKUP($C"+ (rowNo+1) +",$Q$2:$S$" + (savingsAccounts.size() + 1) + ",2,FALSE)),\"\",VLOOKUP($C"+ (rowNo+1) +",$Q$2:$S$" + (savingsAccounts.size() + 1) + ",2,FALSE))"); + writeFormula(TransactionConstants.OPENING_BALANCE_COL, row, "IF(ISERROR(VLOOKUP($C"+ (rowNo+1) +",$Q$2:$S$" + (savingsAccounts.size() + 1) + ",3,FALSE)),\"\",VLOOKUP($C"+ (rowNo+1) +",$Q$2:$S$" + (savingsAccounts.size() + 1) + ",3,FALSE))"); + } + } + + + private void setRules(Sheet worksheet,String dateFormat) { + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.OFFICE_NAME_COL, TransactionConstants.OFFICE_NAME_COL); + CellRangeAddressList clientNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.CLIENT_NAME_COL, TransactionConstants.CLIENT_NAME_COL); + CellRangeAddressList accountNumberRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.SAVINGS_ACCOUNT_NO_COL, TransactionConstants.SAVINGS_ACCOUNT_NO_COL); + CellRangeAddressList transactionTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.TRANSACTION_TYPE_COL, TransactionConstants.TRANSACTION_TYPE_COL); + CellRangeAddressList paymentTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.PAYMENT_TYPE_COL, TransactionConstants.PAYMENT_TYPE_COL); + CellRangeAddressList transactionDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + TransactionConstants.TRANSACTION_DATE_COL, TransactionConstants.TRANSACTION_DATE_COL); + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet)worksheet); + + setNames(worksheet); + + DataValidationConstraint officeNameConstraint = validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint clientNameConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Client_\",$A1))"); + DataValidationConstraint accountNumberConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Account_\",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($B1,\" \",\"_\"),\"(\",\"_\"),\")\",\"_\")))"); + DataValidationConstraint transactionTypeConstraint = validationHelper.createExplicitListConstraint(new String[] {"Withdrawal","Deposit"}); + DataValidationConstraint paymentTypeConstraint = validationHelper.createFormulaListConstraint("PaymentTypes"); + DataValidationConstraint transactionDateConstraint = validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.BETWEEN, "=VLOOKUP($C1,$Q$2:$T$" + (savingsAccounts.size() + 1) + ",4,FALSE)", "=TODAY()",dateFormat); + + DataValidation officeValidation = validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation clientValidation = validationHelper.createValidation(clientNameConstraint, clientNameRange); + DataValidation accountNumberValidation = validationHelper.createValidation(accountNumberConstraint, accountNumberRange); + DataValidation transactionTypeValidation = validationHelper.createValidation(transactionTypeConstraint, transactionTypeRange); + DataValidation paymentTypeValidation = validationHelper.createValidation(paymentTypeConstraint, paymentTypeRange); + DataValidation transactionDateValidation = validationHelper.createValidation(transactionDateConstraint, transactionDateRange); + + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(clientValidation); + worksheet.addValidationData(accountNumberValidation); + worksheet.addValidationData(transactionTypeValidation); + worksheet.addValidationData(paymentTypeValidation); + worksheet.addValidationData(transactionDateValidation); + } + + private void setNames(Sheet worksheet) { + Workbook savingsTransactionWorkbook = worksheet.getWorkbook(); + List officeNames = officeSheetPopulator.getOfficeNames(); + + //Office Names + Name officeGroup = savingsTransactionWorkbook.createName(); + officeGroup.setNameName("Office"); + officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (officeNames.size() + 1)); + + //Clients Named after Offices + for(Integer i = 0; i < officeNames.size(); i++) { + Integer[] officeNameToBeginEndIndexesOfClients = clientSheetPopulator.getOfficeNameToBeginEndIndexesOfClients().get(i); + Name name = savingsTransactionWorkbook.createName(); + if(officeNameToBeginEndIndexesOfClients != null) { + name.setNameName("Client_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + name.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfClients[0] + ":$B$" + officeNameToBeginEndIndexesOfClients[1]); + } + } + + //Counting clients with active savings and starting and end addresses of cells for naming + HashMap clientNameToBeginEndIndexes = new HashMap<>(); + ArrayList clientsWithActiveSavings = new ArrayList<>(); + ArrayList clientIdsWithActiveSavings = new ArrayList<>(); + int startIndex = 1, endIndex = 1; + String clientName = ""; + Long clientId = null; + for(int i = 0; i < savingsAccounts.size(); i++){ + if(!clientName.equals(savingsAccounts.get(i).getClientName())) { + endIndex = i + 1; + clientNameToBeginEndIndexes.put(clientName, new Integer[]{startIndex, endIndex}); + startIndex = i + 2; + clientName = savingsAccounts.get(i).getClientName(); + clientId = savingsAccounts.get(i).getClientId(); + clientsWithActiveSavings.add(clientName); + clientIdsWithActiveSavings.add(clientId); + } + if(i == savingsAccounts.size()-1) { + endIndex = i + 2; + clientNameToBeginEndIndexes.put(clientName, new Integer[]{startIndex, endIndex}); + } + } + + //Account Number Named after Clients + for(int j = 0; j < clientsWithActiveSavings.size(); j++) { + Name name = savingsTransactionWorkbook.createName(); + name.setNameName("Account_" + clientsWithActiveSavings.get(j).replaceAll(" ", "_") + "_" + clientIdsWithActiveSavings.get(j) + "_"); + name.setRefersToFormula(TemplatePopulateImportConstants.SAVINGS_TRANSACTION_SHEET_NAME+"!$Q$" + clientNameToBeginEndIndexes.get(clientsWithActiveSavings.get(j))[0] + ":$Q$" + clientNameToBeginEndIndexes.get(clientsWithActiveSavings.get(j))[1]); + } + + //Payment Type Name + Name paymentTypeGroup = savingsTransactionWorkbook.createName(); + paymentTypeGroup.setNameName("PaymentTypes"); + paymentTypeGroup.setRefersToFormula(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME+"!$D$2:$D$" + (extrasSheetPopulator.getPaymentTypesSize() + 1)); + } + + private void populateSavingsTable(Sheet savingsTransactionSheet,String dateFormat) { + Workbook workbook = savingsTransactionSheet.getWorkbook(); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + int rowIndex = 1; + Row row; + Collections.sort(savingsAccounts, SavingsAccountData.ClientNameComparator); + for(SavingsAccountData savingsAccount : savingsAccounts) { + row = savingsTransactionSheet.createRow(rowIndex++); + writeString(TransactionConstants.LOOKUP_CLIENT_NAME_COL, row, savingsAccount.getClientName() + "(" + savingsAccount.getClientId() + ")"); + writeLong(TransactionConstants.LOOKUP_ACCOUNT_NO_COL, row, Long.parseLong(savingsAccount.getAccountNo())); + writeString(TransactionConstants.LOOKUP_PRODUCT_COL, row, savingsAccount.getSavingsProductName()); + if(savingsAccount.getMinRequiredOpeningBalance() != null) + writeBigDecimal(TransactionConstants.LOOKUP_OPENING_BALANCE_COL, row, savingsAccount.getMinRequiredOpeningBalance()); + writeDate(TransactionConstants.LOOKUP_SAVINGS_ACTIVATION_DATE_COL, row,"" + + savingsAccount.getTimeline().getActivatedOnDate().getDayOfMonth() + "/" + + savingsAccount.getTimeline().getActivatedOnDate().getMonthOfYear() + "/" + + savingsAccount.getTimeline().getActivatedOnDate().getYear() , dateCellStyle,dateFormat); + } + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(TransactionConstants.OFFICE_NAME_COL, 4000); + worksheet.setColumnWidth(TransactionConstants.CLIENT_NAME_COL, 5000); + worksheet.setColumnWidth(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.PRODUCT_COL, 4000); + worksheet.setColumnWidth(TransactionConstants.OPENING_BALANCE_COL, 4000); + worksheet.setColumnWidth(TransactionConstants.TRANSACTION_TYPE_COL, 3300); + worksheet.setColumnWidth(TransactionConstants.AMOUNT_COL, 4000); + worksheet.setColumnWidth(TransactionConstants.TRANSACTION_DATE_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.PAYMENT_TYPE_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.ACCOUNT_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.CHECK_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.RECEIPT_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.ROUTING_CODE_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.BANK_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_CLIENT_NAME_COL, 5000); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_ACCOUNT_NO_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_PRODUCT_COL, 3000); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_OPENING_BALANCE_COL, 3700); + worksheet.setColumnWidth(TransactionConstants.LOOKUP_SAVINGS_ACTIVATION_DATE_COL, 3500); + writeString(TransactionConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(TransactionConstants.CLIENT_NAME_COL, rowHeader, "Client Name*"); + writeString(TransactionConstants.SAVINGS_ACCOUNT_NO_COL, rowHeader, "Account No.*"); + writeString(TransactionConstants.PRODUCT_COL, rowHeader, "Product Name"); + writeString(TransactionConstants.OPENING_BALANCE_COL, rowHeader, "Opening Balance"); + writeString(TransactionConstants.TRANSACTION_TYPE_COL, rowHeader, "Transaction Type*"); + writeString(TransactionConstants.AMOUNT_COL, rowHeader, "Amount*"); + writeString(TransactionConstants.TRANSACTION_DATE_COL, rowHeader, "Date*"); + writeString(TransactionConstants.PAYMENT_TYPE_COL, rowHeader, "Type*"); + writeString(TransactionConstants.ACCOUNT_NO_COL, rowHeader, "Account No"); + writeString(TransactionConstants.CHECK_NO_COL, rowHeader, "Check No"); + writeString(TransactionConstants.RECEIPT_NO_COL, rowHeader, "Receipt No"); + writeString(TransactionConstants.ROUTING_CODE_COL, rowHeader, "Routing Code"); + writeString(TransactionConstants.BANK_NO_COL, rowHeader, "Bank No"); + writeString(TransactionConstants.LOOKUP_CLIENT_NAME_COL, rowHeader, "Lookup Client"); + writeString(TransactionConstants.LOOKUP_ACCOUNT_NO_COL, rowHeader, "Lookup Account"); + writeString(TransactionConstants.LOOKUP_PRODUCT_COL, rowHeader, "Lookup Product"); + writeString(TransactionConstants.LOOKUP_OPENING_BALANCE_COL, rowHeader, "Lookup Opening Balance"); + writeString(TransactionConstants.LOOKUP_SAVINGS_ACTIVATION_DATE_COL, rowHeader, "Lookup Savings Activation Date"); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/savings/SavingsWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/savings/SavingsWorkbookPopulator.java new file mode 100644 index 000000000..17be76b1b --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/savings/SavingsWorkbookPopulator.java @@ -0,0 +1,411 @@ +/** + * 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.populator.savings; + +import org.apache.fineract.infrastructure.bulkimport.constants.SavingsConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.*; +import org.apache.fineract.portfolio.savings.data.SavingsProductData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.List; + +public class SavingsWorkbookPopulator extends AbstractWorkbookPopulator { + + private OfficeSheetPopulator officeSheetPopulator; + private ClientSheetPopulator clientSheetPopulator; + private GroupSheetPopulator groupSheetPopulator; + private PersonnelSheetPopulator personnelSheetPopulator; + private SavingsProductSheetPopulator productSheetPopulator; + + + + public SavingsWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, ClientSheetPopulator clientSheetPopulator, + GroupSheetPopulator groupSheetPopulator, PersonnelSheetPopulator personnelSheetPopulator, + SavingsProductSheetPopulator savingsProductSheetPopulator) { + this.officeSheetPopulator=officeSheetPopulator; + this.clientSheetPopulator=clientSheetPopulator; + this.groupSheetPopulator=groupSheetPopulator; + this.personnelSheetPopulator=personnelSheetPopulator; + this.productSheetPopulator=savingsProductSheetPopulator; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet savingsSheet = workbook.createSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME); + officeSheetPopulator.populate(workbook,dateFormat); + clientSheetPopulator.populate(workbook,dateFormat); + groupSheetPopulator.populate(workbook,dateFormat); + personnelSheetPopulator.populate(workbook,dateFormat); + productSheetPopulator.populate(workbook,dateFormat); + setRules(savingsSheet,dateFormat); + setDefaults(savingsSheet,dateFormat); + setClientAndGroupDateLookupTable(savingsSheet, clientSheetPopulator.getClients(), groupSheetPopulator.getGroups(), + SavingsConstants.LOOKUP_CLIENT_NAME_COL, SavingsConstants.LOOKUP_ACTIVATION_DATE_COL,!TemplatePopulateImportConstants.CONTAINS_CLIENT_EXTERNAL_ID,dateFormat); + setLayout(savingsSheet); + } + + private void setLayout(Sheet worksheet) { + Row rowHeader = worksheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + worksheet.setColumnWidth(SavingsConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.SAVINGS_TYPE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.CLIENT_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.PRODUCT_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.FIELD_OFFICER_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.SUBMITTED_ON_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.APPROVED_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.ACTIVATION_DATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.CURRENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.DECIMAL_PLACES_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.IN_MULTIPLES_OF_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + + worksheet.setColumnWidth(SavingsConstants.NOMINAL_ANNUAL_INTEREST_RATE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.INTEREST_COMPOUNDING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.INTEREST_POSTING_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.INTEREST_CALCULATION_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.MIN_OPENING_BALANCE_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.LOCKIN_PERIOD_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.LOCKIN_PERIOD_FREQUENCY_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.APPLY_WITHDRAWAL_FEE_FOR_TRANSFERS, TemplatePopulateImportConstants.SMALL_COL_SIZE); + + worksheet.setColumnWidth(SavingsConstants.LOOKUP_CLIENT_NAME_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.LOOKUP_ACTIVATION_DATE_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.EXTERNAL_ID_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + + worksheet.setColumnWidth(SavingsConstants.ALLOW_OVER_DRAFT_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.OVER_DRAFT_LIMIT_COL, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + + worksheet.setColumnWidth(SavingsConstants.CHARGE_ID_1, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.CHARGE_AMOUNT_1, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.CHARGE_DUE_DATE_1, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.CHARGE_ID_2, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.CHARGE_AMOUNT_2, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + worksheet.setColumnWidth(SavingsConstants.CHARGE_DUE_DATE_2, TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + + writeString(SavingsConstants.OFFICE_NAME_COL, rowHeader, "Office Name*"); + writeString(SavingsConstants.SAVINGS_TYPE_COL, rowHeader, "Individual/Group*"); + writeString(SavingsConstants.CLIENT_NAME_COL, rowHeader, "Client Name*"); + writeString(SavingsConstants.PRODUCT_COL, rowHeader, "Product*"); + writeString(SavingsConstants.FIELD_OFFICER_NAME_COL, rowHeader, "Field Officer*"); + writeString(SavingsConstants.SUBMITTED_ON_DATE_COL, rowHeader, "Submitted On*"); + writeString(SavingsConstants.APPROVED_DATE_COL, rowHeader, "Approved On*"); + writeString(SavingsConstants.ACTIVATION_DATE_COL, rowHeader, "Activation Date*"); + writeString(SavingsConstants.CURRENCY_COL, rowHeader, "Currency"); + writeString(SavingsConstants.DECIMAL_PLACES_COL, rowHeader, "Decimal Places"); + writeString(SavingsConstants.IN_MULTIPLES_OF_COL, rowHeader, "In Multiples Of"); + writeString(SavingsConstants.NOMINAL_ANNUAL_INTEREST_RATE_COL, rowHeader, "Interest Rate %*"); + writeString(SavingsConstants.INTEREST_COMPOUNDING_PERIOD_COL, rowHeader, "Interest Compounding Period*"); + writeString(SavingsConstants.INTEREST_POSTING_PERIOD_COL, rowHeader, "Interest Posting Period*"); + writeString(SavingsConstants.INTEREST_CALCULATION_COL, rowHeader, "Interest Calculated*"); + writeString(SavingsConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, rowHeader, "# Days in Year*"); + writeString(SavingsConstants.MIN_OPENING_BALANCE_COL, rowHeader, "Min Opening Balance"); + writeString(SavingsConstants.LOCKIN_PERIOD_COL, rowHeader, "Locked In For"); + writeString(SavingsConstants.APPLY_WITHDRAWAL_FEE_FOR_TRANSFERS, rowHeader, "Apply Withdrawal Fee For Transfers"); + + writeString(SavingsConstants.LOOKUP_CLIENT_NAME_COL, rowHeader, "Client Name"); + writeString(SavingsConstants.LOOKUP_ACTIVATION_DATE_COL, rowHeader, "Client Activation Date"); + writeString(SavingsConstants.EXTERNAL_ID_COL, rowHeader, "External Id"); + + writeString(SavingsConstants.ALLOW_OVER_DRAFT_COL, rowHeader, "Is Overdraft Allowed "); + writeString(SavingsConstants.OVER_DRAFT_LIMIT_COL, rowHeader," Maximum Overdraft Amount Limit "); + + writeString(SavingsConstants.CHARGE_ID_1,rowHeader,"Charge Id"); + writeString(SavingsConstants.CHARGE_AMOUNT_1, rowHeader, "Charged Amount"); + writeString(SavingsConstants.CHARGE_DUE_DATE_1, rowHeader, "Charged On Date"); + writeString(SavingsConstants.CHARGE_ID_2,rowHeader,"Charge Id"); + writeString(SavingsConstants.CHARGE_AMOUNT_2, rowHeader, "Charged Amount"); + writeString(SavingsConstants.CHARGE_DUE_DATE_2, rowHeader, "Charged On Date"); + + } + + private void setDefaults(Sheet worksheet,String dateFormat) { + Workbook workbook = worksheet.getWorkbook(); + CellStyle dateCellStyle = workbook.createCellStyle(); + short df = workbook.createDataFormat().getFormat(dateFormat); + dateCellStyle.setDataFormat(df); + for (Integer rowNo = 1; rowNo < 1000; rowNo++) { + Row row = worksheet.createRow(rowNo); + writeFormula(SavingsConstants.CURRENCY_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Currency_\",$D" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Currency_\",$D" + (rowNo + 1) + ")))"); + writeFormula(SavingsConstants.DECIMAL_PLACES_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Decimal_Places_\",$D" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Decimal_Places_\",$D" + (rowNo + 1) + ")))"); + writeFormula(SavingsConstants.IN_MULTIPLES_OF_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"In_Multiples_\",$D" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"In_Multiples_\",$D" + (rowNo + 1) + ")))"); + writeFormula(SavingsConstants.NOMINAL_ANNUAL_INTEREST_RATE_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Interest_Rate_\",$D" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Interest_Rate_\",$D" + (rowNo + 1) + ")))"); + writeFormula(SavingsConstants.INTEREST_COMPOUNDING_PERIOD_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Interest_Compouding_\",$D" + + (rowNo + 1) + "))),\"\",INDIRECT(CONCATENATE(\"Interest_Compouding_\",$D" + (rowNo + 1) + ")))"); + writeFormula(SavingsConstants.INTEREST_POSTING_PERIOD_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Interest_Posting_\",$D" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Interest_Posting_\",$D" + (rowNo + 1) + ")))"); + writeFormula(SavingsConstants.INTEREST_CALCULATION_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Interest_Calculation_\",$D" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Interest_Calculation_\",$D" + (rowNo + 1) + ")))"); + writeFormula(SavingsConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Days_In_Year_\",$D" + + (rowNo + 1) + "))),\"\",INDIRECT(CONCATENATE(\"Days_In_Year_\",$D" + (rowNo + 1) + ")))"); + writeFormula(SavingsConstants.MIN_OPENING_BALANCE_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Min_Balance_\",$D" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Min_Balance_\",$D" + (rowNo + 1) + ")))"); + writeFormula(SavingsConstants.LOCKIN_PERIOD_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Lockin_Period_\",$D" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Lockin_Period_\",$D" + (rowNo + 1) + ")))"); + writeFormula(SavingsConstants.LOCKIN_PERIOD_FREQUENCY_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Lockin_Frequency_\",$D" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Lockin_Frequency_\",$D" + (rowNo + 1) + ")))"); + writeFormula(SavingsConstants.APPLY_WITHDRAWAL_FEE_FOR_TRANSFERS, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Withdrawal_Fee_\",$D" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Withdrawal_Fee_\",$D" + (rowNo + 1) + ")))"); + writeFormula(SavingsConstants.ALLOW_OVER_DRAFT_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Overdraft_\",$D" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Overdraft_\",$D" + (rowNo + 1) + ")))"); + writeFormula(SavingsConstants.OVER_DRAFT_LIMIT_COL, row, "IF(ISERROR(INDIRECT(CONCATENATE(\"Overdraft_Limit_\",$D" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"Overdraft_Limit_\",$D" + (rowNo + 1) + ")))"); + } + } + + private void setRules(Sheet worksheet,String dateFormat) { + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SavingsConstants.OFFICE_NAME_COL, SavingsConstants.OFFICE_NAME_COL); + CellRangeAddressList savingsTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SavingsConstants.SAVINGS_TYPE_COL, SavingsConstants.SAVINGS_TYPE_COL); + CellRangeAddressList clientNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SavingsConstants.CLIENT_NAME_COL, SavingsConstants.CLIENT_NAME_COL); + CellRangeAddressList productNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SavingsConstants.PRODUCT_COL, SavingsConstants.PRODUCT_COL); + CellRangeAddressList fieldOfficerRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SavingsConstants.FIELD_OFFICER_NAME_COL, SavingsConstants.FIELD_OFFICER_NAME_COL); + CellRangeAddressList submittedDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SavingsConstants.SUBMITTED_ON_DATE_COL, SavingsConstants.SUBMITTED_ON_DATE_COL); + CellRangeAddressList approvedDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SavingsConstants.APPROVED_DATE_COL, SavingsConstants.APPROVED_DATE_COL); + CellRangeAddressList activationDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SavingsConstants.ACTIVATION_DATE_COL, SavingsConstants.ACTIVATION_DATE_COL); + CellRangeAddressList interestCompudingPeriodRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SavingsConstants.INTEREST_COMPOUNDING_PERIOD_COL, SavingsConstants.INTEREST_COMPOUNDING_PERIOD_COL); + CellRangeAddressList interestPostingPeriodRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SavingsConstants.INTEREST_POSTING_PERIOD_COL, SavingsConstants.INTEREST_POSTING_PERIOD_COL); + CellRangeAddressList interestCalculationRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SavingsConstants.INTEREST_CALCULATION_COL, SavingsConstants.INTEREST_CALCULATION_COL); + CellRangeAddressList interestCalculationDaysInYearRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), SavingsConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL, + SavingsConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL); + CellRangeAddressList lockinPeriodFrequencyRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SavingsConstants.LOCKIN_PERIOD_FREQUENCY_COL, SavingsConstants.LOCKIN_PERIOD_FREQUENCY_COL); + CellRangeAddressList applyWithdrawalFeeForTransfersRange = new CellRangeAddressList(1, + SpreadsheetVersion.EXCEL97.getLastRowIndex(), SavingsConstants.APPLY_WITHDRAWAL_FEE_FOR_TRANSFERS, SavingsConstants.APPLY_WITHDRAWAL_FEE_FOR_TRANSFERS); + CellRangeAddressList allowOverdraftRange = new CellRangeAddressList(1,SpreadsheetVersion.EXCEL97.getLastRowIndex(),SavingsConstants.ALLOW_OVER_DRAFT_COL,SavingsConstants.ALLOW_OVER_DRAFT_COL); + + + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet) worksheet); + + setNames(worksheet); + + DataValidationConstraint officeNameConstraint = validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint savingsTypeConstraint = validationHelper.createExplicitListConstraint(new String[] { "Individual", + "Group" }); + DataValidationConstraint clientNameConstraint = validationHelper + .createFormulaListConstraint("IF($B1=\"Individual\",INDIRECT(CONCATENATE(\"Client_\",$A1)),INDIRECT(CONCATENATE(\"Group_\",$A1)))"); + DataValidationConstraint productNameConstraint = validationHelper.createFormulaListConstraint("Products"); + DataValidationConstraint fieldOfficerNameConstraint = validationHelper + .createFormulaListConstraint("INDIRECT(CONCATENATE(\"Staff_\",$A1))"); + DataValidationConstraint submittedDateConstraint = validationHelper.createDateConstraint( + DataValidationConstraint.OperatorType.BETWEEN, "=VLOOKUP($C1,$AF$2:$AG$" + + (clientSheetPopulator.getClientsSize() + groupSheetPopulator.getGroupsSize() + 1) + ",2,FALSE)", "=TODAY()", + dateFormat); + DataValidationConstraint approvalDateConstraint = validationHelper.createDateConstraint( + DataValidationConstraint.OperatorType.BETWEEN, "=$F1", "=TODAY()", dateFormat); + DataValidationConstraint activationDateConstraint = validationHelper.createDateConstraint( + DataValidationConstraint.OperatorType.BETWEEN, "=$G1", "=TODAY()", dateFormat); + DataValidationConstraint interestCompudingPeriodConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_DAILY , + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_MONTHLY, + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_QUARTERLY, + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_SEMI_ANNUALLY, + TemplatePopulateImportConstants.INTEREST_COMPOUNDING_PERIOD_ANNUALLY }); + DataValidationConstraint interestPostingPeriodConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_MONTHLY , + TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_QUARTERLY, + TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_BIANUALLY, + TemplatePopulateImportConstants.INTEREST_POSTING_PERIOD_ANNUALLY }); + DataValidationConstraint interestCalculationConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.INTEREST_CAL_DAILY_BALANCE, + TemplatePopulateImportConstants.INTEREST_CAL_AVG_BALANCE }); + DataValidationConstraint interestCalculationDaysInYearConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.INTEREST_CAL_DAYS_IN_YEAR_360, + TemplatePopulateImportConstants.INTEREST_CAL_DAYS_IN_YEAR_365 }); + DataValidationConstraint lockinPeriodFrequencyConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.FREQUENCY_DAYS, + TemplatePopulateImportConstants.FREQUENCY_WEEKS, + TemplatePopulateImportConstants.FREQUENCY_MONTHS, + TemplatePopulateImportConstants.FREQUENCY_YEARS }); + DataValidationConstraint applyWithdrawalFeeForTransferConstraint = validationHelper.createExplicitListConstraint(new String[] { + "True", "False" }); + DataValidationConstraint allowOverdraftConstraint = validationHelper.createExplicitListConstraint(new String[] { + "True", "False" }); + + DataValidation officeValidation = validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation savingsTypeValidation = validationHelper.createValidation(savingsTypeConstraint, savingsTypeRange); + DataValidation clientValidation = validationHelper.createValidation(clientNameConstraint, clientNameRange); + DataValidation productNameValidation = validationHelper.createValidation(productNameConstraint, productNameRange); + DataValidation fieldOfficerValidation = validationHelper.createValidation(fieldOfficerNameConstraint, fieldOfficerRange); + DataValidation interestCompudingPeriodValidation = validationHelper.createValidation(interestCompudingPeriodConstraint, + interestCompudingPeriodRange); + DataValidation interestPostingPeriodValidation = validationHelper.createValidation(interestPostingPeriodConstraint, + interestPostingPeriodRange); + DataValidation interestCalculationValidation = validationHelper.createValidation(interestCalculationConstraint, + interestCalculationRange); + DataValidation interestCalculationDaysInYearValidation = validationHelper.createValidation( + interestCalculationDaysInYearConstraint, interestCalculationDaysInYearRange); + DataValidation lockinPeriodFrequencyValidation = validationHelper.createValidation(lockinPeriodFrequencyConstraint, + lockinPeriodFrequencyRange); + DataValidation applyWithdrawalFeeForTransferValidation = validationHelper.createValidation( + applyWithdrawalFeeForTransferConstraint, applyWithdrawalFeeForTransfersRange); + DataValidation submittedDateValidation = validationHelper.createValidation(submittedDateConstraint, submittedDateRange); + DataValidation approvalDateValidation = validationHelper.createValidation(approvalDateConstraint, approvedDateRange); + DataValidation activationDateValidation = validationHelper.createValidation(activationDateConstraint, activationDateRange); + DataValidation allowOverdraftValidation = validationHelper.createValidation( + allowOverdraftConstraint, allowOverdraftRange); + + worksheet.addValidationData(officeValidation); + worksheet.addValidationData(savingsTypeValidation); + worksheet.addValidationData(clientValidation); + worksheet.addValidationData(productNameValidation); + worksheet.addValidationData(fieldOfficerValidation); + worksheet.addValidationData(submittedDateValidation); + worksheet.addValidationData(approvalDateValidation); + worksheet.addValidationData(activationDateValidation); + worksheet.addValidationData(interestCompudingPeriodValidation); + worksheet.addValidationData(interestPostingPeriodValidation); + worksheet.addValidationData(interestCalculationValidation); + worksheet.addValidationData(interestCalculationDaysInYearValidation); + worksheet.addValidationData(lockinPeriodFrequencyValidation); + worksheet.addValidationData(applyWithdrawalFeeForTransferValidation); + worksheet.addValidationData(allowOverdraftValidation); + } + + private void setNames(Sheet worksheet) { + Workbook savingsWorkbook = worksheet.getWorkbook(); + List officeNames = officeSheetPopulator.getOfficeNames(); + List products = productSheetPopulator.getProducts(); + + // Office Names + Name officeGroup = savingsWorkbook.createName(); + officeGroup.setNameName("Office"); + officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (officeNames.size() + 1)); + + // Client and Loan Officer Names for each office + for (Integer i = 0; i < officeNames.size(); i++) { + Integer[] officeNameToBeginEndIndexesOfClients = clientSheetPopulator.getOfficeNameToBeginEndIndexesOfClients().get(i); + Integer[] officeNameToBeginEndIndexesOfStaff = personnelSheetPopulator.getOfficeNameToBeginEndIndexesOfStaff().get(i); + Integer[] officeNameToBeginEndIndexesOfGroups = groupSheetPopulator.getOfficeNameToBeginEndIndexesOfGroups().get(i); + Name clientName = savingsWorkbook.createName(); + Name fieldOfficerName = savingsWorkbook.createName(); + Name groupName = savingsWorkbook.createName(); + if (officeNameToBeginEndIndexesOfStaff != null) { + fieldOfficerName.setNameName("Staff_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + fieldOfficerName.setRefersToFormula(TemplatePopulateImportConstants.STAFF_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfStaff[0] + ":$B$" + + officeNameToBeginEndIndexesOfStaff[1]); + } + if (officeNameToBeginEndIndexesOfClients != null) { + clientName.setNameName("Client_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + clientName.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfClients[0] + ":$B$" + + officeNameToBeginEndIndexesOfClients[1]); + } + if (officeNameToBeginEndIndexesOfGroups != null) { + groupName.setNameName("Group_" + officeNames.get(i).trim().replaceAll("[ )(]", "_")); + groupName.setRefersToFormula(TemplatePopulateImportConstants.GROUP_SHEET_NAME+"!$B$" + officeNameToBeginEndIndexesOfGroups[0] + ":$B$" + + officeNameToBeginEndIndexesOfGroups[1]); + } + } + + // Product Name + Name productGroup = savingsWorkbook.createName(); + productGroup.setNameName("Products"); + productGroup.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$B$2:$B$" + (productSheetPopulator.getProductsSize() + 1)); + + // Default Interest Rate, Interest Compounding Period, Interest Posting + // Period, Interest Calculation, Interest Calculation Days In Year, + // Minimum Opening Balance, Lockin Period, Lockin Period Frequency, + // Withdrawal Fee Amount, Withdrawal Fee Type, Annual Fee, Annual Fee on + // Date + // Names for each product + for (Integer i = 0; i < products.size(); i++) { + Name interestRateName = savingsWorkbook.createName(); + Name interestCompoundingPeriodName = savingsWorkbook.createName(); + Name interestPostingPeriodName = savingsWorkbook.createName(); + Name interestCalculationName = savingsWorkbook.createName(); + Name daysInYearName = savingsWorkbook.createName(); + Name minOpeningBalanceName = savingsWorkbook.createName(); + Name lockinPeriodName = savingsWorkbook.createName(); + Name lockinPeriodFrequencyName = savingsWorkbook.createName(); + Name currencyName = savingsWorkbook.createName(); + Name decimalPlacesName = savingsWorkbook.createName(); + Name inMultiplesOfName = savingsWorkbook.createName(); + Name withdrawalFeeName = savingsWorkbook.createName(); + Name allowOverdraftName = savingsWorkbook.createName(); + Name overdraftLimitName = savingsWorkbook.createName(); + SavingsProductData product = products.get(i); + String productName = product.getName().replaceAll("[ ]", "_"); + if (product.getNominalAnnualInterestRate() != null) { + interestRateName.setNameName("Interest_Rate_" + productName); + interestRateName.setRefersToFormula("Products!$C$" + (i + 2)); + } + interestCompoundingPeriodName.setNameName("Interest_Compouding_" + productName); + interestPostingPeriodName.setNameName("Interest_Posting_" + productName); + interestCalculationName.setNameName("Interest_Calculation_" + productName); + daysInYearName.setNameName("Days_In_Year_" + productName); + currencyName.setNameName("Currency_" + productName); + decimalPlacesName.setNameName("Decimal_Places_" + productName); + withdrawalFeeName.setNameName("Withdrawal_Fee_" + productName); + allowOverdraftName.setNameName("Overdraft_" + productName); + + interestCompoundingPeriodName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$D$" + (i + 2)); + interestPostingPeriodName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$E$" + (i + 2)); + interestCalculationName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$F$" + (i + 2)); + daysInYearName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$G$" + (i + 2)); + currencyName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$K$" + (i + 2)); + decimalPlacesName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$L$" + (i + 2)); + withdrawalFeeName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$N$" + (i + 2)); + allowOverdraftName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$O$" + (i + 2)); + if (product.getOverdraftLimit() != null) { + overdraftLimitName.setNameName("Overdraft_Limit_" + productName); + overdraftLimitName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$P$" + (i + 2)); + } + if (product.getMinRequiredOpeningBalance() != null) { + minOpeningBalanceName.setNameName("Min_Balance_" + productName); + minOpeningBalanceName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$H$" + (i + 2)); + } + if (product.getLockinPeriodFrequency() != null) { + lockinPeriodName.setNameName("Lockin_Period_" + productName); + lockinPeriodName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$I$" + (i + 2)); + } + if (product.getLockinPeriodFrequencyType() != null) { + lockinPeriodFrequencyName.setNameName("Lockin_Frequency_" + productName); + lockinPeriodFrequencyName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$J$" + (i + 2)); + } + if (product.getCurrency().currencyInMultiplesOf() != null) { + inMultiplesOfName.setNameName("In_Multiples_" + productName); + inMultiplesOfName.setRefersToFormula(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME+"!$M$" + (i + 2)); + } + } + } + +} + + diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/shareaccount/SharedAccountWorkBookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/shareaccount/SharedAccountWorkBookPopulator.java new file mode 100644 index 000000000..376d04fb6 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/shareaccount/SharedAccountWorkBookPopulator.java @@ -0,0 +1,240 @@ +/** + * 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.populator.shareaccount; + +import org.apache.fineract.infrastructure.bulkimport.constants.SharedAccountsConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.ClientSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.SavingsAccountSheetPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.SharedProductsSheetPopulator; +import org.apache.fineract.portfolio.client.data.ClientData; +import org.apache.fineract.portfolio.shareproducts.data.ShareProductData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.List; + +public class SharedAccountWorkBookPopulator extends AbstractWorkbookPopulator { + + private SharedProductsSheetPopulator sharedProductsSheetPopulator; + private ClientSheetPopulator clientSheetPopulator; + private SavingsAccountSheetPopulator savingsAccountSheetPopulator; + + public SharedAccountWorkBookPopulator(SharedProductsSheetPopulator sharedProductsSheetPopulator, + ClientSheetPopulator clientSheetPopulator,SavingsAccountSheetPopulator savingsAccountSheetPopulator) { + this.sharedProductsSheetPopulator=sharedProductsSheetPopulator; + this.clientSheetPopulator=clientSheetPopulator; + this.savingsAccountSheetPopulator=savingsAccountSheetPopulator; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet sharedAccountSheet= workbook.createSheet(TemplatePopulateImportConstants.SHARED_ACCOUNTS_SHEET_NAME); + sharedProductsSheetPopulator.populate(workbook,dateFormat); + clientSheetPopulator.populate(workbook,dateFormat); + savingsAccountSheetPopulator.populate(workbook,dateFormat); + setLayout(sharedAccountSheet); + setRules(sharedAccountSheet,dateFormat); + setDefaults(sharedAccountSheet); + } + + private void setDefaults(Sheet sharedAccountSheet) { + for (Integer rowNo=1;rowNo<3000;rowNo++){ + Row row=sharedAccountSheet.createRow(rowNo); + writeFormula(SharedAccountsConstants.CURRENCY_COL,row,"IF(ISERROR(INDIRECT(CONCATENATE(\"CURRENCY_\",$B" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"CURRENCY_\",$B" + (rowNo + 1) + ")))"); + writeFormula(SharedAccountsConstants.DECIMAL_PLACES_COL,row,"IF(ISERROR(INDIRECT(CONCATENATE(\"DECIMAL_PLACES_\",$B" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"DECIMAL_PLACES_\",$B" + (rowNo + 1) + ")))"); + writeFormula(SharedAccountsConstants.TODAYS_PRICE_COL,row,"IF(ISERROR(INDIRECT(CONCATENATE(\"TODAYS_PRICE_\",$B" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"TODAYS_PRICE_\",$B" + (rowNo + 1) + ")))"); + writeFormula(SharedAccountsConstants.CURRENCY_IN_MULTIPLES_COL,row,"IF(ISERROR(INDIRECT(CONCATENATE(\"CURRENCY_IN_MULTIPLES_\",$B" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"CURRENCY_IN_MULTIPLES_\",$B" + (rowNo + 1) + ")))"); + writeFormula(SharedAccountsConstants.CHARGES_NAME_1_COL,row,"IF(ISERROR(INDIRECT(CONCATENATE(\"CHARGES_NAME_1_\",$B" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"CHARGES_NAME_1_\",$B" + (rowNo + 1) + ")))"); + writeFormula(SharedAccountsConstants.CHARGES_NAME_2_COL,row,"IF(ISERROR(INDIRECT(CONCATENATE(\"CHARGES_NAME_2_\",$B" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"CHARGES_NAME_2_\",$B" + (rowNo + 1) + ")))"); + writeFormula(SharedAccountsConstants.CHARGES_NAME_3_COL,row,"IF(ISERROR(INDIRECT(CONCATENATE(\"CHARGES_NAME_3_\",$B" + (rowNo + 1) + + "))),\"\",INDIRECT(CONCATENATE(\"CHARGES_NAME_3_\",$B" + (rowNo + 1) + ")))"); + } + } + + private void setRules(Sheet sharedAccountSheet,String dateFormat) { + CellRangeAddressList clientNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SharedAccountsConstants.CLIENT_NAME_COL,SharedAccountsConstants.CLIENT_NAME_COL); + CellRangeAddressList productRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SharedAccountsConstants.PRODUCT_COL,SharedAccountsConstants.PRODUCT_COL); + CellRangeAddressList submittedDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SharedAccountsConstants.SUBMITTED_ON_COL, SharedAccountsConstants.SUBMITTED_ON_COL); + CellRangeAddressList lockingFrequencyTypeRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SharedAccountsConstants.LOCK_IN_PERIOD_FREQUENCY_TYPE,SharedAccountsConstants. LOCK_IN_PERIOD_FREQUENCY_TYPE); + CellRangeAddressList applicationDateRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SharedAccountsConstants.APPLICATION_DATE_COL, SharedAccountsConstants.APPLICATION_DATE_COL); + CellRangeAddressList allowDividendCalcRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + SharedAccountsConstants.ALLOW_DIVIDEND_CALCULATION_FOR_INACTIVE_CLIENTS_COL, SharedAccountsConstants.ALLOW_DIVIDEND_CALCULATION_FOR_INACTIVE_CLIENTS_COL); + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet) sharedAccountSheet); + setNames(sharedAccountSheet); + + DataValidationConstraint clientNameConstraint = validationHelper.createFormulaListConstraint("Clients"); + DataValidationConstraint productNameConstraint = validationHelper.createFormulaListConstraint("Products"); + DataValidationConstraint dateConstraint = validationHelper.createDateConstraint + (DataValidationConstraint.OperatorType.LESS_OR_EQUAL,"=TODAY()",null, dateFormat); + DataValidationConstraint frequencyConstraint = validationHelper.createExplicitListConstraint(new String[] { + TemplatePopulateImportConstants.FREQUENCY_DAYS, + TemplatePopulateImportConstants.FREQUENCY_WEEKS, + TemplatePopulateImportConstants.FREQUENCY_MONTHS, + TemplatePopulateImportConstants.FREQUENCY_YEARS }); + DataValidationConstraint booleanConstraint=validationHelper.createExplicitListConstraint(new String[]{"True","False"}); + DataValidation clientValidation = validationHelper.createValidation(clientNameConstraint, clientNameRange); + DataValidation productValidation=validationHelper.createValidation(productNameConstraint,productRange); + DataValidation submittedOnValidation=validationHelper.createValidation(dateConstraint,submittedDateRange); + DataValidation frequencyValidation=validationHelper.createValidation(frequencyConstraint,lockingFrequencyTypeRange); + DataValidation applicationDateValidation=validationHelper.createValidation(dateConstraint,applicationDateRange); + DataValidation allowDividendValidation=validationHelper.createValidation(booleanConstraint,allowDividendCalcRange); + + sharedAccountSheet.addValidationData(clientValidation); + sharedAccountSheet.addValidationData(productValidation); + sharedAccountSheet.addValidationData(submittedOnValidation); + sharedAccountSheet.addValidationData(frequencyValidation); + sharedAccountSheet.addValidationData(applicationDateValidation); + sharedAccountSheet.addValidationData(allowDividendValidation); + + } + + private void setNames(Sheet sharedAccountSheet) { + List clients=clientSheetPopulator.getClients(); + List products=sharedProductsSheetPopulator.getSharedProductDataList(); + Workbook sharedAccountWorkbook=sharedAccountSheet.getWorkbook(); + + Name clientsGroup=sharedAccountWorkbook.createName(); + clientsGroup.setNameName("Clients"); + clientsGroup.setRefersToFormula(TemplatePopulateImportConstants.CLIENT_SHEET_NAME+"!$B$2:$B$"+clients.size()+1); + + Name productGroup=sharedAccountWorkbook.createName(); + productGroup.setNameName("Products"); + productGroup.setRefersToFormula(TemplatePopulateImportConstants.SHARED_PRODUCTS_SHEET_NAME+"!$B$2:$B$"+products.size()+1); + + for (Integer i=0;i offices = officeSheetPopulator.getOffices(); + setNames(staffSheet, offices); + + DataValidationConstraint officeNameConstraint = + validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint isLoanOfficerConstraint = + validationHelper.createExplicitListConstraint(new String[] {"True", "False"}); + DataValidationConstraint joinedOnConstraint = + validationHelper.createDateConstraint(DataValidationConstraint.OperatorType.LESS_OR_EQUAL, + "=TODAY()",null, dateFormat); + DataValidationConstraint isActiveConstraint = + validationHelper.createExplicitListConstraint(new String[] {"True", "False"}); + + DataValidation officeValidation = + validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation isLoanOfficerValidation = + validationHelper.createValidation(isLoanOfficerConstraint, isLoanOfficerNameRange); + DataValidation joinedOnValidation = + validationHelper.createValidation(joinedOnConstraint, joinedOnNameRange); + DataValidation isActiveValidation = + validationHelper.createValidation(isActiveConstraint, isActiveNameRange); + + staffSheet.addValidationData(officeValidation); + staffSheet.addValidationData(isLoanOfficerValidation); + staffSheet.addValidationData(joinedOnValidation); + staffSheet.addValidationData(isActiveValidation); + + } + + private void setNames(Sheet staffSheet, List offices) { + Workbook staffWorkBook=staffSheet.getWorkbook(); + Name officeGroup=staffWorkBook.createName(); + officeGroup.setNameName("Office"); + officeGroup.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (offices.size() + 1)); + } + + private void setLayout(Sheet staffSheet) { + Row rowHeader = staffSheet.createRow(TemplatePopulateImportConstants.ROWHEADER_INDEX); + rowHeader.setHeight(TemplatePopulateImportConstants.ROW_HEADER_HEIGHT); + staffSheet.setColumnWidth(StaffConstants.OFFICE_NAME_COL, TemplatePopulateImportConstants.SMALL_COL_SIZE); + staffSheet.setColumnWidth(StaffConstants.FIRST_NAME_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + staffSheet.setColumnWidth(StaffConstants.LAST_NAME_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + staffSheet.setColumnWidth(StaffConstants.IS_LOAN_OFFICER,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + staffSheet.setColumnWidth(StaffConstants.MOBILE_NO_COL,TemplatePopulateImportConstants.MEDIUM_COL_SIZE); + staffSheet.setColumnWidth(StaffConstants.JOINED_ON_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + staffSheet.setColumnWidth(StaffConstants.EXTERNAL_ID_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + staffSheet.setColumnWidth(StaffConstants.IS_ACTIVE_COL,TemplatePopulateImportConstants.SMALL_COL_SIZE); + writeString(StaffConstants.OFFICE_NAME_COL,rowHeader,"Office Name *"); + writeString(StaffConstants.FIRST_NAME_COL,rowHeader,"First Name *"); + writeString(StaffConstants.LAST_NAME_COL,rowHeader,"Last Name *"); + writeString(StaffConstants.IS_LOAN_OFFICER,rowHeader,"Is Loan Officer *"); + writeString(StaffConstants.MOBILE_NO_COL,rowHeader, "Mobile no"); + writeString(StaffConstants.JOINED_ON_COL,rowHeader,"Joined on *"); + writeString(StaffConstants.EXTERNAL_ID_COL,rowHeader,"External Id *"); + writeString(StaffConstants.IS_ACTIVE_COL,rowHeader,"Is Active *"); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/users/UserWorkbookPopulator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/users/UserWorkbookPopulator.java new file mode 100644 index 000000000..5fbd4608c --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/users/UserWorkbookPopulator.java @@ -0,0 +1,133 @@ +/** + * 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.populator.users; + +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.UserConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.*; +import org.apache.fineract.organisation.office.data.OfficeData; +import org.apache.poi.hssf.usermodel.HSSFDataValidationHelper; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.List; + +public class UserWorkbookPopulator extends AbstractWorkbookPopulator { + + private OfficeSheetPopulator officeSheetPopulator; + private PersonnelSheetPopulator personnelSheetPopulator; + private RoleSheetPopulator roleSheetPopulator; + + public UserWorkbookPopulator(OfficeSheetPopulator officeSheetPopulator, + PersonnelSheetPopulator personnelSheetPopulator, + RoleSheetPopulator roleSheetPopulator) { + this.officeSheetPopulator=officeSheetPopulator; + this.personnelSheetPopulator=personnelSheetPopulator; + this.roleSheetPopulator=roleSheetPopulator; + } + + @Override + public void populate(Workbook workbook,String dateFormat) { + Sheet usersheet=workbook.createSheet(TemplatePopulateImportConstants.USER_SHEET_NAME); + personnelSheetPopulator.populate(workbook,dateFormat); + officeSheetPopulator.populate(workbook,dateFormat); + roleSheetPopulator.populate(workbook,dateFormat); + setLayout(usersheet); + setRules(usersheet); + } + + private void setRules(Sheet usersheet) { + CellRangeAddressList officeNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + UserConstants.OFFICE_NAME_COL, UserConstants.OFFICE_NAME_COL); + CellRangeAddressList staffNameRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + UserConstants.STAFF_NAME_COL, UserConstants.STAFF_NAME_COL); + CellRangeAddressList autoGenPwRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + UserConstants.AUTO_GEN_PW_COL, UserConstants.AUTO_GEN_PW_COL); + CellRangeAddressList overridePwExpiryPolicyRange = new CellRangeAddressList(1, SpreadsheetVersion.EXCEL97.getLastRowIndex(), + UserConstants.OVERRIDE_PW_EXPIRY_POLICY_COL, UserConstants.OVERRIDE_PW_EXPIRY_POLICY_COL); + + DataValidationHelper validationHelper = new HSSFDataValidationHelper((HSSFSheet)usersheet); + List offices = officeSheetPopulator.getOffices(); + setNames(usersheet, offices); + + DataValidationConstraint officeNameConstraint = validationHelper.createFormulaListConstraint("Office"); + DataValidationConstraint staffNameConstraint = validationHelper.createFormulaListConstraint("INDIRECT(CONCATENATE(\"Staff_\",$A1))"); + DataValidationConstraint booleanConstraint = validationHelper.createExplicitListConstraint(new String[]{"True", "False"}); + + DataValidation officeValidation = validationHelper.createValidation(officeNameConstraint, officeNameRange); + DataValidation staffValidation = validationHelper.createValidation(staffNameConstraint, staffNameRange); + DataValidation autoGenPwValidation=validationHelper.createValidation(booleanConstraint,autoGenPwRange); + DataValidation overridePwExpiryPolicyValidation=validationHelper.createValidation(booleanConstraint,overridePwExpiryPolicyRange); + + usersheet.addValidationData(officeValidation); + usersheet.addValidationData(staffValidation); + usersheet.addValidationData(autoGenPwValidation); + usersheet.addValidationData(overridePwExpiryPolicyValidation); + } + + private void setNames(Sheet usersheet, List offices) { + Workbook userWorkbook=usersheet.getWorkbook(); + Name officeUser = userWorkbook.createName(); + + officeUser.setNameName("Office"); + officeUser.setRefersToFormula(TemplatePopulateImportConstants.OFFICE_SHEET_NAME+"!$B$2:$B$" + (offices.size() + 1)); + + //Staff Names for each office + for (Integer i=0;i { + + + private final TenantDetailsService tenantDetailsService; + private final ApplicationContext applicationContext; + private final ImportDocumentRepository importRepository; + private final DocumentWritePlatformService documentService; + + @Autowired + public BulkImportEventListener( + final TenantDetailsService tenantDetailsService, + final ApplicationContext context, + final ImportDocumentRepository importRepository, + final DocumentWritePlatformService documentService) { + this.tenantDetailsService = tenantDetailsService; + this.applicationContext = context; + this.importRepository = importRepository; + this.documentService = documentService; + } + + @Override + public void onApplicationEvent(final BulkImportEvent event) { + + final String tenantIdentifier = event.getTenantIdentifier(); + final FineractPlatformTenant tenant = this.tenantDetailsService + .loadTenantById(tenantIdentifier); + ThreadLocalContextUtil.setTenant(tenant); + ImportHandler importHandler = null; + final ImportDocument importDocument = this.importRepository.findOne(event.getImportId()); + final GlobalEntityType entityType = GlobalEntityType.fromInt(importDocument.getEntityType()); + + switch(entityType) { + case OFFICES : + importHandler = this.applicationContext.getBean("officeImportHandler", ImportHandler.class); + break; + case CENTERS: + importHandler=this.applicationContext.getBean("centerImportHandler",ImportHandler.class); + break; + case CHART_OF_ACCOUNTS: + importHandler=this.applicationContext.getBean("chartOfAccountsImportHandler",ImportHandler.class); + break; + case CLIENTS_ENTTTY: + importHandler=this.applicationContext.getBean("clientEntityImportHandler",ImportHandler.class); + break; + case CLIENTS_PERSON: + importHandler=this.applicationContext.getBean("clientPersonImportHandler",ImportHandler.class); + break; + case FIXED_DEPOSIT_ACCOUNTS: + importHandler=this.applicationContext.getBean("fixedDepositImportHandler",ImportHandler.class); + break; + case FIXED_DEPOSIT_TRANSACTIONS: + importHandler=this.applicationContext.getBean("fixedDepositTransactionImportHandler",ImportHandler.class); + break; + case GROUPS: + importHandler=this.applicationContext.getBean("groupImportHandler",ImportHandler.class); + break; + case GUARANTORS: + importHandler=this.applicationContext.getBean("guarantorImportHandler",ImportHandler.class); + break; + case GL_JOURNAL_ENTRIES: + importHandler=this.applicationContext.getBean("journalEntriesImportHandler",ImportHandler.class); + break; + case LOANS: + importHandler=this.applicationContext.getBean("loanImportHandler",ImportHandler.class); + break; + case LOAN_TRANSACTIONS: + importHandler=this.applicationContext.getBean("loanRepaymentImportHandler",ImportHandler.class); + break; + case RECURRING_DEPOSIT_ACCOUNTS: + importHandler=this.applicationContext.getBean("recurringDepositImportHandler",ImportHandler.class); + break; + case RECURRING_DEPOSIT_ACCOUNTS_TRANSACTIONS: + importHandler=this.applicationContext.getBean("recurringDepositTransactionImportHandler",ImportHandler.class); + break; + case SAVINGS_ACCOUNT: + importHandler=this.applicationContext.getBean("savingsImportHandler",ImportHandler.class); + break; + case SAVINGS_TRANSACTIONS: + importHandler=this.applicationContext.getBean("savingsTransactionImportHandler",ImportHandler.class); + break; + case SHARE_ACCOUNTS: + importHandler=this.applicationContext.getBean("sharedAccountImportHandler",ImportHandler.class); + break; + case STAFF: + importHandler=this.applicationContext.getBean("staffImportHandler",ImportHandler.class); + break; + case USERS: + importHandler=this.applicationContext.getBean("userImportHandler",ImportHandler.class); + break; + default : throw new GeneralPlatformDomainRuleException("error.msg.unable.to.find.resource", + "Unable to find requested resource"); + + } + + final Workbook workbook = event.getWorkbook(); + final Count count = importHandler.process(workbook, event.getLocale(), event.getDateFormat()); + importDocument.update(DateUtils.getLocalDateTimeOfTenant(), count.getSuccessCount(), count.getErrorCount()); + this.importRepository.save(importDocument); + + final Set modifiedParams = new HashSet<>(); + modifiedParams.add("fileName"); + modifiedParams.add("size"); + modifiedParams.add("type"); + modifiedParams.add("location"); + Document document = importDocument.getDocument(); + + DocumentCommand documentCommand = new DocumentCommand(modifiedParams, document.getId(), entityType.name(), null, + document.getName(), document.getFileName(), document.getSize(), URLConnection.guessContentTypeFromName(document.getFileName()), + null, null); + + final ByteArrayOutputStream bos = new ByteArrayOutputStream(); + try { + try { + workbook.write(bos); + } finally { + bos.close(); + } + } catch (IOException io) { + io.printStackTrace(); + } + byte[] bytes = bos.toByteArray(); + ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + this.documentService.updateDocument(documentCommand, bis); + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorService.java new file mode 100644 index 000000000..bca137acd --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorService.java @@ -0,0 +1,26 @@ +/** + * 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.service; + +import javax.ws.rs.core.Response; + +public interface BulkImportWorkbookPopulatorService { + + public Response getTemplate(final String entityType, final Long officeId, final Long staffId,final String dateFormat); +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorServiceImpl.java new file mode 100644 index 000000000..c329ef450 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorServiceImpl.java @@ -0,0 +1,674 @@ +/** + * 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.service; + +import org.apache.fineract.accounting.glaccount.data.GLAccountData; +import org.apache.fineract.accounting.glaccount.service.GLAccountReadPlatformService; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.populator.*; +import org.apache.fineract.infrastructure.bulkimport.populator.centers.CentersWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.chartofaccounts.ChartOfAccountsWorkbook; +import org.apache.fineract.infrastructure.bulkimport.populator.client.ClientEntityWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.client.ClientPersonWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.fixeddeposits.FixedDepositTransactionWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.fixeddeposits.FixedDepositWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.group.GroupsWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.guarantor.GuarantorWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.journalentry.JournalEntriesWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.loan.LoanWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.loanrepayment.LoanRepaymentWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.office.OfficeWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.recurringdeposit.RecurringDepositTransactionWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.recurringdeposit.RecurringDepositWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.savings.SavingsTransactionsWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.savings.SavingsWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.shareaccount.SharedAccountWorkBookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.staff.StaffWorkbookPopulator; +import org.apache.fineract.infrastructure.bulkimport.populator.users.UserWorkbookPopulator; +import org.apache.fineract.infrastructure.codes.data.CodeValueData; +import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService; +import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; +import org.apache.fineract.infrastructure.core.service.DateUtils; +import org.apache.fineract.infrastructure.core.service.Page; +import org.apache.fineract.infrastructure.core.service.SearchParameters; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.apache.fineract.organisation.monetary.data.CurrencyData; +import org.apache.fineract.organisation.monetary.service.CurrencyReadPlatformService; +import org.apache.fineract.organisation.office.data.OfficeData; +import org.apache.fineract.organisation.office.service.OfficeReadPlatformService; +import org.apache.fineract.organisation.staff.data.StaffData; +import org.apache.fineract.organisation.staff.service.StaffReadPlatformService; +import org.apache.fineract.portfolio.charge.data.ChargeData; +import org.apache.fineract.portfolio.charge.service.ChargeReadPlatformService; +import org.apache.fineract.portfolio.client.data.ClientData; +import org.apache.fineract.portfolio.client.service.ClientReadPlatformService; +import org.apache.fineract.portfolio.fund.data.FundData; +import org.apache.fineract.portfolio.fund.service.FundReadPlatformService; +import org.apache.fineract.portfolio.group.api.GroupingTypesApiConstants; +import org.apache.fineract.portfolio.group.data.CenterData; +import org.apache.fineract.portfolio.group.data.GroupGeneralData; +import org.apache.fineract.portfolio.group.service.CenterReadPlatformService; +import org.apache.fineract.portfolio.group.service.GroupReadPlatformService; +import org.apache.fineract.portfolio.loanaccount.data.LoanAccountData; +import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService; +import org.apache.fineract.portfolio.loanproduct.data.LoanProductData; +import org.apache.fineract.portfolio.loanproduct.service.LoanProductReadPlatformService; +import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData; +import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeReadPlatformService; +import org.apache.fineract.portfolio.products.data.ProductData; +import org.apache.fineract.portfolio.products.service.ProductReadPlatformService; +import org.apache.fineract.portfolio.savings.DepositAccountType; +import org.apache.fineract.portfolio.savings.data.*; +import org.apache.fineract.portfolio.savings.service.DepositProductReadPlatformService; +import org.apache.fineract.portfolio.savings.service.SavingsAccountReadPlatformService; +import org.apache.fineract.portfolio.savings.service.SavingsProductReadPlatformService; +import org.apache.fineract.portfolio.shareproducts.data.ShareProductData; +import org.apache.fineract.useradministration.data.RoleData; +import org.apache.fineract.useradministration.service.RoleReadPlatformService; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Workbook; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.ResponseBuilder; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +@Service +public class BulkImportWorkbookPopulatorServiceImpl implements BulkImportWorkbookPopulatorService { + + private final PlatformSecurityContext context; + private final OfficeReadPlatformService officeReadPlatformService; + private final StaffReadPlatformService staffReadPlatformService; + private final ClientReadPlatformService clientReadPlatformService; + private final CenterReadPlatformService centerReadPlatformService; + private final GroupReadPlatformService groupReadPlatformService; + private final FundReadPlatformService fundReadPlatformService; + private final PaymentTypeReadPlatformService paymentTypeReadPlatformService; + private final LoanProductReadPlatformService loanProductReadPlatformService; + private final CurrencyReadPlatformService currencyReadPlatformService; + private final LoanReadPlatformService loanReadPlatformService; + private final GLAccountReadPlatformService glAccountReadPlatformService; + private final SavingsAccountReadPlatformService savingsAccountReadPlatformService; + private final CodeValueReadPlatformService codeValueReadPlatformService; + private final SavingsProductReadPlatformService savingsProductReadPlatformService; + private final ProductReadPlatformService productReadPlatformService; + private final ChargeReadPlatformService chargeReadPlatformService; + private final DepositProductReadPlatformService depositProductReadPlatformService; + private final RoleReadPlatformService roleReadPlatformService; + + @Autowired + public BulkImportWorkbookPopulatorServiceImpl(final PlatformSecurityContext context, + final OfficeReadPlatformService officeReadPlatformService, + final StaffReadPlatformService staffReadPlatformService, + final ClientReadPlatformService clientReadPlatformService, + final CenterReadPlatformService centerReadPlatformService, + final GroupReadPlatformService groupReadPlatformService, + final FundReadPlatformService fundReadPlatformService, + final PaymentTypeReadPlatformService paymentTypeReadPlatformService, + final LoanProductReadPlatformService loanProductReadPlatformService, + final CurrencyReadPlatformService currencyReadPlatformService, + final LoanReadPlatformService loanReadPlatformService, + final GLAccountReadPlatformService glAccountReadPlatformService, + final SavingsAccountReadPlatformService savingsAccountReadPlatformService, + final CodeValueReadPlatformService codeValueReadPlatformService, + final SavingsProductReadPlatformService savingsProductReadPlatformService, + final ProductReadPlatformService productReadPlatformService, + final ChargeReadPlatformService chargeReadPlatformService, + final DepositProductReadPlatformService depositProductReadPlatformService, + final RoleReadPlatformService roleReadPlatformService) { + this.officeReadPlatformService = officeReadPlatformService; + this.staffReadPlatformService = staffReadPlatformService; + this.context = context; + this.clientReadPlatformService=clientReadPlatformService; + this.centerReadPlatformService=centerReadPlatformService; + this.groupReadPlatformService=groupReadPlatformService; + this.fundReadPlatformService=fundReadPlatformService; + this.paymentTypeReadPlatformService=paymentTypeReadPlatformService; + this.loanProductReadPlatformService=loanProductReadPlatformService; + this.currencyReadPlatformService=currencyReadPlatformService; + this.loanReadPlatformService=loanReadPlatformService; + this.glAccountReadPlatformService=glAccountReadPlatformService; + this.savingsAccountReadPlatformService=savingsAccountReadPlatformService; + this.codeValueReadPlatformService=codeValueReadPlatformService; + this.savingsProductReadPlatformService=savingsProductReadPlatformService; + this.productReadPlatformService=productReadPlatformService; + this.chargeReadPlatformService=chargeReadPlatformService; + this.depositProductReadPlatformService=depositProductReadPlatformService; + this.roleReadPlatformService=roleReadPlatformService; + } + + @Override + public Response getTemplate(String entityType, Long officeId, Long staffId,final String dateFormat) { + WorkbookPopulator populator=null; + final Workbook workbook=new HSSFWorkbook(); + if(entityType!=null){ + if (entityType.trim().equalsIgnoreCase(GlobalEntityType.CLIENTS_PERSON.toString())|| + entityType.trim().equalsIgnoreCase(GlobalEntityType.CLIENTS_ENTTTY.toString())) { + populator = populateClientWorkbook(entityType,officeId, staffId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.CENTERS.toString())) { + populator=populateCenterWorkbook(officeId,staffId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.GROUPS.toString())) { + populator = populateGroupsWorkbook(officeId, staffId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.LOANS.toString())) { + populator = populateLoanWorkbook(officeId, staffId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.LOAN_TRANSACTIONS.toString())) { + populator = populateLoanRepaymentWorkbook(officeId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.GL_JOURNAL_ENTRIES.toString())) { + populator = populateJournalEntriesWorkbook(officeId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.GUARANTORS.toString())) { + populator = populateGuarantorWorkbook(officeId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.OFFICES.toString())) { + populator=populateOfficeWorkbook(); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.CHART_OF_ACCOUNTS.toString())) { + populator=populateChartOfAccountsWorkbook(); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.STAFF.toString())) { + populator=populateStaffWorkbook(officeId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.SHARE_ACCOUNTS.toString())) { + populator=populateSharedAcountsWorkbook(officeId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.SAVINGS_ACCOUNT.toString())) { + populator=populateSavingsAccountWorkbook(officeId,staffId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.SAVINGS_TRANSACTIONS.toString())) { + populator=populateSavingsTransactionWorkbook(officeId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.RECURRING_DEPOSIT_ACCOUNTS.toString())) { + populator=populateRecurringDepositWorkbook(officeId,staffId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.RECURRING_DEPOSIT_ACCOUNTS_TRANSACTIONS.toString())) { + populator=populateRecurringDepositTransactionWorkbook(officeId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.FIXED_DEPOSIT_ACCOUNTS.toString())) { + populator = populateFixedDepositWorkbook(officeId, staffId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.FIXED_DEPOSIT_TRANSACTIONS.toString())){ + populator=populateFixedDepositTransactionsWorkbook(officeId); + }else if (entityType.trim().equalsIgnoreCase(GlobalEntityType.USERS.toString())){ + populator=populateUserWorkbook(officeId,staffId); + }else { + throw new GeneralPlatformDomainRuleException("error.msg.unable.to.find.resource", + "Unable to find requested resource"); + } + populator.populate(workbook,dateFormat); + return buildResponse(workbook, entityType); + }else { + throw new GeneralPlatformDomainRuleException("error.msg.given.entity.type.null", + "Given Entity type is null"); + } + } + + + private WorkbookPopulator populateClientWorkbook(final String entityType ,final Long officeId, final Long staffId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.STAFF_ENTITY_TYPE); + List offices = fetchOffices(officeId); + List staff = fetchStaff(staffId); + List clientTypeCodeValues =fetchCodeValuesByCodeName("ClientType"); + List clientClassification=fetchCodeValuesByCodeName("ClientClassification"); + List addressTypesCodeValues=fetchCodeValuesByCodeName("ADDRESS_TYPE"); + List stateProvinceCodeValues=fetchCodeValuesByCodeName("STATE"); + List countryCodeValues=fetchCodeValuesByCodeName("COUNTRY"); + if(entityType.trim().equalsIgnoreCase(GlobalEntityType.CLIENTS_PERSON.toString())) { + List genderCodeValues = fetchCodeValuesByCodeName("Gender"); + return new ClientPersonWorkbookPopulator(new OfficeSheetPopulator(offices), + new PersonnelSheetPopulator(staff, offices), clientTypeCodeValues, genderCodeValues, clientClassification + , addressTypesCodeValues, stateProvinceCodeValues, countryCodeValues); + }else if(entityType.trim().equalsIgnoreCase(GlobalEntityType.CLIENTS_ENTTTY.toString())){ + List constitutionCodeValues=fetchCodeValuesByCodeName("Constitution"); + List mainBusinessline=fetchCodeValuesByCodeName("Main Business Line"); + return new ClientEntityWorkbookPopulator(new OfficeSheetPopulator(offices), + new PersonnelSheetPopulator(staff, offices), clientTypeCodeValues, constitutionCodeValues,mainBusinessline, + clientClassification, addressTypesCodeValues, stateProvinceCodeValues, countryCodeValues); + } + return null; + } + + private Response buildResponse(final Workbook workbook, final String entity) { + String filename = entity + DateUtils.getLocalDateOfTenant().toString() + ".xls"; + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try { + workbook.write(baos); + } catch (IOException e) { + e.printStackTrace(); + } + + final ResponseBuilder response = Response.ok(baos.toByteArray()); + response.header("Content-Disposition", "attachment; filename=\"" + filename + "\""); + response.header("Content-Type", "application/vnd.ms-excel"); + return response.build(); + } + + @SuppressWarnings("unchecked") + private List fetchOffices(final Long officeId) { + List offices = null; + if (officeId == null) { + Boolean includeAllOffices = Boolean.TRUE; + offices = (List) this.officeReadPlatformService.retrieveAllOffices(includeAllOffices, null); + } else { + offices = new ArrayList<>(); + offices.add(this.officeReadPlatformService.retrieveOffice(officeId)); + } + return offices; + } + + @SuppressWarnings("unchecked") + private List fetchStaff(final Long staffId) { + List staff = null; + if (staffId == null){ + staff = + (List) this.staffReadPlatformService.retrieveAllStaff(null, null, Boolean.FALSE, null); + //System.out.println("Staff List size : "+staff.size()); + }else { + staff = new ArrayList<>(); + staff.add(this.staffReadPlatformService.retrieveStaff(staffId)); + } + return staff; + } + private List fetchCodeValuesByCodeName(String codeName){ + List codeValues=null; + if (codeName!=null){ + codeValues=(List)codeValueReadPlatformService.retrieveCodeValuesByCode(codeName); + }else { + throw new NullPointerException(); + } + return codeValues; + } + private ListfetchSavingsProducts(){ + List savingsProducts=(List)savingsProductReadPlatformService.retrieveAll(); + return savingsProducts; + } + +private WorkbookPopulator populateCenterWorkbook(Long officeId,Long staffId){ + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.STAFF_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.GROUP_ENTITY_TYPE); + List offices = fetchOffices(officeId); + List staff = fetchStaff(staffId); + List groups = fetchGroups(officeId); + return new CentersWorkbookPopulator(new OfficeSheetPopulator(offices), + new PersonnelSheetPopulator(staff, offices),new GroupSheetPopulator(groups,offices)); +} + + private WorkbookPopulator populateGroupsWorkbook(Long officeId, Long staffId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.STAFF_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CENTER_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CLIENT_ENTITY_TYPE); + List offices = fetchOffices(officeId); + List staff = fetchStaff(staffId); + List centers = fetchCenters(officeId); + List clients = fetchClients(officeId); + return new GroupsWorkbookPopulator(new OfficeSheetPopulator(offices), + new PersonnelSheetPopulator(staff, offices), new CenterSheetPopulator(centers, offices), + new ClientSheetPopulator(clients, offices)); + } + private List fetchCenters(Long officeId) { + Listcenters=null; + if (officeId==null) { + centers=(List) this.centerReadPlatformService.retrieveAll(null, null); + } else { + SearchParameters searchParameters = SearchParameters.from(null, officeId, null, null, null); + centers = (List)centerReadPlatformService.retrieveAll(searchParameters,null); + } + + return centers; + } + private List fetchClients(Long officeId) { + List clients=null; + if (officeId==null) { + Page clientDataPage =this.clientReadPlatformService.retrieveAll(null); + if (clientDataPage!=null){ + clients=new ArrayList<>(); + for (ClientData client: clientDataPage.getPageItems()) { + clients.add(client); + } + } + } else { + SearchParameters searchParameters = SearchParameters.from(null, officeId, null, null, null); + Page clientDataPage =this.clientReadPlatformService.retrieveAll(searchParameters); + if (clientDataPage!=null){ + clients=new ArrayList<>(); + for (ClientData client: clientDataPage.getPageItems()) { + clients.add(client); + } + } + } + return clients; + } + + + private WorkbookPopulator populateLoanWorkbook(Long officeId, Long staffId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.STAFF_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.GROUP_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CLIENT_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.LOAN_PRODUCT_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.FUNDS_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.PAYMENT_TYPE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CURRENCY_ENTITY_TYPE); + List offices = fetchOffices(officeId); + List staff = fetchStaff(staffId); + List clients = fetchClients(officeId); + List groups = fetchGroups(officeId); + List loanproducts = fetchLoanProducts(); + List funds = fetchFunds(); + List paymentTypes = fetchPaymentTypes(); + List currencies = fetchCurrencies(); + return new LoanWorkbookPopulator(new OfficeSheetPopulator(offices), new ClientSheetPopulator(clients, offices), + new GroupSheetPopulator(groups, offices), new PersonnelSheetPopulator(staff, offices), + new LoanProductSheetPopulator(loanproducts), new ExtrasSheetPopulator(funds, paymentTypes, currencies)); + } + + private List fetchCurrencies() { + List currencies =(List) this.currencyReadPlatformService. + retrieveAllPlatformCurrencies(); + return currencies; + } + + private List fetchPaymentTypes() { + List paymentTypeData =(List) this.paymentTypeReadPlatformService + .retrieveAllPaymentTypes(); + return paymentTypeData; + } + + private List fetchFunds() { + List funds =(List) this.fundReadPlatformService.retrieveAllFunds(); + return funds; + } + + private List fetchLoanProducts() { + Listloanproducts =(List) this.loanProductReadPlatformService + .retrieveAllLoanProducts(); + return loanproducts; + } + + private List fetchGroups(Long officeId) { + List groups = null; + if (officeId == null) { + groups = (List) this.groupReadPlatformService.retrieveAll(null, null); + } else { + SearchParameters searchParameters = SearchParameters.from(null, officeId, null, null, null); + groups = (List)groupReadPlatformService.retrieveAll(searchParameters,null); + } + + return groups; + } + + private WorkbookPopulator populateLoanRepaymentWorkbook(Long officeId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CLIENT_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.FUNDS_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.PAYMENT_TYPE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CURRENCY_ENTITY_TYPE); + List offices = fetchOffices(officeId); + List clients = fetchClients(officeId); + List funds = fetchFunds(); + List paymentTypes = fetchPaymentTypes(); + List currencies = fetchCurrencies(); + List loans = fetchLoanAccounts(officeId); + return new LoanRepaymentWorkbookPopulator(loans, new OfficeSheetPopulator(offices), + new ClientSheetPopulator(clients, offices), new ExtrasSheetPopulator(funds, paymentTypes, currencies)); + } + + private List fetchLoanAccounts(final Long officeId) { + List loanAccounts = null; + if(officeId==null){ + loanAccounts= loanReadPlatformService.retrieveAll(null).getPageItems(); + }else { + SearchParameters searchParameters = SearchParameters.from(null, officeId, null, null, null); + loanAccounts = loanReadPlatformService.retrieveAll(searchParameters).getPageItems(); + } + return loanAccounts; + } + + private WorkbookPopulator populateJournalEntriesWorkbook(Long officeId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.GL_ACCOUNT_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.FUNDS_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.PAYMENT_TYPE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CURRENCY_ENTITY_TYPE); + List offices = fetchOffices(officeId); + List glAccounts = fetchGLAccounts(); + List funds = fetchFunds(); + List paymentTypes = fetchPaymentTypes(); + List currencies = fetchCurrencies(); + return new JournalEntriesWorkbookPopulator(new OfficeSheetPopulator(offices), + new GlAccountSheetPopulator(glAccounts), new ExtrasSheetPopulator(funds, paymentTypes, currencies)); + } + + private List fetchGLAccounts() { + List glaccounts = (List) this.glAccountReadPlatformService. + retrieveAllGLAccounts(null, null, null, + null, null, null); + return glaccounts; + } + + private WorkbookPopulator populateGuarantorWorkbook(Long officeId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.STAFF_ENTITY_TYPE); + List offices = fetchOffices(officeId); + Listclients=fetchClients(officeId); + List loans = fetchLoanAccounts(officeId); + List savingsaccounts = fetchSavingsAccounts(officeId); + List guarantorRelationshipTypes=fetchCodeValuesByCodeName("GuarantorRelationship"); + return new GuarantorWorkbookPopulator(new OfficeSheetPopulator(offices), + new ClientSheetPopulator(clients, offices),loans,savingsaccounts,guarantorRelationshipTypes); + } + + private List fetchSavingsAccounts(Long officeId) { + List savingsAccounts=null; + if (officeId!=null) { + String activeAccounts="sa.status_enum = 300"; + SearchParameters searchParameters = SearchParameters.from(activeAccounts, officeId, null, null, null); + savingsAccounts = savingsAccountReadPlatformService.retrieveAll(searchParameters).getPageItems();; + }else { + savingsAccounts= savingsAccountReadPlatformService.retrieveAll(null).getPageItems(); + } + return savingsAccounts; + } + + + private WorkbookPopulator populateOfficeWorkbook() { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + List offices = fetchOffices(null); + return new OfficeWorkbookPopulator(offices); + } + + + + + private WorkbookPopulator populateChartOfAccountsWorkbook() { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.GL_ACCOUNT_ENTITY_TYPE); + List glAccounts = fetchGLAccounts(); + return new ChartOfAccountsWorkbook(glAccounts); + } + + + private WorkbookPopulator populateStaffWorkbook(Long officeId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + List offices=fetchOffices(officeId); + return new StaffWorkbookPopulator(new OfficeSheetPopulator(offices)); + } + + + + private WorkbookPopulator populateSharedAcountsWorkbook(Long officeId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CLIENT_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.SHARED_ACCOUNT_ENTITY_TYPE); + List shareProductDataList=fetchSharedProducts(); + List chargesForShares=fetchChargesForShares(); + List clientDataList=fetchClients(officeId); + ListofficeDataList=fetchOffices(officeId); + List savingsAccounts = fetchSavingsAccounts(officeId); + return new SharedAccountWorkBookPopulator(new SharedProductsSheetPopulator(shareProductDataList,chargesForShares), + new ClientSheetPopulator(clientDataList,officeDataList),new SavingsAccountSheetPopulator(savingsAccounts)); + } + + private List fetchChargesForShares() { + ListchargesForShares=(List) chargeReadPlatformService.retrieveSharesApplicableCharges(); + return chargesForShares; + } + + private List fetchSharedProducts() { + List productDataList = productReadPlatformService.retrieveAllProducts(0,50).getPageItems() ; + List sharedProductDataList=new ArrayList<>(); + if(productDataList!=null) { + for (ProductData data : productDataList) { + ShareProductData shareProduct = (ShareProductData) data; + sharedProductDataList.add(shareProduct); + } + } + return sharedProductDataList; + } + + + private WorkbookPopulator populateSavingsAccountWorkbook(Long officeId, Long staffId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.STAFF_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.GROUP_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CLIENT_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.SAVINGS_PRODUCT_ENTITY_TYPE); + List offices = fetchOffices(officeId); + List staff = fetchStaff(staffId); + List clients = fetchClients(officeId); + List groups = fetchGroups(officeId); + List savingsProducts=fetchSavingsProducts(); + return new SavingsWorkbookPopulator(new OfficeSheetPopulator(offices), new ClientSheetPopulator(clients, offices), + new GroupSheetPopulator(groups, offices), new PersonnelSheetPopulator(staff, offices), + new SavingsProductSheetPopulator(savingsProducts)); + } + + + + private WorkbookPopulator populateSavingsTransactionWorkbook(Long officeId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CLIENT_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.FUNDS_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.PAYMENT_TYPE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CURRENCY_ENTITY_TYPE); + List offices = fetchOffices(officeId); + List clients = fetchClients(officeId); + List funds = fetchFunds(); + List paymentTypes = fetchPaymentTypes(); + List currencies = fetchCurrencies(); + List savingsAccounts=fetchSavingsAccounts(officeId); + return new SavingsTransactionsWorkbookPopulator(new OfficeSheetPopulator(offices), new ClientSheetPopulator(clients, offices), + new ExtrasSheetPopulator(funds, paymentTypes, currencies),savingsAccounts); + } + + + private WorkbookPopulator populateRecurringDepositWorkbook(Long officeId,Long staffId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CLIENT_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.STAFF_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.RECURRING_DEPOSIT_PRODUCT_ENTITY_TYPE); + List offices = fetchOffices(officeId); + List clients = fetchClients(officeId); + List staff = fetchStaff(staffId); + List recurringDepositProducts = fetchRecurringDepositProducts(); + return new RecurringDepositWorkbookPopulator(new OfficeSheetPopulator(offices), new ClientSheetPopulator(clients, offices), + new PersonnelSheetPopulator(staff,offices),new RecurringDepositProductSheetPopulator(recurringDepositProducts)); + } + + private List fetchRecurringDepositProducts() { + List depositProducts=(List)depositProductReadPlatformService + .retrieveAll(DepositAccountType.RECURRING_DEPOSIT); + List recurringDepositProducts=new ArrayList<>(); + for (DepositProductData depositproduct: depositProducts) { + RecurringDepositProductData recurringDepositProduct= (RecurringDepositProductData) depositproduct; + recurringDepositProducts.add(recurringDepositProduct); + } + return recurringDepositProducts; + } + + + + private WorkbookPopulator populateRecurringDepositTransactionWorkbook(Long officeId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CLIENT_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.FUNDS_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.PAYMENT_TYPE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CURRENCY_ENTITY_TYPE); + List offices = fetchOffices(officeId); + List clients = fetchClients(officeId); + List funds = fetchFunds(); + List paymentTypes = fetchPaymentTypes(); + List currencies = fetchCurrencies(); + List savingsAccounts=fetchSavingsAccounts(officeId); + return new RecurringDepositTransactionWorkbookPopulator(new OfficeSheetPopulator(offices), new ClientSheetPopulator(clients, offices), + new ExtrasSheetPopulator(funds, paymentTypes, currencies),savingsAccounts); + } + + private WorkbookPopulator populateFixedDepositWorkbook(Long officeId, Long staffId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CLIENT_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.STAFF_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.FIXED_DEPOSIT_PRODUCT_ENTITY_TYPE); + List offices = fetchOffices(officeId); + List clients = fetchClients(officeId); + List staff = fetchStaff(staffId); + List fixedDepositProducts = fetchFixedDepositProducts(); + return new FixedDepositWorkbookPopulator(new OfficeSheetPopulator(offices), new ClientSheetPopulator(clients, offices), + new PersonnelSheetPopulator(staff,offices),new FixedDepositProductSheetPopulator(fixedDepositProducts)); + + + } + + private List fetchFixedDepositProducts() { + List depositProducts=(List)depositProductReadPlatformService + .retrieveAll(DepositAccountType.FIXED_DEPOSIT); + List fixedDepositProducts=new ArrayList<>(); + for (DepositProductData depositproduct: depositProducts) { + FixedDepositProductData fixedDepositProduct= (FixedDepositProductData) depositproduct; + fixedDepositProducts.add(fixedDepositProduct); + } + return fixedDepositProducts; + + } + + private WorkbookPopulator populateUserWorkbook(Long officeId, Long staffId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.USER_ENTITY_TYPE); + List offices = fetchOffices(officeId); + List staff = fetchStaff(staffId); + List roles=fetchRoles(); + return new UserWorkbookPopulator(new OfficeSheetPopulator(offices), new PersonnelSheetPopulator(staff,offices), + new RoleSheetPopulator(roles)); + } + + private List fetchRoles() { + List rolesList= (List) roleReadPlatformService.retrieveAllActiveRoles(); + return rolesList; + } + + private WorkbookPopulator populateFixedDepositTransactionsWorkbook(Long officeId) { + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.OFFICE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CLIENT_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.FUNDS_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.PAYMENT_TYPE_ENTITY_TYPE); + this.context.authenticatedUser().validateHasReadPermission(TemplatePopulateImportConstants.CURRENCY_ENTITY_TYPE); + List offices = fetchOffices(officeId); + List clients = fetchClients(officeId); + List funds = fetchFunds(); + List paymentTypes = fetchPaymentTypes(); + List currencies = fetchCurrencies(); + List savingsAccounts=fetchSavingsAccounts(officeId); + return new FixedDepositTransactionWorkbookPopulator(new OfficeSheetPopulator(offices), new ClientSheetPopulator(clients, offices), + new ExtrasSheetPopulator(funds, paymentTypes, currencies),savingsAccounts); + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookService.java new file mode 100644 index 000000000..c0ce1a929 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookService.java @@ -0,0 +1,40 @@ +/** + * 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.service; + +import com.sun.jersey.core.header.FormDataContentDisposition; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.data.ImportData; +import org.apache.fineract.infrastructure.documentmanagement.data.DocumentData; + +import javax.ws.rs.core.Response; +import java.io.InputStream; +import java.util.Collection; + +public interface BulkImportWorkbookService { + + public Long importWorkbook(String entityType, InputStream inputStream, FormDataContentDisposition fileDetail, + final String locale, final String dateFormat); + public Collection getImports(GlobalEntityType type); + + public DocumentData getOutputTemplateLocation(String importDocumentId); + + public Response getOutputTemplate(String importDocumentId); + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookServiceImpl.java new file mode 100644 index 000000000..b8f199cdb --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookServiceImpl.java @@ -0,0 +1,296 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE multipartFile + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this multipartFile + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this multipartFile 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.service; + +import com.google.common.io.Files; +import com.sun.jersey.core.header.FormDataContentDisposition; +import org.apache.fineract.infrastructure.bulkimport.data.BulkImportEvent; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.data.ImportData; +import org.apache.fineract.infrastructure.bulkimport.data.ImportFormatType; +import org.apache.fineract.infrastructure.bulkimport.domain.ImportDocument; +import org.apache.fineract.infrastructure.bulkimport.domain.ImportDocumentRepository; +import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler; +import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils; +import org.apache.fineract.infrastructure.core.domain.JdbcSupport; +import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; +import org.apache.fineract.infrastructure.core.service.DateUtils; +import org.apache.fineract.infrastructure.core.service.RoutingDataSource; +import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; +import org.apache.fineract.infrastructure.documentmanagement.data.DocumentData; +import org.apache.fineract.infrastructure.documentmanagement.domain.Document; +import org.apache.fineract.infrastructure.documentmanagement.domain.DocumentRepository; +import org.apache.fineract.infrastructure.documentmanagement.service.DocumentWritePlatformService; +import org.apache.fineract.infrastructure.documentmanagement.service.DocumentWritePlatformServiceJpaRepositoryImpl; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.tika.Tika; +import org.apache.tika.io.IOUtils; +import org.apache.tika.io.TikaInputStream; +import org.joda.time.LocalDate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; + +import javax.ws.rs.core.Response; +import java.io.*; +import java.net.URLConnection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; + +@Service +public class BulkImportWorkbookServiceImpl implements BulkImportWorkbookService { + private final ApplicationContext applicationContext; + private final PlatformSecurityContext securityContext; + private final DocumentWritePlatformService documentWritePlatformService; + private final DocumentRepository documentRepository; + private final ImportDocumentRepository importDocumentRepository; + private final JdbcTemplate jdbcTemplate; + + @Autowired + public BulkImportWorkbookServiceImpl(final ApplicationContext applicationContext, + final PlatformSecurityContext securityContext, + final DocumentWritePlatformService documentWritePlatformService, + final DocumentRepository documentRepository, + final ImportDocumentRepository importDocumentRepository, final RoutingDataSource dataSource) { + this.applicationContext = applicationContext; + this.securityContext = securityContext; + this.documentWritePlatformService = documentWritePlatformService; + this.documentRepository = documentRepository; + this.importDocumentRepository = importDocumentRepository; + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + @Override + public Long importWorkbook(String entity, InputStream inputStream, FormDataContentDisposition fileDetail, + final String locale, final String dateFormat) { + try { + if (entity !=null && inputStream!=null &&fileDetail!=null&&locale!=null&&dateFormat!=null) { + + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + IOUtils.copy(inputStream, baos); + final byte[] bytes = baos.toByteArray(); + InputStream clonedInputStream = new ByteArrayInputStream(bytes); + InputStream clonedInputStreamWorkbook =new ByteArrayInputStream(bytes); + final Tika tika = new Tika(); + final TikaInputStream tikaInputStream = TikaInputStream.get(clonedInputStream); + final String fileType = tika.detect(tikaInputStream); + final String fileExtension = Files.getFileExtension(fileDetail.getFileName()).toLowerCase(); + ImportFormatType format = ImportFormatType.of(fileExtension); + if (!fileType.contains("msoffice")) { + throw new GeneralPlatformDomainRuleException("error.msg.invalid.file.extension", + "Uploaded file extension is not recognized."); + } + Workbook workbook = new HSSFWorkbook(clonedInputStreamWorkbook); + GlobalEntityType entityType=null; + int primaryColumn=0; + ImportHandler importHandler = null; + if (entity.trim().equalsIgnoreCase(GlobalEntityType.CLIENTS_PERSON.toString())) { + entityType = GlobalEntityType.CLIENTS_PERSON; + primaryColumn = 0; + }else if(entity.trim().equalsIgnoreCase(GlobalEntityType.CLIENTS_ENTTTY.toString())){ + entityType = GlobalEntityType.CLIENTS_ENTTTY; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.CENTERS.toString())) { + entityType = GlobalEntityType.CENTERS; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.GROUPS.toString())) { + entityType = GlobalEntityType.GROUPS; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.LOANS.toString())) { + entityType = GlobalEntityType.LOANS; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.LOAN_TRANSACTIONS.toString())) { + entityType = GlobalEntityType.LOAN_TRANSACTIONS; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.GUARANTORS.toString())) { + entityType = GlobalEntityType.GUARANTORS; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.OFFICES.toString())) { + entityType = GlobalEntityType.OFFICES; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.CHART_OF_ACCOUNTS.toString())) { + entityType = GlobalEntityType.CHART_OF_ACCOUNTS; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.GL_JOURNAL_ENTRIES.toString())) { + entityType = GlobalEntityType.GL_JOURNAL_ENTRIES; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.STAFF.toString())) { + entityType = GlobalEntityType.STAFF; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.SHARE_ACCOUNTS.toString())) { + entityType = GlobalEntityType.SHARE_ACCOUNTS; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.SAVINGS_ACCOUNT.toString())) { + entityType = GlobalEntityType.SAVINGS_ACCOUNT; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.SAVINGS_TRANSACTIONS.toString())) { + entityType = GlobalEntityType.SAVINGS_TRANSACTIONS; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.RECURRING_DEPOSIT_ACCOUNTS.toString())) { + entityType = GlobalEntityType.RECURRING_DEPOSIT_ACCOUNTS; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.RECURRING_DEPOSIT_ACCOUNTS_TRANSACTIONS.toString())) { + entityType = GlobalEntityType.RECURRING_DEPOSIT_ACCOUNTS_TRANSACTIONS; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.FIXED_DEPOSIT_ACCOUNTS.toString())) { + entityType = GlobalEntityType.FIXED_DEPOSIT_ACCOUNTS; + primaryColumn = 0; + }else if (entity.trim().equalsIgnoreCase(GlobalEntityType.FIXED_DEPOSIT_TRANSACTIONS.toString())){ + entityType = GlobalEntityType.FIXED_DEPOSIT_TRANSACTIONS; + primaryColumn = 0; + }else if(entity.trim().equalsIgnoreCase(GlobalEntityType.USERS.toString())){ + entityType = GlobalEntityType.USERS; + primaryColumn = 0; + }else{ + throw new GeneralPlatformDomainRuleException("error.msg.unable.to.find.resource", + "Unable to find requested resource"); + } + return publishEvent(primaryColumn, fileDetail, clonedInputStreamWorkbook, entityType, + workbook, locale, dateFormat); + }else { + throw new GeneralPlatformDomainRuleException("error.msg.null","One or more of the given parameters not found"); + } + } catch (IOException e) { + e.printStackTrace(); + throw new GeneralPlatformDomainRuleException("error.msg.io.exception","IO exception occured with "+fileDetail.getFileName()+" "+e.getMessage()); + + } + } + + + private Long publishEvent(final Integer primaryColumn, + final FormDataContentDisposition fileDetail, final InputStream clonedInputStreamWorkbook, + final GlobalEntityType entityType, final Workbook workbook, + final String locale, final String dateFormat) { + + final String fileName = fileDetail.getFileName(); + + SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL); + + final Long documentId = this.documentWritePlatformService.createInternalDocument( + DocumentWritePlatformServiceJpaRepositoryImpl.DOCUMENT_MANAGEMENT_ENTITY.IMPORT.name(), + this.securityContext.authenticatedUser().getId(), null, clonedInputStreamWorkbook, + URLConnection.guessContentTypeFromName(fileName), fileName, null, fileName); + final Document document = this.documentRepository.findOne(documentId); + + final ImportDocument importDocument = ImportDocument.instance(document, + DateUtils.getLocalDateTimeOfTenant(), entityType.getValue(), + this.securityContext.authenticatedUser(), + ImportHandlerUtils.getNumberOfRows(workbook.getSheetAt(0), + primaryColumn)); + this.importDocumentRepository.saveAndFlush(importDocument); + BulkImportEvent event = BulkImportEvent.instance(ThreadLocalContextUtil.getTenant() + .getTenantIdentifier(), workbook, importDocument.getId(), locale, dateFormat); + applicationContext.publishEvent(event); + return importDocument.getId(); + } + @Override + public Collection getImports(GlobalEntityType type) { + this.securityContext.authenticatedUser(); + + final ImportMapper rm = new ImportMapper(); + final String sql = "select " + rm.schema() + " order by i.id desc"; + + return this.jdbcTemplate.query(sql, rm, new Object[] {type.getValue()}); + } + + + + private static final class ImportMapper implements RowMapper { + + public String schema() { + final StringBuilder sql = new StringBuilder(); + sql.append("i.id as id, i.document_id as documentId, d.name as name, i.import_time as importTime, i.end_time as endTime, ") + .append("i.completed as completed, i.total_records as totalRecords, i.success_count as successCount, ") + .append("i.failure_count as failureCount, i.createdby_id as createdBy ") + .append("from m_import_document i inner join m_document d on i.document_id=d.id ") + .append("where i.entity_type= ? "); + return sql.toString(); + } + + @Override + public ImportData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + + final Long id = rs.getLong("id"); + final Long documentId = rs.getLong("documentId"); + final String name = rs.getString("name"); + final LocalDate importTime = JdbcSupport.getLocalDate(rs, "importTime"); + final LocalDate endTime = JdbcSupport.getLocalDate(rs, "endTime"); + final Boolean completed = rs.getBoolean("completed"); + final Integer totalRecords = JdbcSupport.getInteger(rs, "totalRecords"); + final Integer successCount = JdbcSupport.getInteger(rs, "successCount"); + final Integer failureCount = JdbcSupport.getInteger(rs, "failureCount"); + final Long createdBy = rs.getLong("createdBy"); + + return ImportData.instance(id, documentId, importTime, endTime, completed, + name, createdBy, totalRecords, successCount, failureCount); + } + } + + @Override + public DocumentData getOutputTemplateLocation(String importDocumentId) { + this.securityContext.authenticatedUser(); + final ImportTemplateLocationMapper importTemplateLocationMapper=new ImportTemplateLocationMapper(); + final String sql = "select " + importTemplateLocationMapper.schema(); + + return this.jdbcTemplate.queryForObject(sql, importTemplateLocationMapper, new Object[] {importDocumentId}); + } + + @Override + public Response getOutputTemplate(String importDocumentId) { + this.securityContext.authenticatedUser(); + final ImportTemplateLocationMapper importTemplateLocationMapper=new ImportTemplateLocationMapper(); + final String sql = "select " + importTemplateLocationMapper.schema(); + DocumentData documentData= this.jdbcTemplate.queryForObject(sql, importTemplateLocationMapper, new Object[] {importDocumentId}); + return buildResponse(documentData); + } + + private Response buildResponse(DocumentData documentData) { + String fileName="Output"+documentData.fileName(); + String fileLocation=documentData.fileLocation(); + File file=new File(fileLocation); + final Response.ResponseBuilder response = Response.ok((Object)file); + response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\""); + response.header("Content-Type", "application/vnd.ms-excel"); + return response.build(); + } + + private static final class ImportTemplateLocationMapper implements RowMapper { + public String schema() { + final StringBuilder sql = new StringBuilder(); + sql.append("d.location,d.file_name ") + .append("from m_import_document i inner join m_document d on i.document_id=d.id ") + .append("where i.id= ? "); + return sql.toString(); + } + @Override + public DocumentData mapRow (ResultSet rs,int rowNum) throws SQLException { + final String location = rs.getString("location"); + final String fileName=rs.getString("file_name"); + return new DocumentData(null,null,null,null,fileName, + null,null,null,location,null); + } + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/data/CodeValueData.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/data/CodeValueData.java index 8b3a8192f..d7a5ca0ab 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/data/CodeValueData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/data/CodeValueData.java @@ -37,6 +37,15 @@ public class CodeValueData implements Serializable { private final boolean active; private final boolean mandatory; + public CodeValueData( final Long id){ + this.id = id; + this.name = null; + this.position = null; + this.description = null; + this.active = false; + this.mandatory = false; + } + public static CodeValueData instance(final Long id, final String name, final Integer position, final boolean isActive, final boolean mandatory) { String description = null; diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/data/PaginationParametersDataValidator.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/data/PaginationParametersDataValidator.java index c1edb48da..e5c67484e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/data/PaginationParametersDataValidator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/data/PaginationParametersDataValidator.java @@ -33,27 +33,24 @@ public class PaginationParametersDataValidator { private final Set sortOrderValues = new HashSet<>(Arrays.asList("ASC", "DESC")); public void validateParameterValues(PaginationParameters parameters, final Set supportedOrdeByValues, final String resourceName) { - final List dataValidationErrors = new ArrayList<>(); + if (parameters.isOrderByRequested() && !supportedOrdeByValues.contains(parameters.getOrderBy())) { + final String defaultUserMessage = "The orderBy value '" + parameters.getOrderBy() + + "' is not supported. The supported orderBy values are " + supportedOrdeByValues.toString(); + final ApiParameterError error = ApiParameterError.parameterError("validation.msg." + resourceName + + ".orderBy.value.is.not.supported", defaultUserMessage, "orderBy", parameters.getOrderBy(), + supportedOrdeByValues.toString()); + dataValidationErrors.add(error); + } - if (parameters.isOrderByRequested() && !supportedOrdeByValues.contains(parameters.getOrderBy())) { - final String defaultUserMessage = "The orderBy value '" + parameters.getOrderBy() - + "' is not supported. The supported orderBy values are " + supportedOrdeByValues.toString(); - final ApiParameterError error = ApiParameterError.parameterError("validation.msg." + resourceName - + ".orderBy.value.is.not.supported", defaultUserMessage, "orderBy", parameters.getOrderBy(), - supportedOrdeByValues.toString()); - dataValidationErrors.add(error); - } - - if (parameters.isSortOrderProvided() && !sortOrderValues.contains(parameters.getSortOrder().toUpperCase())) { - final String defaultUserMessage = "The sortOrder value '" + parameters.getSortOrder() - + "' is not supported. The supported sortOrder values are " + sortOrderValues.toString(); - final ApiParameterError error = ApiParameterError.parameterError("validation.msg." + resourceName - + ".sortOrder.value.is.not.supported", defaultUserMessage, "sortOrder", parameters.getSortOrder(), - sortOrderValues.toString()); - dataValidationErrors.add(error); - } - + if (parameters.isSortOrderProvided() && !sortOrderValues.contains(parameters.getSortOrder().toUpperCase())) { + final String defaultUserMessage = "The sortOrder value '" + parameters.getSortOrder() + + "' is not supported. The supported sortOrder values are " + sortOrderValues.toString(); + final ApiParameterError error = ApiParameterError.parameterError("validation.msg." + resourceName + + ".sortOrder.value.is.not.supported", defaultUserMessage, "sortOrder", parameters.getSortOrder(), + sortOrderValues.toString()); + dataValidationErrors.add(error); + } throwExceptionIfValidationWarningsExist(dataValidationErrors); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/DocumentWritePlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/DocumentWritePlatformService.java index 0e08deb57..fdf72a826 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/DocumentWritePlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/DocumentWritePlatformService.java @@ -35,4 +35,9 @@ public interface DocumentWritePlatformService { @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'DELETE_DOCUMENT')") CommandProcessingResult deleteDocument(DocumentCommand documentCommand); + @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'CREATE_DOCUMENT')") + Long createInternalDocument(String entityType, Long entityId, + Long fileSize, InputStream inputStream, String mimeType, + String name, String description, String fileName); + } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java index b229db573..1ddd86dc2 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java @@ -87,6 +87,22 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr } } + @Transactional + @Override + public Long createInternalDocument(final String entityType, final Long entityId, + final Long fileSize, final InputStream inputStream, final String mimeType, + final String name, final String description, final String fileName) { + + + final DocumentCommand documentCommand = new DocumentCommand(null, null, entityType, entityId, name, fileName, + fileSize, mimeType, description, null); + + final Long documentId = createDocument(documentCommand, inputStream); + + return documentId; + + } + @Transactional @Override public CommandProcessingResult updateDocument(final DocumentCommand documentCommand, final InputStream inputStream) { @@ -161,7 +177,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr /*** Entities for document Management **/ public static enum DOCUMENT_MANAGEMENT_ENTITY { - CLIENTS, CLIENT_IDENTIFIERS, STAFF, LOANS, SAVINGS, GROUPS; + CLIENTS, CLIENT_IDENTIFIERS, STAFF, LOANS, SAVINGS, GROUPS,IMPORT; @Override public String toString() { diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/data/CurrencyData.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/data/CurrencyData.java index 217e0960d..c3c87505c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/data/CurrencyData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/data/CurrencyData.java @@ -37,6 +37,16 @@ public class CurrencyData { return new CurrencyData("", "", 0, 0, "", ""); } + public CurrencyData(String code) { + this.code = code; + this.name = null; + this.decimalPlaces =0; + this.inMultiplesOf = null; + this.displaySymbol = null; + this.nameCode = null; + this.displayLabel = null; + } + public CurrencyData(final String code, final String name, final int decimalPlaces, final Integer inMultiplesOf, final String displaySymbol, final String nameCode) { this.code = code; @@ -83,4 +93,8 @@ public class CurrencyData { return builder.toString(); } + + public String getName() { + return name; + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficesApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficesApiResource.java index 9f0b109c6..f2c52da22 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficesApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficesApiResource.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.organisation.office.api; +import java.io.InputStream; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -34,11 +35,17 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; 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.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; @@ -70,16 +77,23 @@ public class OfficesApiResource { private final DefaultToApiJsonSerializer toApiJsonSerializer; private final ApiRequestParameterHelper apiRequestParameterHelper; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; + @Autowired public OfficesApiResource(final PlatformSecurityContext context, final OfficeReadPlatformService readPlatformService, final DefaultToApiJsonSerializer toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper, - final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) { + final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, + final BulkImportWorkbookService bulkImportWorkbookService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) { this.context = context; this.readPlatformService = readPlatformService; this.toApiJsonSerializer = toApiJsonSerializer; this.apiRequestParameterHelper = apiRequestParameterHelper; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + this.bulkImportWorkbookService=bulkImportWorkbookService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; } @GET @@ -165,4 +179,22 @@ public class OfficesApiResource { return this.toApiJsonSerializer.serialize(result); } + + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getOfficeTemplate(@QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.OFFICES.toString(), null,null,dateFormat); + } + + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postOfficeTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, + @FormDataParam("locale") final String locale, @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId = this.bulkImportWorkbookService.importWorkbook(GlobalEntityType.OFFICES.toString(), + uploadedInputStream,fileDetail, locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/data/OfficeData.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/data/OfficeData.java index 3ea04ee93..66688073d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/data/OfficeData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/data/OfficeData.java @@ -22,6 +22,7 @@ import java.io.Serializable; import java.util.Collection; import java.util.List; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.joda.time.LocalDate; /** @@ -40,6 +41,36 @@ public class OfficeData implements Serializable { @SuppressWarnings("unused") private final Collection allowedParents; + //import fields + private transient Integer rowIndex; + private String locale; + private String dateFormat; + + public static OfficeData importInstance(final String name, final Long parentId, final LocalDate openingDate,final String externalId) { + return new OfficeData(null, name, null, externalId, openingDate, null, parentId, null, null); + } + public void setImportFields(final Integer rowIndex, final String locale, final String dateFormat) { + this.rowIndex = rowIndex; + this.locale = locale; + this.dateFormat = dateFormat; + } + public static OfficeData testInstance(final Long id,final String name){ + return new OfficeData(id,name,null,null, + null,null,null,null, + null); + } + public LocalDate getOpeningDate() { + return openingDate; + } + + public Integer getRowIndex() { + return rowIndex; + } + + public Long getId() { + return id; + } + public static OfficeData dropdown(final Long id, final String name, final String nameDecorated) { return new OfficeData(id, name, nameDecorated, null, null, null, null, null, null); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/service/OfficeReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/service/OfficeReadPlatformServiceImpl.java index 79bd1a852..769b2a132 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/service/OfficeReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/service/OfficeReadPlatformServiceImpl.java @@ -156,17 +156,17 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService sqlBuilder.append("select "); sqlBuilder.append(rm.officeSchema()); sqlBuilder.append(" where o.hierarchy like ? "); + if(searchParameters!=null) { + if (searchParameters.isOrderByRequested()) { + sqlBuilder.append("order by ").append(searchParameters.getOrderBy()); - if (searchParameters.isOrderByRequested()) { - sqlBuilder.append("order by ").append(searchParameters.getOrderBy()); - - if (searchParameters.isSortOrderProvided()) { - sqlBuilder.append(' ').append(searchParameters.getSortOrder()); + if (searchParameters.isSortOrderProvided()) { + sqlBuilder.append(' ').append(searchParameters.getSortOrder()); + } + } else { + sqlBuilder.append("order by o.hierarchy"); } - } else { - sqlBuilder.append("order by o.hierarchy"); } - return this.jdbcTemplate.query(sqlBuilder.toString(), rm, new Object[] { hierarchySearchString }); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/api/StaffApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/api/StaffApiResource.java index c857874cb..d9ec51161 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/api/StaffApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/api/StaffApiResource.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.organisation.staff.api; +import java.io.InputStream; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -34,11 +35,17 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; 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.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; @@ -72,18 +79,25 @@ public class StaffApiResource { private final DefaultToApiJsonSerializer toApiJsonSerializer; private final ApiRequestParameterHelper apiRequestParameterHelper; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; + @Autowired public StaffApiResource(final PlatformSecurityContext context, final StaffReadPlatformService readPlatformService, final OfficeReadPlatformService officeReadPlatformService, final DefaultToApiJsonSerializer toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper, - final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) { + final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, + final BulkImportWorkbookService bulkImportWorkbookService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) { this.context = context; this.readPlatformService = readPlatformService; this.officeReadPlatformService = officeReadPlatformService; this.toApiJsonSerializer = toApiJsonSerializer; this.apiRequestParameterHelper = apiRequestParameterHelper; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + this.bulkImportWorkbookService=bulkImportWorkbookService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; } @GET @@ -150,4 +164,24 @@ public class StaffApiResource { return this.toApiJsonSerializer.serialize(result); } + + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getStaffTemplate(@QueryParam("officeId")final Long officeId, + @QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.STAFF.toString(), officeId,null,dateFormat); + } + + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postStaffTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, + @FormDataParam("locale") final String locale, + @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId = this. bulkImportWorkbookService.importWorkbook(GlobalEntityType.STAFF.toString(), uploadedInputStream, + fileDetail,locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/data/StaffData.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/data/StaffData.java index 45f0dbd54..265b67160 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/data/StaffData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/data/StaffData.java @@ -20,6 +20,7 @@ package org.apache.fineract.organisation.staff.data; import java.util.Collection; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.organisation.office.data.OfficeData; import org.joda.time.LocalDate; @@ -40,6 +41,41 @@ public class StaffData { private final Boolean isActive; private final LocalDate joiningDate; + //import fields + private transient Integer rowIndex; + private String dateFormat; + private String locale; + + public static StaffData importInstance(String externalId, String firstName, String lastName, String mobileNo, Long officeId, Boolean isLoanOfficer, + Boolean isActive, LocalDate joinedOnDate, Integer rowIndex,String locale, String dateFormat){ + return new StaffData(externalId,firstName,lastName,mobileNo,officeId,isLoanOfficer,isActive, + joinedOnDate,rowIndex,locale,dateFormat); + + } + private StaffData(String externalId, String firstname, String lastname, String mobileNo, Long officeId, Boolean isLoanOfficer, + Boolean isActive, LocalDate joiningDate, Integer rowIndex,String locale, String dateFormat) { + + this.externalId = externalId; + this.firstname = firstname; + this.lastname = lastname; + this.mobileNo = mobileNo; + this.officeId = officeId; + this.isLoanOfficer = isLoanOfficer; + this.isActive = isActive; + this.joiningDate = joiningDate; + this.rowIndex = rowIndex; + this.dateFormat= dateFormat; + this.locale= locale; + this.allowedOffices = null; + this.id = null; + this.officeName = null; + this.displayName = null; + } + + public Integer getRowIndex() { + return rowIndex; + } + @SuppressWarnings("unused") private final Collection allowedOffices; diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/service/StaffReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/service/StaffReadPlatformServiceImpl.java index ed675a17f..37c869c53 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/service/StaffReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/service/StaffReadPlatformServiceImpl.java @@ -241,14 +241,16 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService { } // Passing status parameter to get ACTIVE (By Default), INACTIVE or ALL // (Both active and Inactive) employees - if (status.equalsIgnoreCase("active")) { - extraCriteria.append(" and s.is_active = 1 "); - } else if (status.equalsIgnoreCase("inActive")) { - extraCriteria.append(" and s.is_active = 0 "); - } else if (status.equalsIgnoreCase("all")) {} else { - throw new UnrecognizedQueryParamException("status", status, new Object[] { "all", "active", "inactive" }); + if (status!=null) { + if (status.equalsIgnoreCase("active")) { + extraCriteria.append(" and s.is_active = 1 "); + } else if (status.equalsIgnoreCase("inActive")) { + extraCriteria.append(" and s.is_active = 0 "); + } else if (status.equalsIgnoreCase("all")) { + } else { + throw new UnrecognizedQueryParamException("status", status, new Object[]{"all", "active", "inactive"}); + } } - //adding the Authorization criteria so that a user cannot see an employee who does not belong to his office or a sub office for his office. extraCriteria.append(" and o.hierarchy like ? "); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/accounts/api/AccountsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/accounts/api/AccountsApiResource.java index f627c89a3..9e72b0b22 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/accounts/api/AccountsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/accounts/api/AccountsApiResource.java @@ -28,11 +28,17 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; 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.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; @@ -40,6 +46,7 @@ import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSer import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.portfolio.accounts.constants.AccountsApiConstants; +import org.apache.fineract.portfolio.accounts.constants.ShareAccountApiConstants; import org.apache.fineract.portfolio.accounts.data.AccountData; import org.apache.fineract.portfolio.accounts.service.AccountReadPlatformService; import org.apache.fineract.portfolio.products.exception.ResourceNotFoundException; @@ -49,6 +56,8 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; +import java.io.InputStream; + @Path("/accounts/{type}") @Component @@ -60,18 +69,24 @@ public class AccountsApiResource { private final DefaultToApiJsonSerializer toApiJsonSerializer; private final PlatformSecurityContext platformSecurityContext; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; @Autowired public AccountsApiResource(final ApplicationContext applicationContext, final ApiRequestParameterHelper apiRequestParameterHelper, final DefaultToApiJsonSerializer toApiJsonSerializer, final PlatformSecurityContext platformSecurityContext, - final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) { + final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, + final BulkImportWorkbookService bulkImportWorkbookService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) { this.applicationContext = applicationContext ; this.apiRequestParameterHelper = apiRequestParameterHelper ; this.toApiJsonSerializer = toApiJsonSerializer ; this.platformSecurityContext = platformSecurityContext ; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService ; + this.bulkImportWorkbookService=bulkImportWorkbookService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; } @GET @@ -160,4 +175,22 @@ public class AccountsApiResource { final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } + + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getSharedAccountsTemplate(@QueryParam("officeId") final Long officeId, + @QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.SHARE_ACCOUNTS.toString(),officeId, null,dateFormat); + } + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postSharedAccountsTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, + @FormDataParam("locale") final String locale, @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId = this. bulkImportWorkbookService.importWorkbook(GlobalEntityType.SHARE_ACCOUNTS.toString(), uploadedInputStream, + fileDetail,locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/data/AddressData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/data/AddressData.java index 8601b46a9..61bd88946 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/data/AddressData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/data/AddressData.java @@ -76,6 +76,38 @@ public class AddressData { private final Collection stateProvinceIdOptions; private final Collection addressTypeIdOptions; + public AddressData(Long addressTypeId,String street, String addressLine1, String addressLine2, String addressLine3, + String city,String postalCode, Boolean isActive,Long stateProvinceId,Long countryId) { + + this.addressTypeId = addressTypeId; + this.isActive = isActive; + this.street = street; + this.addressLine1 = addressLine1; + this.addressLine2 = addressLine2; + this.addressLine3 = addressLine3; + this.countryId = countryId; + this.postalCode = postalCode; + this.stateProvinceId = stateProvinceId; + this.city = city; + this.townVillage = null; + this.client_id = null; + this.addressType = null; + this.addressId = null; + this.countyDistrict = null; + this.countryName = null; + this.stateName = null; + this.latitude = null; + this.longitude = null; + this.createdBy = null; + this.createdOn = null; + this.updatedBy = null; + this.updatedOn = null; + this.countryIdOptions = null; + this.stateProvinceIdOptions = null; + this.addressTypeIdOptions = null; + } + + private AddressData(final String addressType, final Long client_id, final Long addressId, final Long addressTypeId, final Boolean is_active, final String street, final String addressLine1, final String addressLine2, final String addressLine3, final String townVillage, final String city, final String countyDistrict, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/data/CalendarData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/data/CalendarData.java index 2c6513a76..12fa06477 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/data/CalendarData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/data/CalendarData.java @@ -21,6 +21,7 @@ package org.apache.fineract.portfolio.calendar.data; import java.util.Collection; import java.util.List; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.portfolio.calendar.domain.CalendarFrequencyType; import org.apache.fineract.portfolio.calendar.domain.CalendarRemindBy; @@ -41,7 +42,7 @@ public class CalendarData { private final Long calendarInstanceId; private final Long entityId; private final EnumOptionData entityType; - private final String title; + private String title; private final String description; private final String location; private final LocalDate startDate; @@ -78,7 +79,123 @@ public class CalendarData { final List frequencyOptions; final List repeatsOnDayOptions; final List frequencyNthDayTypeOptions; - + + //import fields + private transient Integer rowIndex; + private String dateFormat; + private String locale; + private String centerId; + private String typeId; + + public static CalendarData importInstanceNoRepeatsOnDay(LocalDate startDate, boolean repeating, + EnumOptionData frequency, Integer interval,Integer rowIndex,String locale,String dateFormat){ + return new CalendarData(startDate, repeating, frequency, interval, rowIndex,locale,dateFormat); + + } + public static CalendarData importInstanceWithRepeatsOnDay(LocalDate startDate, boolean repeating, + EnumOptionData frequency,Integer interval,EnumOptionData repeatsOnDay,Integer rowIndex, + String locale,String dateFormat){ + return new CalendarData(startDate, repeating, frequency, interval, repeatsOnDay, rowIndex,locale,dateFormat); + } + private CalendarData(LocalDate startDate, boolean repeating,EnumOptionData frequency,Integer interval, + Integer rowIndex,String locale,String dateFormat) { + this.startDate = startDate; + this.repeating = repeating; + this.frequency = frequency; + this.interval = interval; + this.rowIndex=rowIndex; + this.dateFormat= dateFormat; + this.locale= locale; + this.description = ""; + this.typeId = "1"; + this.id = null; + this.calendarInstanceId = null; + this.entityId = null; + this.entityType = null; + this.title = null; + this.location = null; + this.endDate = null; + this.meetingTime = null; + this.type = null; + this.recurrence = null; + this.repeatsOnDay = null; + this.repeatsOnNthDayOfMonth = null; + this.remindBy = null; + this.firstReminder = null; + this.secondReminder = null; + this.recurringDates = null; + this.nextTenRecurringDates = null; + this.humanReadable = null; + this.recentEligibleMeetingDate =null; + this.createdDate = null; + this.lastUpdatedDate = null; + this.createdByUserId = null; + this.createdByUsername = null; + this.lastUpdatedByUserId = null; + this.lastUpdatedByUsername = null; + this.repeatsOnDayOfMonth = null; + this.entityTypeOptions = null; + this.calendarTypeOptions = null; + this.remindByOptions = null; + this.frequencyOptions = null; + this.repeatsOnDayOptions = null; + this.frequencyNthDayTypeOptions = null; + this.duration=null; + } + + private CalendarData(LocalDate startDate, boolean repeating,EnumOptionData frequency,Integer interval, + EnumOptionData repeatsOnDay,Integer rowIndex,String locale,String dateFormat) { + this.startDate = startDate; + this.repeating = repeating; + this.frequency = frequency; + this.interval = interval; + this.repeatsOnDay = repeatsOnDay; + this.rowIndex=rowIndex; + this.dateFormat= dateFormat; + this.locale= locale; + this.description = ""; + this.typeId = "1"; + this.id = null; + this.calendarInstanceId = null; + this.entityId = null; + this.entityType = null; + this.title = null; + this.location = null; + this.endDate = null; + this.meetingTime = null; + this.type = null; + this.recurrence = null; + this.repeatsOnNthDayOfMonth = null; + this.remindBy = null; + this.firstReminder = null; + this.secondReminder = null; + this.recurringDates = null; + this.nextTenRecurringDates = null; + this.humanReadable = null; + this.recentEligibleMeetingDate =null; + this.createdDate = null; + this.lastUpdatedDate = null; + this.createdByUserId = null; + this.createdByUsername = null; + this.lastUpdatedByUserId = null; + this.lastUpdatedByUsername = null; + this.repeatsOnDayOfMonth = null; + this.entityTypeOptions = null; + this.calendarTypeOptions = null; + this.remindByOptions = null; + this.frequencyOptions = null; + this.repeatsOnDayOptions = null; + this.frequencyNthDayTypeOptions = null; + this.duration=null; + } + public void setCenterId(String centerId) { + this.centerId = centerId; + } + + public void setTitle(String title){ + this.title=title; + } + public static CalendarData instance(final Long id, final Long calendarInstanceId, final Long entityId, final EnumOptionData entityType, final String title, final String description, final String location, final LocalDate startDate, final LocalDate endDate, final Integer duration, final EnumOptionData type, final boolean repeating, final String recurrence, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/data/ChargeData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/data/ChargeData.java index 9828962cc..179f245d9 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/data/ChargeData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/data/ChargeData.java @@ -308,4 +308,16 @@ public class ChargeData implements Comparable, Serializable { } return isOverdueInstallmentCharge; } + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public CurrencyData getCurrency() { + return currency; + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java index 090cc0a9e..a0c9d98a2 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java @@ -29,6 +29,7 @@ public class ClientApiConstants { public static final String CLIENT_RESOURCE_NAME = "client"; public static final String CLIENT_CHARGES_RESOURCE_NAME = "CLIENTCHARGE"; + // Client Charge Action Names public static final String CLIENT_CHARGE_ACTION_CREATE = "CREATE"; public static final String CLIENT_CHARGE_ACTION_DELETE = "DELETE"; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientsApiResource.java index f8bf7a88d..d0e0af329 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientsApiResource.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.portfolio.client.api; +import java.io.InputStream; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -35,12 +36,17 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; import org.apache.commons.lang.StringUtils; 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.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.exception.UnrecognizedQueryParamException; @@ -72,6 +78,8 @@ public class ClientsApiResource { private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final AccountDetailsReadPlatformService accountDetailsReadPlatformService; private final SavingsAccountReadPlatformService savingsAccountReadPlatformService; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; @Autowired public ClientsApiResource(final PlatformSecurityContext context, final ClientReadPlatformService readPlatformService, @@ -80,7 +88,9 @@ public class ClientsApiResource { final ApiRequestParameterHelper apiRequestParameterHelper, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final AccountDetailsReadPlatformService accountDetailsReadPlatformService, - final SavingsAccountReadPlatformService savingsAccountReadPlatformService) { + final SavingsAccountReadPlatformService savingsAccountReadPlatformService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService, + final BulkImportWorkbookService bulkImportWorkbookService) { this.context = context; this.clientReadPlatformService = readPlatformService; this.toApiJsonSerializer = toApiJsonSerializer; @@ -89,6 +99,8 @@ public class ClientsApiResource { this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.accountDetailsReadPlatformService = accountDetailsReadPlatformService; this.savingsAccountReadPlatformService = savingsAccountReadPlatformService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; + this.bulkImportWorkbookService=bulkImportWorkbookService; } @GET @@ -310,4 +322,23 @@ public class ClientsApiResource { final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.clientAccountSummaryToApiJsonSerializer.serialize(settings, clientAccount, CLIENT_ACCOUNTS_DATA_PARAMETERS); } + + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getClientTemplate(@QueryParam("legalFormType")final String legalFormType, + @QueryParam("officeId")final Long officeId,@QueryParam("staffId")final Long staffId, + @QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(legalFormType, officeId, staffId,dateFormat); + } + + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postClientTemplate(@QueryParam("legalFormType")final String legalFormType,@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("locale") final String locale, + @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId = bulkImportWorkbookService.importWorkbook(legalFormType, uploadedInputStream,fileDetail,locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientData.java index 3827307fc..680e03717 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientData.java @@ -21,10 +21,12 @@ package org.apache.fineract.portfolio.client.data; import java.util.Collection; import java.util.List; + import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.CompareToBuilder; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.dataqueries.data.DatatableData; @@ -106,6 +108,223 @@ final public class ClientData implements Comparable { private final List datatables; + //import fields + private transient Integer rowIndex; + private String dateFormat; + private String locale; + private Long clientTypeId; + private Long genderId; + private Long clientClassificationId; + private Long legalFormId; + private LocalDate submittedOnDate; + + public static ClientData importClientEntityInstance(Long legalFormId,Integer rowIndex,String fullname,Long officeId, Long clientTypeId, + Long clientClassificationId,Long staffId,Boolean active,LocalDate activationDate,LocalDate submittedOnDate, + String externalId,LocalDate dateOfBirth,String mobileNo,ClientNonPersonData clientNonPersonDetails, + AddressData address,String locale,String dateFormat){ + return new ClientData(legalFormId,rowIndex,fullname,officeId,clientTypeId,clientClassificationId, + staffId,active,activationDate,submittedOnDate, externalId,dateOfBirth,mobileNo,clientNonPersonDetails,address, + locale,dateFormat); + } + + public static ClientData importClientPersonInstance(Long legalFormId,Integer rowIndex,String firstName,String lastName,String middleName, + LocalDate submittedOn,LocalDate activationDate,Boolean active,String externalId,Long officeId, + Long staffId,String mobileNo, LocalDate dob,Long clientTypeId,Long genderId, + Long clientClassificationId,Boolean isStaff,AddressData address,String locale,String dateFormat){ + + return new ClientData(legalFormId,rowIndex,firstName,lastName,middleName,submittedOn,activationDate,active,externalId, + officeId,staffId,mobileNo,dob,clientTypeId,genderId,clientClassificationId,isStaff,address,locale,dateFormat); + } + + private ClientData(Long legalFormId,Integer rowIndex,String firstname,String lastname,String middlename, + LocalDate submittedOn,LocalDate activationDate,Boolean active,String externalId,Long officeId, + Long staffId,String mobileNo, LocalDate dob,Long clientTypeId,Long genderId, + Long clientClassificationId,Boolean isStaff,AddressData address,String locale,String dateFormat ) { + this.rowIndex=rowIndex; + this.dateFormat=dateFormat; + this.locale= locale; + this.firstname = firstname; + this.lastname = lastname; + this.middlename = middlename; + this.activationDate=activationDate; + this.submittedOnDate=submittedOn; + this.active=active; + this.externalId=externalId; + this.officeId=officeId; + this.staffId=staffId; + this.legalFormId=legalFormId; + this.mobileNo=mobileNo; + this.dateOfBirth=dob; + this.clientTypeId=clientTypeId; + this.genderId=genderId; + this.clientClassificationId=clientClassificationId; + this.isStaff=isStaff; + this.address=address; + this.id = null; + this.accountNo = null; + this.status = null; + this.subStatus = null; + this.fullname = null; + this.displayName = null; + this.gender = null; + this.clientType = null; + this.clientClassification = null; + this.officeName = null; + this.transferToOfficeId = null; + this.transferToOfficeName =null; + this.imageId = null; + this.imagePresent = null; + this.staffName = null; + this.timeline = null; + this.savingsProductId = null; + this.savingsProductName = null; + this.savingsAccountId =null; + this.legalForm = null; + this.groups = null; + this.officeOptions = null; + this.staffOptions = null; + this.narrations = null; + this.savingProductOptions = null; + this.savingAccountOptions = null; + this.genderOptions = null; + this.clientTypeOptions = null; + this.clientClassificationOptions = null; + this.clientNonPersonConstitutionOptions = null; + this.clientNonPersonMainBusinessLineOptions = null; + this.clientLegalFormOptions = null; + this.clientNonPersonDetails = null; + this.isAddressEnabled =null; + this.datatables = null; + this.familyMemberOptions=null; + } + + private ClientData(Long legalFormId,Integer rowIndex,String fullname,Long officeId, Long clientTypeId, + Long clientClassificationId,Long staffId,Boolean active,LocalDate activationDate,LocalDate submittedOnDate, + String externalId,LocalDate dateOfBirth,String mobileNo,ClientNonPersonData clientNonPersonDetails, + AddressData address,String locale,String dateFormat) { + this.id = null; + this.accountNo = null; + this.externalId = externalId; + this.status = null; + this.subStatus = null; + this.active = active; + this.activationDate = activationDate; + this.firstname = null; + this.middlename = null; + this.lastname = null; + this.fullname = fullname; + this.displayName = null; + this.mobileNo = mobileNo; + this.dateOfBirth = dateOfBirth; + this.gender = null; + this.clientType = null; + this.clientClassification = null; + this.isStaff = null; + this.officeId = officeId; + this.officeName = null; + this.transferToOfficeId = null; + this.transferToOfficeName = null; + this.imageId = null; + this.imagePresent = null; + this.staffId = staffId; + this.staffName = null; + this.timeline = null; + this.savingsProductId = null; + this.savingsProductName = null; + this.savingsAccountId = null; + this.legalForm = null; + this.groups = null; + this.officeOptions = null; + this.staffOptions = null; + this.narrations = null; + this.savingProductOptions = null; + this.savingAccountOptions = null; + this.genderOptions = null; + this.clientTypeOptions = null; + this.clientClassificationOptions = null; + this.clientNonPersonConstitutionOptions = null; + this.clientNonPersonMainBusinessLineOptions = null; + this.clientLegalFormOptions = null; + this.clientNonPersonDetails = clientNonPersonDetails; + this.address = address; + this.isAddressEnabled = null; + this.datatables = null; + this.rowIndex = rowIndex; + this.dateFormat=dateFormat; + this.locale= locale; + this.clientTypeId = clientTypeId; + this.genderId = null; + this.clientClassificationId = clientClassificationId; + this.legalFormId = legalFormId; + this.submittedOnDate = submittedOnDate; + this.familyMemberOptions=null; + } + + public ClientData(Long id) { + this.id = id; + this.accountNo = null; + this.externalId = null; + this.status = null; + this.subStatus = null; + this.active = null; + this.activationDate = null; + this.firstname = null; + this.middlename = null; + this.lastname = null; + this.fullname = null; + this.displayName = null; + this.mobileNo = null; + this.dateOfBirth = null; + this.gender = null; + this.clientType = null; + this.clientClassification = null; + this.isStaff = null; + this.officeId = null; + this.officeName = null; + this.transferToOfficeId = null; + this.transferToOfficeName = null; + this.imageId = null; + this.imagePresent = null; + this.staffId = null; + this.staffName = null; + this.timeline = null; + this.savingsProductId = null; + this.savingsProductName = null; + this.savingsAccountId = null; + this.legalForm = null; + this.groups = null; + this.officeOptions = null; + this.staffOptions = null; + this.narrations = null; + this.savingProductOptions = null; + this.savingAccountOptions = null; + this.genderOptions = null; + this.clientTypeOptions = null; + this.clientClassificationOptions = null; + this.clientNonPersonConstitutionOptions = null; + this.clientNonPersonMainBusinessLineOptions = null; + this.clientLegalFormOptions = null; + this.clientNonPersonDetails = null; + this.address = null; + this.isAddressEnabled = null; + this.datatables = null; + this.familyMemberOptions=null; + } + + public Integer getRowIndex() { + return rowIndex; + } + + public Long getSavingsAccountId() { + return savingsAccountId; + } + + public Long getId(){return id;} + + public String getOfficeName() { + return officeName; + } + public static ClientData template(final Long officeId, final LocalDate joinedDate, final Collection officeOptions, final Collection staffOptions, final Collection narrations, final Collection genderOptions, final Collection savingProductOptions, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientNonPersonData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientNonPersonData.java index d6ffdb9ec..f81c92158 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientNonPersonData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientNonPersonData.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.portfolio.client.data; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.joda.time.LocalDate; @@ -32,6 +33,31 @@ public class ClientNonPersonData { private final LocalDate incorpValidityTillDate; private final CodeValueData mainBusinessLine; private final String remarks; + + //import fields + private Long mainBusinessLineId; + private Long constitutionId; + private String locale; + private String dateFormat; + + public static ClientNonPersonData importInstance(String incorporationNo, LocalDate incorpValidityTillDate, + String remarks, Long mainBusinessLineId, Long constitutionId,String locale,String dateFormat){ + return new ClientNonPersonData(incorporationNo,incorpValidityTillDate,remarks, + mainBusinessLineId,constitutionId,locale,dateFormat); + } + private ClientNonPersonData(String incorpNumber, LocalDate incorpValidityTillDate, + String remarks, Long mainBusinessLineId, Long constitutionId,String locale,String dateFormat) { + + this.incorpNumber = incorpNumber; + this.incorpValidityTillDate = incorpValidityTillDate; + this.remarks = remarks; + this.mainBusinessLineId = mainBusinessLineId; + this.constitutionId = constitutionId; + this.dateFormat= dateFormat; + this.locale= locale; + this.constitution = null; + this.mainBusinessLine = null; + } public ClientNonPersonData(CodeValueData constitution, String incorpNo, LocalDate incorpValidityTillDate, CodeValueData mainBusinessLine, String remarks) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformServiceImpl.java index b5e88259b..9c0b9325d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformServiceImpl.java @@ -189,33 +189,34 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService sqlBuilder.append("select SQL_CALC_FOUND_ROWS "); sqlBuilder.append(this.clientMapper.schema()); sqlBuilder.append(" where (o.hierarchy like ? or transferToOffice.hierarchy like ?) "); - - if(searchParameters.isSelfUser()){ - sqlBuilder.append(" and c.id in (select umap.client_id from m_selfservice_user_client_mapping as umap where umap.appuser_id = ? ) "); - paramList.add(appUserID); - } - final String extraCriteria = buildSqlStringFromClientCriteria(this.clientMapper.schema(), searchParameters, paramList); - - if (StringUtils.isNotBlank(extraCriteria)) { - sqlBuilder.append(" and (").append(extraCriteria).append(")"); - } + if(searchParameters!=null) { + if (searchParameters.isSelfUser()) { + sqlBuilder.append(" and c.id in (select umap.client_id from m_selfservice_user_client_mapping as umap where umap.appuser_id = ? ) "); + paramList.add(appUserID); + } - if (searchParameters.isOrderByRequested()) { - sqlBuilder.append(" order by ").append(searchParameters.getOrderBy()); + final String extraCriteria = buildSqlStringFromClientCriteria(this.clientMapper.schema(), searchParameters, paramList); - if (searchParameters.isSortOrderProvided()) { - sqlBuilder.append(' ').append(searchParameters.getSortOrder()); + if (StringUtils.isNotBlank(extraCriteria)) { + sqlBuilder.append(" and (").append(extraCriteria).append(")"); + } + + if (searchParameters.isOrderByRequested()) { + sqlBuilder.append(" order by ").append(searchParameters.getOrderBy()); + + if (searchParameters.isSortOrderProvided()) { + sqlBuilder.append(' ').append(searchParameters.getSortOrder()); + } + } + + if (searchParameters.isLimited()) { + sqlBuilder.append(" limit ").append(searchParameters.getLimit()); + if (searchParameters.isOffset()) { + sqlBuilder.append(" offset ").append(searchParameters.getOffset()); + } } } - - if (searchParameters.isLimited()) { - sqlBuilder.append(" limit ").append(searchParameters.getLimit()); - if (searchParameters.isOffset()) { - sqlBuilder.append(" offset ").append(searchParameters.getOffset()); - } - } - final String sqlCountRows = "SELECT FOUND_ROWS()"; return this.paginationHelper.fetchPage(this.jdbcTemplate, sqlCountRows, sqlBuilder.toString(), paramList.toArray(), this.clientMapper); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/data/FundData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/data/FundData.java index 58d8a9ec1..2857cafad 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/data/FundData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/data/FundData.java @@ -41,4 +41,12 @@ public class FundData implements Serializable { this.name = name; this.externalId = externalId; } + + public String getName() { + return name; + } + + public Long getId() { + return id; + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/CentersApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/CentersApiResource.java index 0195e99cd..c590fcdd4 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/CentersApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/CentersApiResource.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.portfolio.group.api; +import java.io.InputStream; import java.util.*; import javax.ws.rs.Consumes; @@ -32,13 +33,19 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; import org.apache.commons.lang.StringUtils; import org.apache.fineract.accounting.journalentry.api.DateParam; 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.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.core.api.ApiParameterHelper; import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; import org.apache.fineract.infrastructure.core.api.JsonQuery; @@ -93,6 +100,8 @@ public class CentersApiResource { private final CalendarReadPlatformService calendarReadPlatformService; private final MeetingReadPlatformService meetingReadPlatformService; private final EntityDatatableChecksReadService entityDatatableChecksReadService; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; @Autowired public CentersApiResource(final PlatformSecurityContext context, final CenterReadPlatformService centerReadPlatformService, @@ -103,7 +112,9 @@ public class CentersApiResource { final CollectionSheetReadPlatformService collectionSheetReadPlatformService, final FromJsonHelper fromJsonHelper, final AccountDetailsReadPlatformService accountDetailsReadPlatformService, final CalendarReadPlatformService calendarReadPlatformService, final MeetingReadPlatformService meetingReadPlatformService, - final EntityDatatableChecksReadService entityDatatableChecksReadService) { + final EntityDatatableChecksReadService entityDatatableChecksReadService, + final BulkImportWorkbookService bulkImportWorkbookService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) { this.context = context; this.centerReadPlatformService = centerReadPlatformService; this.centerApiJsonSerializer = centerApiJsonSerializer; @@ -117,6 +128,8 @@ public class CentersApiResource { this.calendarReadPlatformService = calendarReadPlatformService; this.meetingReadPlatformService = meetingReadPlatformService; this.entityDatatableChecksReadService = entityDatatableChecksReadService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; + this.bulkImportWorkbookService=bulkImportWorkbookService; } @GET @@ -334,4 +347,21 @@ public class CentersApiResource { final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.groupSummaryToApiJsonSerializer.serialize(settings, groupAccount, GROUP_ACCOUNTS_DATA_PARAMETERS); } + + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getCentersTemplate(@QueryParam("officeId")final Long officeId,@QueryParam("staffId")final Long staffId, + @QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.CENTERS.toString(), officeId,staffId,dateFormat); + } + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postCentersTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, + @FormDataParam("locale") final String locale, @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId=this. bulkImportWorkbookService.importWorkbook(GlobalEntityType.CENTERS.toString(), uploadedInputStream,fileDetail,locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/GroupsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/GroupsApiResource.java index 96dc132a9..10d369d67 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/GroupsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/GroupsApiResource.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.portfolio.group.api; +import java.io.InputStream; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -36,12 +37,18 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; import org.apache.commons.lang.StringUtils; 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.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.core.api.ApiParameterHelper; import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; import org.apache.fineract.infrastructure.core.api.JsonQuery; @@ -104,6 +111,9 @@ public class GroupsApiResource { private final CalendarReadPlatformService calendarReadPlatformService; private final MeetingReadPlatformService meetingReadPlatformService; private final EntityDatatableChecksReadService entityDatatableChecksReadService; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; + @Autowired public GroupsApiResource(final PlatformSecurityContext context, final GroupReadPlatformService groupReadPlatformService, @@ -117,7 +127,9 @@ public class GroupsApiResource { final GroupRolesReadPlatformService groupRolesReadPlatformService, final AccountDetailsReadPlatformService accountDetailsReadPlatformService, final CalendarReadPlatformService calendarReadPlatformService, final MeetingReadPlatformService meetingReadPlatformService, - final EntityDatatableChecksReadService entityDatatableChecksReadService) { + final EntityDatatableChecksReadService entityDatatableChecksReadService, + final BulkImportWorkbookService bulkImportWorkbookService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) { this.context = context; this.groupReadPlatformService = groupReadPlatformService; @@ -135,6 +147,8 @@ public class GroupsApiResource { this.calendarReadPlatformService = calendarReadPlatformService; this.meetingReadPlatformService = meetingReadPlatformService; this.entityDatatableChecksReadService = entityDatatableChecksReadService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; + this.bulkImportWorkbookService=bulkImportWorkbookService; } @GET @@ -441,4 +455,24 @@ public class GroupsApiResource { final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.groupSummaryToApiJsonSerializer.serialize(settings, groupAccount, GROUP_ACCOUNTS_DATA_PARAMETERS); } + + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getGroupsTemplate(@QueryParam("officeId")final Long officeId, + @QueryParam("staffId")final Long staffId,@QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.GROUPS.toString(), + officeId, staffId,dateFormat); + } + + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postGroupTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, + @FormDataParam("locale") final String locale, @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId = this. bulkImportWorkbookService.importWorkbook(GlobalEntityType.GROUPS.toString(), + uploadedInputStream,fileDetail,locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/CenterData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/CenterData.java index 2d2828d60..7369a206f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/CenterData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/CenterData.java @@ -22,6 +22,7 @@ import java.math.BigDecimal; import java.util.Collection; import java.util.List; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.dataqueries.data.DatatableData; @@ -67,6 +68,59 @@ public class CenterData { private List datatables = null; + //import fields + private transient Integer rowIndex; + private String dateFormat; + private String locale; + private LocalDate submittedOnDate; + + public static CenterData importInstance(String name,List groupMembers,LocalDate activationDate, + boolean active ,LocalDate submittedOnDate,String externalId, Long officeId, + Long staffId,Integer rowIndex,String dateFormat,String locale){ + + return new CenterData(name,groupMembers,activationDate, active,submittedOnDate, externalId, officeId, staffId, rowIndex,dateFormat,locale); + } + + private CenterData(String name,List groupMembers,LocalDate activationDate, + boolean active ,LocalDate submittedOnDate,String externalId, Long officeId, + Long staffId,Integer rowIndex,String dateFormat,String locale) { + this.name = name; + this.groupMembers=groupMembers; + this.externalId = externalId; + this.officeId = officeId; + this.staffId = staffId; + this.active = active; + this.activationDate = activationDate; + this.submittedOnDate=submittedOnDate; + this.rowIndex = rowIndex; + this.dateFormat= dateFormat; + this.locale=locale; + this.status=null; + this.id=null; + this.accountNo = null; + this.staffName = null; + this.hierarchy = null; + this.timeline = null; + this.groupMembersOptions = null; + this.collectionMeetingCalendar = null; + this.closureReasons =null; + this.officeOptions = null; + this.staffOptions = null; + this.totalCollected =null; + this.totalOverdue = null; + this.totaldue = null; + this.installmentDue = null; + this.officeName=null; + } + + public Integer getRowIndex() { + return rowIndex; + } + + public String getOfficeName() { + return officeName; + } + public static CenterData template(final Long officeId, final String accountNo, final LocalDate activationDate, final Collection officeOptions, final Collection staffOptions, final Collection groupMembersOptions, final BigDecimal totalCollected, final BigDecimal totalOverdue, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/GroupGeneralData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/GroupGeneralData.java index d6c225964..5781bb8d4 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/GroupGeneralData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/data/GroupGeneralData.java @@ -21,6 +21,7 @@ package org.apache.fineract.portfolio.group.data; import java.util.Collection; import java.util.List; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.dataqueries.data.DatatableData; @@ -74,6 +75,104 @@ public class GroupGeneralData { private List datatables = null; + //import fields + private transient Integer rowIndex; + private String dateFormat; + private String locale; + private LocalDate submittedOnDate; + + public static GroupGeneralData importInstance(String groupName,List clientMembers,LocalDate activationDate, + LocalDate submittedOnDate ,Boolean active,String externalId,Long officeId,Long staffId, + Long centerId, Integer rowIndex,String locale,String dateFormat){ + + return new GroupGeneralData(groupName, clientMembers, activationDate, submittedOnDate,active, externalId, + officeId, staffId, centerId, rowIndex,locale,dateFormat); + } + + private GroupGeneralData(String name,List clientMembers,LocalDate activationDate, + LocalDate submittedOnDate ,Boolean active,String externalId,Long officeId,Long staffId, + Long centerId, Integer rowIndex,String locale,String dateFormat ){ + this.dateFormat= dateFormat; + this.locale= locale; + this.name = name; + this.clientMembers = clientMembers; + this.officeId = officeId; + this.staffId = staffId; + this.centerId = centerId; + this.externalId = externalId; + this.active = active; + this.activationDate = activationDate; + this.submittedOnDate=submittedOnDate; + this.rowIndex = rowIndex; + this.id=null; + this.accountNo = null; + this.status = null; + this.officeName = null; + this.centerName =null; + this.staffName = null; + this.hierarchy = null; + this.groupLevel = null; + this.activeClientMembers = null; + this.groupRoles = null; + this.calendarsData = null; + this.collectionMeetingCalendar = null; + this.centerOptions = null; + this.officeOptions = null; + this.staffOptions = null; + this.clientOptions = null; + this.availableRoles = null; + this.selectedRole = null; + this.closureReasons = null; + this.timeline = null; + } + + public GroupGeneralData(Long id) { + this.id = id; + this.accountNo = null; + this.name = null; + this.externalId = null; + this.status = null; + this.active = null; + this.activationDate = null; + this.officeId = null; + this.officeName = null; + this.centerId = null; + this.centerName = null; + this.staffId = null; + this.staffName = null; + this.hierarchy = null; + this.groupLevel = null; + this.clientMembers = null; + this.activeClientMembers = null; + this.groupRoles = null; + this.calendarsData = null; + this.collectionMeetingCalendar = null; + this.centerOptions = null; + this.officeOptions = null; + this.staffOptions = null; + this.clientOptions = null; + this.availableRoles = null; + this.selectedRole = null; + this.closureReasons = null; + this.timeline = null; + } + + public Integer getRowIndex() { + return rowIndex; + } + + public Long getCenterId() { + return centerId; + } + + public LocalDate getActivationDate() { + return activationDate; + } + + public String getOfficeName() { + return officeName; + } + public static GroupGeneralData lookup(final Long groupId, final String accountNo, final String groupName) { final Collection clientMembers = null; final Collection groupRoles = null; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java index 34350c2bd..38823fb8d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/CenterReadPlatformServiceImpl.java @@ -127,50 +127,50 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService StringBuffer extraCriteria = new StringBuffer(200); extraCriteria.append(" and g.level_id = " + GroupTypes.CENTER.getId()); + if (searchCriteria!=null) { + String sqlQueryCriteria = searchCriteria.getSqlSearch(); + if (StringUtils.isNotBlank(sqlQueryCriteria)) { + SQLInjectionValidator.validateSQLInput(sqlQueryCriteria); + sqlQueryCriteria = sqlQueryCriteria.replaceAll(" display_name ", " g.display_name "); + sqlQueryCriteria = sqlQueryCriteria.replaceAll("display_name ", "g.display_name "); + extraCriteria.append(" and (").append(sqlQueryCriteria).append(") "); + this.columnValidator.validateSqlInjection(schemaSl, sqlQueryCriteria); + } - String sqlQueryCriteria = searchCriteria.getSqlSearch(); - if (StringUtils.isNotBlank(sqlQueryCriteria)) { - SQLInjectionValidator.validateSQLInput(sqlQueryCriteria); - sqlQueryCriteria = sqlQueryCriteria.replaceAll(" display_name ", " g.display_name "); - sqlQueryCriteria = sqlQueryCriteria.replaceAll("display_name ", "g.display_name "); - extraCriteria.append(" and (").append(sqlQueryCriteria).append(") "); - this.columnValidator.validateSqlInjection(schemaSl, sqlQueryCriteria); + final Long officeId = searchCriteria.getOfficeId(); + if (officeId != null) { + extraCriteria.append(" and g.office_id = ? "); + paramList.add(officeId); + } + + final String externalId = searchCriteria.getExternalId(); + if (externalId != null) { + paramList.add(ApiParameterHelper.sqlEncodeString(externalId)); + extraCriteria.append(" and g.external_id = ? "); + } + + final String name = searchCriteria.getName(); + if (name != null) { + paramList.add(ApiParameterHelper.sqlEncodeString(name + "%")); + extraCriteria.append(" and g.display_name like ? "); + } + + final String hierarchy = searchCriteria.getHierarchy(); + if (hierarchy != null) { + paramList.add(ApiParameterHelper.sqlEncodeString(hierarchy + "%")); + extraCriteria.append(" and o.hierarchy like ? "); + } + + if (StringUtils.isNotBlank(extraCriteria.toString())) { + extraCriteria.delete(0, 4); + } + + final Long staffId = searchCriteria.getStaffId(); + if (staffId != null) { + paramList.add(staffId); + extraCriteria.append(" and g.staff_id = ? "); + } } - - final Long officeId = searchCriteria.getOfficeId(); - if (officeId != null) { - extraCriteria.append(" and g.office_id = ? "); - paramList.add(officeId); - } - - final String externalId = searchCriteria.getExternalId(); - if (externalId != null) { - paramList.add(ApiParameterHelper.sqlEncodeString(externalId)); - extraCriteria.append(" and g.external_id = ? "); - } - - final String name = searchCriteria.getName(); - if (name != null) { - paramList.add(ApiParameterHelper.sqlEncodeString(name + "%")); - extraCriteria.append(" and g.display_name like ? "); - } - - final String hierarchy = searchCriteria.getHierarchy(); - if (hierarchy != null) { - paramList.add(ApiParameterHelper.sqlEncodeString(hierarchy + "%")); - extraCriteria.append(" and o.hierarchy like ? "); - } - - if (StringUtils.isNotBlank(extraCriteria.toString())) { - extraCriteria.delete(0, 4); - } - - final Long staffId = searchCriteria.getStaffId(); - if (staffId != null) { - paramList.add(staffId); - extraCriteria.append(" and g.staff_id = ? "); - } - return extraCriteria.toString(); } @@ -409,8 +409,9 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService @Override public Collection retrieveAll(SearchParameters searchParameters, PaginationParameters parameters) { - - this.paginationParametersDataValidator.validateParameterValues(parameters, supportedOrderByValues, "audits"); + if (parameters!=null) { + this.paginationParametersDataValidator.validateParameterValues(parameters, supportedOrderByValues, "audits"); + } final AppUser currentUser = this.context.authenticatedUser(); final String hierarchy = currentUser.getOffice().getHierarchy(); final String hierarchySearchString = hierarchy + "%"; @@ -421,24 +422,24 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService sqlBuilder.append(" where o.hierarchy like ?"); List paramList = new ArrayList<>( Arrays.asList(hierarchySearchString)); - + if (searchParameters!=null) { final String extraCriteria = getCenterExtraCriteria(this.centerMapper.schema(), paramList, searchParameters); this.columnValidator.validateSqlInjection(sqlBuilder.toString(), extraCriteria); if (StringUtils.isNotBlank(extraCriteria)) { sqlBuilder.append(" and (").append(extraCriteria).append(")"); } - if (searchParameters.isOrderByRequested()) { - sqlBuilder.append(" order by ").append(searchParameters.getOrderBy()).append(' ').append(searchParameters.getSortOrder()); - } + if (searchParameters.isOrderByRequested()) { + sqlBuilder.append(" order by ").append(searchParameters.getOrderBy()).append(' ').append(searchParameters.getSortOrder()); + } - if (searchParameters.isLimited()) { - sqlBuilder.append(" limit ").append(searchParameters.getLimit()); - if (searchParameters.isOffset()) { - sqlBuilder.append(" offset ").append(searchParameters.getOffset()); + if (searchParameters.isLimited()) { + sqlBuilder.append(" limit ").append(searchParameters.getLimit()); + if (searchParameters.isOffset()) { + sqlBuilder.append(" offset ").append(searchParameters.getOffset()); + } } } - return this.jdbcTemplate.query(sqlBuilder.toString(), this.centerMapper, paramList.toArray()); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupReadPlatformServiceImpl.java index 8dd0ed61a..e8a1fd630 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupReadPlatformServiceImpl.java @@ -188,19 +188,22 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { sqlBuilder.append(" where o.hierarchy like ?"); List paramList = new ArrayList<>( Arrays.asList(hierarchySearchString)); - final String extraCriteria = getGroupExtraCriteria(this.allGroupTypesDataMapper.schema(), paramList, searchParameters); - if (StringUtils.isNotBlank(extraCriteria)) { - sqlBuilder.append(" and (").append(extraCriteria).append(")"); - } + if (searchParameters!=null) { + final String extraCriteria = getGroupExtraCriteria(this.allGroupTypesDataMapper.schema(), paramList, searchParameters); - if (parameters.isOrderByRequested()) { - sqlBuilder.append(parameters.orderBySql()); + if (StringUtils.isNotBlank(extraCriteria)) { + sqlBuilder.append(" and (").append(extraCriteria).append(")"); + } } + if (parameters!=null) { + if (parameters.isOrderByRequested()) { + sqlBuilder.append(parameters.orderBySql()); + } - if (parameters.isLimited()) { - sqlBuilder.append(parameters.limitSql()); + if (parameters.isLimited()) { + sqlBuilder.append(parameters.limitSql()); + } } - return this.jdbcTemplate.query(sqlBuilder.toString(), this.allGroupTypesDataMapper, paramList.toArray()); } @@ -211,58 +214,57 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { StringBuffer extraCriteria = new StringBuffer(200); extraCriteria.append(" and g.level_Id = ").append(GroupTypes.GROUP.getId()); - String sqlSearch = searchCriteria.getSqlSearch(); - if (sqlSearch != null) { - SQLInjectionValidator.validateSQLInput(sqlSearch); - sqlSearch = sqlSearch.replaceAll(" display_name ", " g.display_name "); - sqlSearch = sqlSearch.replaceAll("display_name ", "g.display_name "); - extraCriteria.append(" and ( ").append(sqlSearch).append(") "); - this.columnValidator.validateSqlInjection(schemaSql, sqlSearch); - } + String sqlSearch = searchCriteria.getSqlSearch(); + if (sqlSearch != null) { + SQLInjectionValidator.validateSQLInput(sqlSearch); + sqlSearch = sqlSearch.replaceAll(" display_name ", " g.display_name "); + sqlSearch = sqlSearch.replaceAll("display_name ", "g.display_name "); + extraCriteria.append(" and ( ").append(sqlSearch).append(") "); + this.columnValidator.validateSqlInjection(schemaSql, sqlSearch); + } - final Long officeId = searchCriteria.getOfficeId(); - if (officeId != null) { - paramList.add(officeId); - extraCriteria.append(" and g.office_id = ? "); - } + final Long officeId = searchCriteria.getOfficeId(); + if (officeId != null) { + paramList.add(officeId); + extraCriteria.append(" and g.office_id = ? "); + } - final String externalId = searchCriteria.getExternalId(); - if (externalId != null) { - paramList.add(ApiParameterHelper.sqlEncodeString(externalId)); - extraCriteria.append(" and g.external_id = ? "); - } + final String externalId = searchCriteria.getExternalId(); + if (externalId != null) { + paramList.add(ApiParameterHelper.sqlEncodeString(externalId)); + extraCriteria.append(" and g.external_id = ? "); + } - final String name = searchCriteria.getName(); - if (name != null) { - paramList.add(ApiParameterHelper.sqlEncodeString("%" + name + "%")); - extraCriteria.append(" and g.display_name like ? "); - } + final String name = searchCriteria.getName(); + if (name != null) { + paramList.add(ApiParameterHelper.sqlEncodeString("%" + name + "%")); + extraCriteria.append(" and g.display_name like ? "); + } - final String hierarchy = searchCriteria.getHierarchy(); - if (hierarchy != null) { - paramList.add(ApiParameterHelper.sqlEncodeString(hierarchy + "%")); - extraCriteria.append(" and o.hierarchy like ? "); - } + final String hierarchy = searchCriteria.getHierarchy(); + if (hierarchy != null) { + paramList.add(ApiParameterHelper.sqlEncodeString(hierarchy + "%")); + extraCriteria.append(" and o.hierarchy like ? "); + } - if (searchCriteria.isStaffIdPassed()) { - paramList.add(searchCriteria.getStaffId()); - extraCriteria.append(" and g.staff_id = ? "); - } + if (searchCriteria.isStaffIdPassed()) { + paramList.add(searchCriteria.getStaffId()); + extraCriteria.append(" and g.staff_id = ? "); + } - if (StringUtils.isNotBlank(extraCriteria.toString())) { - extraCriteria.delete(0, 4); - } + if (StringUtils.isNotBlank(extraCriteria.toString())) { + extraCriteria.delete(0, 4); + } - final Long staffId = searchCriteria.getStaffId(); - if (staffId != null) { - paramList.add(staffId); - extraCriteria.append(" and g.staff_id = ? "); - } - - if(searchCriteria.isOrphansOnly()){ - extraCriteria.append(" and g.parent_id IS NULL"); - } + final Long staffId = searchCriteria.getStaffId(); + if (staffId != null) { + paramList.add(staffId); + extraCriteria.append(" and g.staff_id = ? "); + } + if (searchCriteria.isOrphansOnly()) { + extraCriteria.append(" and g.parent_id IS NULL"); + } return extraCriteria.toString(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java index e3c51c761..b1c6223af 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java @@ -20,6 +20,7 @@ package org.apache.fineract.portfolio.loanaccount.api; import static org.apache.fineract.portfolio.loanproduct.service.LoanEnumerations.interestType; +import java.io.InputStream; import java.util.*; import javax.ws.rs.Consumes; @@ -34,12 +35,18 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; import org.apache.commons.lang.StringUtils; 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.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService; import org.apache.fineract.infrastructure.core.api.ApiParameterHelper; @@ -169,6 +176,9 @@ public class LoansApiResource { private final LoanScheduleHistoryReadPlatformService loanScheduleHistoryReadPlatformService; private final AccountDetailsReadPlatformService accountDetailsReadPlatformService; private final EntityDatatableChecksReadService entityDatatableChecksReadService; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; + @Autowired public LoansApiResource(final PlatformSecurityContext context, final LoanReadPlatformService loanReadPlatformService, @@ -189,7 +199,9 @@ public class LoansApiResource { final AccountAssociationsReadPlatformService accountAssociationsReadPlatformService, final LoanScheduleHistoryReadPlatformService loanScheduleHistoryReadPlatformService, final AccountDetailsReadPlatformService accountDetailsReadPlatformService, - final EntityDatatableChecksReadService entityDatatableChecksReadService) { + final EntityDatatableChecksReadService entityDatatableChecksReadService, + final BulkImportWorkbookService bulkImportWorkbookService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) { this.context = context; this.loanReadPlatformService = loanReadPlatformService; this.loanProductReadPlatformService = loanProductReadPlatformService; @@ -215,6 +227,8 @@ public class LoansApiResource { this.loanScheduleHistoryReadPlatformService = loanScheduleHistoryReadPlatformService; this.accountDetailsReadPlatformService = accountDetailsReadPlatformService; this.entityDatatableChecksReadService = entityDatatableChecksReadService; + this.bulkImportWorkbookService=bulkImportWorkbookService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; } /* @@ -755,4 +769,41 @@ public class LoansApiResource { private boolean is(final String commandParam, final String commandValue) { return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue); } + + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getLoansTemplate(@QueryParam("officeId") final Long officeId, + @QueryParam("staffId") final Long staffId,@QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.LOANS.toString(), officeId, staffId,dateFormat); + } + + @GET + @Path("repayments/downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getLoanRepaymentTemplate(@QueryParam("officeId") final Long officeId, + @QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.LOAN_TRANSACTIONS.toString(), officeId, null,dateFormat); + } + + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postLoanTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, + @FormDataParam("locale") final String locale, @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId = this. bulkImportWorkbookService.importWorkbook(GlobalEntityType.LOANS.toString(), uploadedInputStream,fileDetail,locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } + + @POST + @Path("repayments/uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postLoanRepaymentTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail,@FormDataParam("locale") final String locale, + @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId = this.bulkImportWorkbookService.importWorkbook(GlobalEntityType.LOAN_TRANSACTIONS.toString(), uploadedInputStream,fileDetail, + locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/DisbursementData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/DisbursementData.java index 939a0acfd..6e9c7081a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/DisbursementData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/DisbursementData.java @@ -20,6 +20,7 @@ package org.apache.fineract.portfolio.loanaccount.data; import java.math.BigDecimal; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.joda.time.LocalDate; /** @@ -37,6 +38,38 @@ public class DisbursementData implements Comparable { private final BigDecimal chargeAmount; private final BigDecimal waivedChargeAmount; + //import fields + private transient Integer rowIndex; + private String dateFormat; + private String locale; + private String note; + private transient String linkAccountId; + + public static DisbursementData importInstance(LocalDate actualDisbursementDate,String linkAccountId, + Integer rowIndex,String locale,String dateFormat){ + return new DisbursementData(actualDisbursementDate,linkAccountId,rowIndex,locale,dateFormat); + } + private DisbursementData(LocalDate actualDisbursementDate,String linkAccountId, + Integer rowIndex,String locale,String dateFormat) { + this.dateFormat= dateFormat; + this.locale= locale; + this.actualDisbursementDate = actualDisbursementDate; + this.rowIndex = rowIndex; + this.note=""; + this.linkAccountId=linkAccountId; + this.id=null; + this.expectedDisbursementDate=null; + this.principal=null; + this.loanChargeId=null; + this.chargeAmount=null; + this.waivedChargeAmount=null; + + } + + public String getLinkAccountId() { + return linkAccountId; + } + public DisbursementData(Long id, final LocalDate expectedDisbursementDate, final LocalDate actualDisbursementDate, final BigDecimal principalDisbursed, final String loanChargeId, BigDecimal chargeAmount, BigDecimal waivedChargeAmount) { this.id = id; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanAccountData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanAccountData.java index 5109c3e71..fbcf5c0ae 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanAccountData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanAccountData.java @@ -23,6 +23,7 @@ import java.util.*; import javax.persistence.Transient; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.dataqueries.data.DatatableData; @@ -214,6 +215,393 @@ public class LoanAccountData { private List datatables = null; + //import fields + private String dateFormat; + private String locale; + private transient Integer rowIndex; + private LocalDate submittedOnDate; + private Long productId; + private Integer loanTermFrequency; + private EnumOptionData loanTermFrequencyType; + private LocalDate repaymentsStartingFromDate; + private String linkAccountId; + private Long groupId; + private LocalDate expectedDisbursementDate; + + public static LoanAccountData importInstanceIndividual(EnumOptionData loanTypeEnumOption,Long clientId,Long productId, + Long loanOfficerId,LocalDate submittedOnDate, + Long fundId,BigDecimal principal, Integer numberOfRepayments,Integer repaymentEvery, + EnumOptionData repaidEveryFrequencyEnums, Integer loanTermFrequency,EnumOptionData loanTermFrequencyTypeEnum, + BigDecimal nominalInterestRate,LocalDate expectedDisbursementDate ,EnumOptionData amortizationEnumOption, + EnumOptionData interestMethodEnum, EnumOptionData interestCalculationPeriodTypeEnum,BigDecimal inArrearsTolerance,Long transactionProcessingStrategyId, + Integer graceOnPrincipalPayment,Integer graceOnInterestPayment,Integer graceOnInterestCharged, + LocalDate interestChargedFromDate,LocalDate repaymentsStartingFromDate,Integer rowIndex , + String externalId,Long groupId,Collection charges,String linkAccountId, + String locale,String dateFormat){ + + return new LoanAccountData(loanTypeEnumOption, clientId, productId, loanOfficerId, submittedOnDate, fundId, + principal, numberOfRepayments, + repaymentEvery, repaidEveryFrequencyEnums, loanTermFrequency, loanTermFrequencyTypeEnum, nominalInterestRate, expectedDisbursementDate, + amortizationEnumOption, interestMethodEnum, interestCalculationPeriodTypeEnum, inArrearsTolerance, transactionProcessingStrategyId, + graceOnPrincipalPayment, graceOnInterestPayment, graceOnInterestCharged, interestChargedFromDate, repaymentsStartingFromDate, + rowIndex, externalId, null, charges, linkAccountId,locale,dateFormat); + } + + private LoanAccountData(EnumOptionData loanType,Long clientId,Long productId,Long loanOfficerId,LocalDate submittedOnDate, + Long fundId,BigDecimal principal, Integer numberOfRepayments,Integer repaymentEvery, + EnumOptionData repaymentFrequencyType, Integer loanTermFrequency,EnumOptionData loanTermFrequencyType, + BigDecimal interestRatePerPeriod,LocalDate expectedDisbursementDate ,EnumOptionData amortizationType, + EnumOptionData interestType, EnumOptionData interestCalculationPeriodType,BigDecimal inArrearsTolerance,Long transactionProcessingStrategyId, + Integer graceOnPrincipalPayment,Integer graceOnInterestPayment,Integer graceOnInterestCharged, + LocalDate interestChargedFromDate,LocalDate repaymentsStartingFromDate,Integer rowIndex , + String externalId,Long groupId,Collection charges,String linkAccountId, + String locale,String dateFormat) { + this.dateFormat=dateFormat; + this.locale= locale; + this.rowIndex=rowIndex; + this.submittedOnDate=submittedOnDate; + this.productId=productId; + this.loanTermFrequency=loanTermFrequency; + this.loanTermFrequencyType=loanTermFrequencyType; + this.repaymentsStartingFromDate=repaymentsStartingFromDate; + this.linkAccountId=linkAccountId; + this.externalId = externalId; + this.clientId = clientId; + this.fundId = fundId; + this.loanOfficerId = loanOfficerId; + this.numberOfRepayments = numberOfRepayments; + this.loanType = loanType; + this.principal = principal; + this.repaymentEvery = repaymentEvery; + this.repaymentFrequencyType = repaymentFrequencyType; + this.interestRatePerPeriod = interestRatePerPeriod; + this.amortizationType = amortizationType; + this.interestType = interestType; + this.interestCalculationPeriodType = interestCalculationPeriodType; + this.inArrearsTolerance = inArrearsTolerance; + this.transactionProcessingStrategyId = transactionProcessingStrategyId; + this.graceOnInterestPayment = graceOnInterestPayment; + this.graceOnInterestCharged = graceOnInterestCharged; + this.graceOnPrincipalPayment = graceOnPrincipalPayment; + this.interestChargedFromDate = interestChargedFromDate; + this.groupId=groupId; + this.expectedDisbursementDate=expectedDisbursementDate; + this.charges = charges; + this.id = null; + this.accountNo = null; + + this.status = null; + this.subStatus = null; + + this.clientAccountNo = null; + this.clientName = null; + this.clientOfficeId = null; + this.group = null; + this.loanProductId = null; + this.loanProductName = null; + this.loanProductDescription = null; + this.isLoanProductLinkedToFloatingRate = false; + + this.fundName = null; + this.loanPurposeId = null; + this.loanPurposeName = null; + + this.loanOfficerName = null; + + this.currency = null; + + this.approvedPrincipal = null; + this.proposedPrincipal = null; + this.termFrequency = null; + this.termPeriodFrequencyType = null; + + + this.repaymentFrequencyNthDayType = null; + this.repaymentFrequencyDayOfWeekType = null; + + this.interestRateFrequencyType = null; + this.annualInterestRate = null; + this.isFloatingInterestRate = false; + this.interestRateDifferential = null; + + this.allowPartialPeriodInterestCalcualtion = null; + + this.transactionProcessingStrategyName = null; + + this.recurringMoratoriumOnPrincipalPeriods = null; + + this.graceOnArrearsAgeing = null; + + this.expectedFirstRepaymentOnDate = null; + this.syncDisbursementWithMeeting = null; + this.timeline = null; + this.summary = null; + this.repaymentSchedule = null; + this.transactions = null; + + this.collateral = null; + this.guarantors = null; + this.meeting = null; + this.notes = null; + this.disbursementDetails = null; + this.originalSchedule = null; + this.productOptions = null; + this.loanOfficerOptions = null; + this.loanPurposeOptions = null; + this.fundOptions = null; + this.termFrequencyTypeOptions = null; + this.repaymentFrequencyTypeOptions = null; + this.repaymentFrequencyNthDayTypeOptions = null; + this.repaymentFrequencyDaysOfWeekTypeOptions = null; + this.interestRateFrequencyTypeOptions = null; + this.amortizationTypeOptions = null; + this.interestTypeOptions = null; + this.interestCalculationPeriodTypeOptions = null; + this.transactionProcessingStrategyOptions = null; + this.chargeOptions = null; + this.loanCollateralOptions = null; + this.calendarOptions = null; + this.feeChargesAtDisbursementCharged = null; + this.totalOverpaid = null; + this.loanCounter = null; + this.loanProductCounter = null; + this.linkedAccount = null; + this.accountLinkingOptions = null; + this.multiDisburseLoan = null; + this.canDefineInstallmentAmount = null; + this.fixedEmiAmount = null; + this.maxOutstandingLoanBalance = null; + this.canDisburse = null; + this.emiAmountVariations = null; + this.clientActiveLoanOptions = null; + this.canUseForTopup = null; + this.isTopup = false; + this.closureLoanId = null; + this.closureLoanAccountNo = null; + this.topupAmount = null; + this.memberVariations = null; + this.inArrears = null; + this.isNPA = null; + this.overdueCharges = null; + this.daysInMonthType = null; + this.daysInYearType = null; + this.isInterestRecalculationEnabled = false; + this.interestRecalculationData = null; + this.createStandingInstructionAtDisbursement = null; + this.paidInAdvance = null; + this.interestRatesPeriods = null; + this.isVariableInstallmentsAllowed = null; + this.minimumGap = null; + this.maximumGap = null; + } + + public static LoanAccountData importInstanceGroup(EnumOptionData loanTypeEnumOption,Long groupIdforGroupLoan,Long productId, + Long loanOfficerId,LocalDate submittedOnDate, + Long fundId,BigDecimal principal, Integer numberOfRepayments,Integer repaidEvery, + EnumOptionData repaidEveryFrequencyEnums, Integer loanTermFrequency,EnumOptionData loanTermFrequencyTypeEnum, + BigDecimal nominalInterestRate, EnumOptionData amortizationEnumOption,EnumOptionData interestMethodEnum, + EnumOptionData interestCalculationPeriodEnum,BigDecimal arrearsTolerance, + Long transactionProcessingStrategyId, + Integer graceOnPrincipalPayment,Integer graceOnInterestPayment,Integer graceOnInterestCharged, + LocalDate interestChargedFromDate,LocalDate repaymentsStartingFromDate, + Integer rowIndex ,String externalId,String linkAccountId,String locale,String dateFormat){ + + return new LoanAccountData(loanTypeEnumOption, groupIdforGroupLoan, productId, loanOfficerId, submittedOnDate, fundId, + principal, numberOfRepayments, + repaidEvery, repaidEveryFrequencyEnums, loanTermFrequency, loanTermFrequencyTypeEnum, nominalInterestRate, + amortizationEnumOption, interestMethodEnum, interestCalculationPeriodEnum, arrearsTolerance, + transactionProcessingStrategyId, graceOnPrincipalPayment, graceOnInterestPayment, graceOnInterestCharged, + interestChargedFromDate, repaymentsStartingFromDate, rowIndex, externalId, linkAccountId,locale,dateFormat); + } + private LoanAccountData(EnumOptionData loanType,Long clientId,Long productId,Long loanOfficerId,LocalDate submittedOnDate, + Long fundId,BigDecimal principal, Integer numberOfRepayments,Integer repaymentEvery, + EnumOptionData repaymentFrequencyType, Integer loanTermFrequency,EnumOptionData loanTermFrequencyType, + BigDecimal interestRatePerPeriod, EnumOptionData amortizationType,EnumOptionData interestType, + EnumOptionData interestCalculationPeriodType,BigDecimal inArrearsTolerance, + Long transactionProcessingStrategyId, + Integer graceOnPrincipalPayment,Integer graceOnInterestPayment,Integer graceOnInterestCharged, + LocalDate interestChargedFromDate,LocalDate repaymentsStartingFromDate, + Integer rowIndex ,String externalId,String linkAccountId,String locale,String dateFormat) { + this.dateFormat=dateFormat; + this.locale= locale; + this.rowIndex=rowIndex; + this.submittedOnDate=submittedOnDate; + this.productId=productId; + this.loanTermFrequency=loanTermFrequency; + this.loanTermFrequencyType=loanTermFrequencyType; + this.repaymentsStartingFromDate=repaymentsStartingFromDate; + this.linkAccountId=linkAccountId; + this.externalId = externalId; + this.clientId = clientId; + this.fundId = fundId; + this.loanOfficerId = loanOfficerId; + this.numberOfRepayments = numberOfRepayments; + this.loanType = loanType; + this.principal = principal; + this.repaymentEvery = repaymentEvery; + this.repaymentFrequencyType = repaymentFrequencyType; + this.interestRatePerPeriod = interestRatePerPeriod; + this.amortizationType = amortizationType; + this.interestType = interestType; + this.interestCalculationPeriodType = interestCalculationPeriodType; + this.inArrearsTolerance = inArrearsTolerance; + this.transactionProcessingStrategyId = transactionProcessingStrategyId; + this.graceOnInterestPayment = graceOnInterestPayment; + this.graceOnInterestCharged = graceOnInterestCharged; + this.graceOnPrincipalPayment = graceOnPrincipalPayment; + this.interestChargedFromDate = interestChargedFromDate; + this.groupId=null; + this.charges = null; + this.id = null; + this.accountNo = null; + + this.status = null; + this.subStatus = null; + + this.clientAccountNo = null; + this.clientName = null; + this.clientOfficeId = null; + this.group = null; + this.loanProductId = null; + this.loanProductName = null; + this.loanProductDescription = null; + this.isLoanProductLinkedToFloatingRate = false; + + this.fundName = null; + this.loanPurposeId = null; + this.loanPurposeName = null; + + this.loanOfficerName = null; + + this.currency = null; + + this.approvedPrincipal = null; + this.proposedPrincipal = null; + this.termFrequency = null; + this.termPeriodFrequencyType = null; + + + this.repaymentFrequencyNthDayType = null; + this.repaymentFrequencyDayOfWeekType = null; + + this.interestRateFrequencyType = null; + this.annualInterestRate = null; + this.isFloatingInterestRate = false; + this.interestRateDifferential = null; + + this.allowPartialPeriodInterestCalcualtion = null; + + this.transactionProcessingStrategyName = null; + + this.recurringMoratoriumOnPrincipalPeriods = null; + + this.graceOnArrearsAgeing = null; + + this.expectedFirstRepaymentOnDate = null; + this.syncDisbursementWithMeeting = null; + this.timeline = null; + this.summary = null; + this.repaymentSchedule = null; + this.transactions = null; + + this.collateral = null; + this.guarantors = null; + this.meeting = null; + this.notes = null; + this.disbursementDetails = null; + this.originalSchedule = null; + this.productOptions = null; + this.loanOfficerOptions = null; + this.loanPurposeOptions = null; + this.fundOptions = null; + this.termFrequencyTypeOptions = null; + this.repaymentFrequencyTypeOptions = null; + this.repaymentFrequencyNthDayTypeOptions = null; + this.repaymentFrequencyDaysOfWeekTypeOptions = null; + this.interestRateFrequencyTypeOptions = null; + this.amortizationTypeOptions = null; + this.interestTypeOptions = null; + this.interestCalculationPeriodTypeOptions = null; + this.transactionProcessingStrategyOptions = null; + this.chargeOptions = null; + this.loanCollateralOptions = null; + this.calendarOptions = null; + this.feeChargesAtDisbursementCharged = null; + this.totalOverpaid = null; + this.loanCounter = null; + this.loanProductCounter = null; + this.linkedAccount = null; + this.accountLinkingOptions = null; + this.multiDisburseLoan = null; + this.canDefineInstallmentAmount = null; + this.fixedEmiAmount = null; + this.maxOutstandingLoanBalance = null; + this.canDisburse = null; + this.emiAmountVariations = null; + this.clientActiveLoanOptions = null; + this.canUseForTopup = null; + this.isTopup = false; + this.closureLoanId = null; + this.closureLoanAccountNo = null; + this.topupAmount = null; + this.memberVariations = null; + this.inArrears = null; + this.isNPA = null; + this.overdueCharges = null; + this.daysInMonthType = null; + this.daysInYearType = null; + this.isInterestRecalculationEnabled = false; + this.interestRecalculationData = null; + this.createStandingInstructionAtDisbursement = null; + this.paidInAdvance = null; + this.interestRatesPeriods = null; + this.isVariableInstallmentsAllowed = null; + this.minimumGap = null; + this.maximumGap = null; + } + + + public Integer getRowIndex() { + return rowIndex; + } + + public Long getClientId() { + return clientId; + } + + public String getClientName() { + return clientName; + } + + public BigDecimal getPrincipal() { + return principal; + } + + public LoanApplicationTimelineData getTimeline() { + return timeline; + } + + public String getAccountNo() { + return accountNo; + } + + public String getLoanProductName() { + return loanProductName; + } + + public static final Comparator ClientNameComparator = new Comparator() { + + @Override + public int compare(LoanAccountData loan1, LoanAccountData loan2) { + String clientOfLoan1 = loan1.getClientName().toUpperCase(Locale.ENGLISH); + String clientOfLoan2 = loan2.getClientName().toUpperCase(Locale.ENGLISH); + return clientOfLoan1.compareTo(clientOfLoan2); + } + }; + + public String getClientAccountNo() { + return clientAccountNo; + } /** * Used to produce a {@link LoanAccountData} with only collateral options * for now. @@ -1622,4 +2010,8 @@ public class LoanAccountData { public void setDatatables(final List datatables) { this.datatables = datatables; } + + public String getStatusStringValue(){ + return this.status.value(); + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanApprovalData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanApprovalData.java index 5d3a06c38..ef80f1b60 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanApprovalData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanApprovalData.java @@ -20,6 +20,7 @@ package org.apache.fineract.portfolio.loanaccount.data; import java.math.BigDecimal; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.joda.time.LocalDate; /** @@ -30,6 +31,27 @@ public class LoanApprovalData { private final LocalDate approvalDate; private final BigDecimal approvalAmount; + //import fields + private LocalDate approvedOnDate; + private String note; + private String dateFormat; + private String locale; + private transient Integer rowIndex; + + public static LoanApprovalData importInstance(LocalDate approvedOnDate, Integer rowIndex, + String locale,String dateFormat){ + return new LoanApprovalData(approvedOnDate,rowIndex,locale,dateFormat); + } + private LoanApprovalData(LocalDate approvedOnDate, Integer rowIndex,String locale,String dateFormat) { + this.approvedOnDate = approvedOnDate; + this.rowIndex = rowIndex; + this.dateFormat=dateFormat; + this.locale= locale; + this.note=""; + this.approvalAmount=null; + this.approvalDate=null; + } + public LoanApprovalData(final BigDecimal approvalAmount, final LocalDate approvalDate) { this.approvalDate = approvalDate; this.approvalAmount = approvalAmount; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanTransactionData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanTransactionData.java index 39d689957..e3424fa88 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanTransactionData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanTransactionData.java @@ -21,6 +21,7 @@ package org.apache.fineract.portfolio.loanaccount.data; import java.math.BigDecimal; import java.util.Collection; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.organisation.monetary.data.CurrencyData; import org.apache.fineract.portfolio.account.data.AccountTransferData; @@ -66,6 +67,116 @@ public class LoanTransactionData { private Collection writeOffReasonOptions = null; + //import fields + private transient Integer rowIndex; + private String dateFormat; + private String locale; + private BigDecimal transactionAmount; + private LocalDate transactionDate; + private Long paymentTypeId; + private String accountNumber; + private Integer checkNumber; + private Integer routingCode; + private Integer receiptNumber; + private Integer bankNumber; + private transient Integer accountId; + private transient String transactionType; + + public static LoanTransactionData importInstance(BigDecimal repaymentAmount,LocalDate lastRepaymentDate, + Long repaymentTypeId,Integer rowIndex,String locale,String dateFormat){ + return new LoanTransactionData(repaymentAmount, lastRepaymentDate, repaymentTypeId, rowIndex,locale,dateFormat); + } + private LoanTransactionData(BigDecimal transactionAmount,LocalDate transactionDate, + Long paymentTypeId,Integer rowIndex,String locale,String dateFormat) { + this.transactionAmount=transactionAmount; + this.transactionDate=transactionDate; + this.paymentTypeId=paymentTypeId; + this.rowIndex = rowIndex; + this.dateFormat= dateFormat; + this.locale= locale; + this.amount = null; + this.date = null; + this.type = null; + this.id =null; + this.officeId = null; + this.officeName = null; + this.currency = null; + this.paymentDetailData = null; + this.principalPortion = null; + this.interestPortion = null; + this.feeChargesPortion = null; + this.penaltyChargesPortion = null; + this.overpaymentPortion = null; + this.unrecognizedIncomePortion = null; + this.externalId = null; + this.transfer = null; + this.fixedEmiAmount = null; + this.outstandingLoanBalance = null; + this.submittedOnDate = null; + this.manuallyReversed = false; + this.possibleNextRepaymentDate = null; + this.paymentTypeOptions = null; + this.writeOffReasonOptions = null; + } + public static LoanTransactionData importInstance(BigDecimal repaymentAmount,LocalDate repaymentDate, + Long repaymentTypeId, String accountNumber,Integer checkNumber,Integer routingCode, + Integer receiptNumber, Integer bankNumber,Integer loanAccountId,String transactionType, + Integer rowIndex,String locale, String dateFormat){ + return new LoanTransactionData(repaymentAmount, repaymentDate, repaymentTypeId, accountNumber, + checkNumber, routingCode, receiptNumber, bankNumber, loanAccountId, "", + rowIndex,locale,dateFormat); + } + + private LoanTransactionData(BigDecimal transactionAmount,LocalDate transactionDate, Long paymentTypeId, + String accountNumber,Integer checkNumber,Integer routingCode,Integer receiptNumber, + Integer bankNumber,Integer accountId,String transactionType,Integer rowIndex,String locale, + String dateFormat) { + this.transactionAmount = transactionAmount; + this.transactionDate = transactionDate; + this.paymentTypeId = paymentTypeId; + this.accountNumber=accountNumber; + this.checkNumber=checkNumber; + this.routingCode=routingCode; + this.receiptNumber=receiptNumber; + this.bankNumber=bankNumber; + this.accountId=accountId; + this.transactionType=transactionType; + this.rowIndex=rowIndex; + this.dateFormat=dateFormat; + this.locale= locale; + this.id = null; + this.officeId = null; + this.officeName = null; + this.type = null; + this.date = null; + this.currency = null; + this.paymentDetailData = null; + this.amount = null; + this.principalPortion = null; + this.interestPortion = null; + this.feeChargesPortion = null; + this.penaltyChargesPortion = null; + this.overpaymentPortion = null; + this.unrecognizedIncomePortion = null; + this.externalId = null; + this.transfer = null; + this.fixedEmiAmount = null; + this.outstandingLoanBalance = null; + this.submittedOnDate = null; + this.manuallyReversed = false; + this.possibleNextRepaymentDate = null; + this.paymentTypeOptions = null; + this.writeOffReasonOptions = null; + } + + public Integer getAccountId() { + return accountId; + } + + public Integer getRowIndex() { + return rowIndex; + } + public static LoanTransactionData templateOnTop(final LoanTransactionData loanTransactionData, final Collection paymentTypeOptions) { return new LoanTransactionData(loanTransactionData.id, loanTransactionData.officeId, loanTransactionData.officeName, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/api/GuarantorsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/api/GuarantorsApiResource.java index 948036e89..1be3d268e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/api/GuarantorsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/api/GuarantorsApiResource.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.portfolio.loanaccount.guarantor.api; +import java.io.InputStream; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -35,11 +36,17 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; 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.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService; import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; @@ -89,6 +96,9 @@ public class GuarantorsApiResource { private final PlatformSecurityContext context; private final PortfolioAccountReadPlatformService portfolioAccountReadPlatformService; private final LoanReadPlatformService loanReadPlatformService; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; + @Autowired public GuarantorsApiResource(final PlatformSecurityContext context, final GuarantorReadPlatformService guarantorReadPlatformService, @@ -96,7 +106,9 @@ public class GuarantorsApiResource { final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final CodeValueReadPlatformService codeValueReadPlatformService, final PortfolioAccountReadPlatformService portfolioAccountReadPlatformService, - final LoanReadPlatformService loanReadPlatformService) { + final LoanReadPlatformService loanReadPlatformService, + final BulkImportWorkbookService bulkImportWorkbookService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) { this.context = context; this.apiRequestParameterHelper = apiRequestParameterHelper; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; @@ -105,6 +117,8 @@ public class GuarantorsApiResource { this.codeValueReadPlatformService = codeValueReadPlatformService; this.portfolioAccountReadPlatformService = portfolioAccountReadPlatformService; this.loanReadPlatformService = loanReadPlatformService; + this.bulkImportWorkbookService=bulkImportWorkbookService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; } @GET @@ -218,4 +232,22 @@ public class GuarantorsApiResource { final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.apiJsonSerializerService.serialize(settings, guarantorData, ACCOUNT_TRANSFER_API_RESPONSE_DATA_PARAMETERS); } + + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getGuarantorTemplate(@QueryParam("officeId") final Long officeId,@QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.GUARANTORS.toString(), officeId,null,dateFormat); + } + + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postGuarantorTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail,@FormDataParam("locale") final String locale, + @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId =this.bulkImportWorkbookService.importWorkbook(GlobalEntityType.GUARANTORS.toString(), + uploadedInputStream,fileDetail,locale,dateFormat); + return this.apiJsonSerializerService.serialize(importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/data/GuarantorData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/data/GuarantorData.java index f46b52a8f..c6132e758 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/data/GuarantorData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/data/GuarantorData.java @@ -18,9 +18,11 @@ */ package org.apache.fineract.portfolio.loanaccount.guarantor.data; +import java.math.BigDecimal; import java.util.Collection; import java.util.List; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.organisation.staff.data.StaffData; @@ -67,6 +69,68 @@ public class GuarantorData { private final Collection allowedClientRelationshipTypes; private final Collection accountLinkingOptions; + //import fields + private Integer guarantorTypeId; + private Integer clientRelationshipTypeId; + private Integer savingsId; + private BigDecimal amount; + private transient Long accountId; + private transient Integer rowIndex; + private String dateFormat; + private String locale; + + public static GuarantorData importInstance(Integer guarantorTypeId,Integer clientRelationshipTypeId,Long entityId,String firstName, + String lastName,String addressLine1,String addressLine2,String city,LocalDate dob, String zip, + Integer savingsId, BigDecimal amount,Integer rowIndex,Long accountId,String locale,String dateFormat){ + return new GuarantorData(guarantorTypeId,clientRelationshipTypeId,entityId,firstName, lastName, + addressLine1, addressLine2,city,dob,zip,savingsId,amount, rowIndex, accountId,locale,dateFormat); + } + private GuarantorData(Integer guarantorTypeId,Integer clientRelationshipTypeId,Long entityId,String firstname, + String lastname,String addressLine1,String addressLine2,String city,LocalDate dob, String zip, + Integer savingsId, BigDecimal amount,Integer rowIndex,Long accountId,String locale,String dateFormat) { + this.rowIndex=rowIndex; + this.firstname = firstname; + this.lastname = lastname; + this.entityId = entityId; + this.addressLine1 = addressLine1; + this.addressLine2 = addressLine2; + this.city = city; + this.zip = zip; + this.dob = dob; + this.guarantorTypeId = guarantorTypeId; + this.clientRelationshipTypeId = clientRelationshipTypeId; + this.savingsId = savingsId; + this.amount = amount; + this.accountId = accountId; + this.dateFormat=dateFormat; + this.locale= locale; + this.clientRelationshipType = null; + this.guarantorType = null; + this.id = null; + this.loanId = null; + this.externalId = null; + this.officeName = null; + this.joinedDate = null; + this.state = null; + this.country = null; + this.mobileNumber = null; + this.housePhoneNumber = null; + this.comment = null; + this.guarantorFundingDetails = null; + this.status = false; + this.guarantorTypeOptions = null; + this.allowedClientRelationshipTypes = null; + this.accountLinkingOptions = null; + } + + public Long getAccountId() { + return accountId; + } + + public Integer getRowIndex() { + return rowIndex; + } + public static GuarantorData template(final List guarantorTypeOptions, final Collection allowedClientRelationshipTypes, Collection accountLinkingOptions) { final Collection guarantorFundingDetails = null; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java index ab6c31044..3a7f44fda 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java @@ -301,41 +301,48 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { extraCriterias.add(hierarchySearchString); extraCriterias.add(hierarchySearchString); - String sqlQueryCriteria = searchParameters.getSqlSearch(); - if (StringUtils.isNotBlank(sqlQueryCriteria)) { - SQLInjectionValidator.validateSQLInput(sqlQueryCriteria); - sqlQueryCriteria = sqlQueryCriteria.replaceAll("accountNo", "l.account_no"); - this.columnValidator.validateSqlInjection(sqlBuilder.toString(), sqlQueryCriteria); - sqlBuilder.append(" and (").append(sqlQueryCriteria).append(")"); - } + if (searchParameters!=null) { - if (StringUtils.isNotBlank(searchParameters.getExternalId())) { - sqlBuilder.append(" and l.external_id = ?"); - extraCriterias.add(searchParameters.getExternalId()); - arrayPos = arrayPos + 1; - } + String sqlQueryCriteria = searchParameters.getSqlSearch(); + if (StringUtils.isNotBlank(sqlQueryCriteria)) { + SQLInjectionValidator.validateSQLInput(sqlQueryCriteria); + sqlQueryCriteria = sqlQueryCriteria.replaceAll("accountNo", "l.account_no"); + this.columnValidator.validateSqlInjection(sqlBuilder.toString(), sqlQueryCriteria); + sqlBuilder.append(" and (").append(sqlQueryCriteria).append(")"); + } - if (StringUtils.isNotBlank(searchParameters.getAccountNo())) { - sqlBuilder.append(" and l.account_no = ?"); - extraCriterias.add(searchParameters.getAccountNo()); - arrayPos = arrayPos + 1; - } + if (StringUtils.isNotBlank(searchParameters.getExternalId())) { + sqlBuilder.append(" and l.external_id = ?"); + extraCriterias.add(searchParameters.getExternalId()); + arrayPos = arrayPos + 1; + } + if(searchParameters.getOfficeId()!=null){ + sqlBuilder.append("and c.office_id =?"); + extraCriterias.add(searchParameters.getOfficeId()); + arrayPos = arrayPos + 1; + } - if (searchParameters.isOrderByRequested()) { - sqlBuilder.append(" order by ").append(searchParameters.getOrderBy()); + if (StringUtils.isNotBlank(searchParameters.getAccountNo())) { + sqlBuilder.append(" and l.account_no = ?"); + extraCriterias.add(searchParameters.getAccountNo()); + arrayPos = arrayPos + 1; + } - if (searchParameters.isSortOrderProvided()) { - sqlBuilder.append(' ').append(searchParameters.getSortOrder()); + if (searchParameters.isOrderByRequested()) { + sqlBuilder.append(" order by ").append(searchParameters.getOrderBy()); + + if (searchParameters.isSortOrderProvided()) { + sqlBuilder.append(' ').append(searchParameters.getSortOrder()); + } + } + + if (searchParameters.isLimited()) { + sqlBuilder.append(" limit ").append(searchParameters.getLimit()); + if (searchParameters.isOffset()) { + sqlBuilder.append(" offset ").append(searchParameters.getOffset()); + } } } - - if (searchParameters.isLimited()) { - sqlBuilder.append(" limit ").append(searchParameters.getLimit()); - if (searchParameters.isOffset()) { - sqlBuilder.append(" offset ").append(searchParameters.getOffset()); - } - } - final Object[] objectArray = extraCriterias.toArray(); final Object[] finalObjectArray = Arrays.copyOf(objectArray, arrayPos); final String sqlCountRows = "SELECT FOUND_ROWS()"; @@ -343,6 +350,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { this.loaanLoanMapper); } + @Override public LoanAccountData retrieveTemplateWithClientAndProductDetails(final Long clientId, final Long productId) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/data/LoanProductData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/data/LoanProductData.java index d95fcce0c..c84649031 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/data/LoanProductData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/data/LoanProductData.java @@ -1196,4 +1196,28 @@ public class LoanProductData { public BigDecimal getInterestRateDifferential() { return this.interestRateDifferential; } + + public LocalDate getStartDate() { + return startDate; + } + + public LocalDate getCloseDate() { + return closeDate; + } + + public Integer getMinNumberOfRepayments() { + return minNumberOfRepayments; + } + + public Integer getMaxNumberOfRepayments() { + return maxNumberOfRepayments; + } + + public BigDecimal getMinInterestRatePerPeriod() { + return minInterestRatePerPeriod; + } + + public BigDecimal getMaxInterestRatePerPeriod() { + return maxInterestRatePerPeriod; + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/paymenttype/data/PaymentTypeData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/paymenttype/data/PaymentTypeData.java index 03d8f922e..03331f836 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/paymenttype/data/PaymentTypeData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/paymenttype/data/PaymentTypeData.java @@ -50,4 +50,12 @@ public class PaymentTypeData { Long position = null; return new PaymentTypeData(id, name, description, isCashPayment, position); } + + public Long getId() { + return id; + } + + public String getName() { + return name; + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/FixedDepositAccountsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/FixedDepositAccountsApiResource.java index 49cba4fe5..a3a91717e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/FixedDepositAccountsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/FixedDepositAccountsApiResource.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.portfolio.savings.api; +import java.io.InputStream; import java.math.BigDecimal; import java.util.Arrays; import java.util.Collection; @@ -36,12 +37,18 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; import org.apache.commons.lang.StringUtils; 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.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.core.api.ApiParameterHelper; import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; import org.apache.fineract.infrastructure.core.api.JsonQuery; @@ -86,6 +93,9 @@ public class FixedDepositAccountsApiResource { private final FromJsonHelper fromJsonHelper; private final DepositAccountPreMatureCalculationPlatformService accountPreMatureCalculationPlatformService; private final AccountAssociationsReadPlatformService accountAssociationsReadPlatformService; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; + @Autowired public FixedDepositAccountsApiResource(final DepositAccountReadPlatformService depositAccountReadPlatformService, @@ -94,7 +104,9 @@ public class FixedDepositAccountsApiResource { final ApiRequestParameterHelper apiRequestParameterHelper, final SavingsAccountChargeReadPlatformService savingsAccountChargeReadPlatformService, final FromJsonHelper fromJsonHelper, final DepositAccountPreMatureCalculationPlatformService accountPreMatureCalculationPlatformService, - final AccountAssociationsReadPlatformService accountAssociationsReadPlatformService) { + final AccountAssociationsReadPlatformService accountAssociationsReadPlatformService, + final BulkImportWorkbookService bulkImportWorkbookService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) { this.depositAccountReadPlatformService = depositAccountReadPlatformService; this.context = context; this.toApiJsonSerializer = toApiJsonSerializer; @@ -104,6 +116,8 @@ public class FixedDepositAccountsApiResource { this.fromJsonHelper = fromJsonHelper; this.accountPreMatureCalculationPlatformService = accountPreMatureCalculationPlatformService; this.accountAssociationsReadPlatformService = accountAssociationsReadPlatformService; + this.bulkImportWorkbookService=bulkImportWorkbookService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; } @GET @@ -356,4 +370,41 @@ public class FixedDepositAccountsApiResource { final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.toApiJsonSerializer.serialize(settings, account, DepositsApiConstants.FIXED_DEPOSIT_ACCOUNT_RESPONSE_DATA_PARAMETERS); } + + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getFixedDepositTemplate(@QueryParam("officeId")final Long officeId, + @QueryParam("staffId")final Long staffId,@QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate + (GlobalEntityType.FIXED_DEPOSIT_ACCOUNTS.toString(),officeId,staffId,dateFormat); + } + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postFixedDepositTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail,@FormDataParam("locale") final String locale, + @FormDataParam("dateFormat") final String dateFormat){ + Long importDocumentId = bulkImportWorkbookService.importWorkbook(GlobalEntityType.FIXED_DEPOSIT_ACCOUNTS.toString(), + uploadedInputStream,fileDetail,locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } + + @GET + @Path("transaction/downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getFixedDepositTransactionTemplate(@QueryParam("officeId")final Long officeId,@QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.FIXED_DEPOSIT_TRANSACTIONS.toString(), officeId,null,dateFormat); + } + + @POST + @Path("transaction/uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postFixedDepositTransactionTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail,@FormDataParam("locale") final String locale, + @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId = this.bulkImportWorkbookService.importWorkbook(GlobalEntityType.FIXED_DEPOSIT_TRANSACTIONS.toString(), + uploadedInputStream,fileDetail,locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/RecurringDepositAccountsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/RecurringDepositAccountsApiResource.java index bedfadc6e..b1578e44d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/RecurringDepositAccountsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/RecurringDepositAccountsApiResource.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.portfolio.savings.api; +import java.io.InputStream; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -35,12 +36,18 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; import org.apache.commons.lang.StringUtils; 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.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.core.api.ApiParameterHelper; import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; import org.apache.fineract.infrastructure.core.api.JsonQuery; @@ -82,6 +89,9 @@ public class RecurringDepositAccountsApiResource { private final SavingsAccountChargeReadPlatformService savingsAccountChargeReadPlatformService; private final FromJsonHelper fromJsonHelper; private final DepositAccountPreMatureCalculationPlatformService accountPreMatureCalculationPlatformService; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; + @Autowired public RecurringDepositAccountsApiResource(final DepositAccountReadPlatformService depositAccountReadPlatformService, @@ -89,7 +99,9 @@ public class RecurringDepositAccountsApiResource { final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final ApiRequestParameterHelper apiRequestParameterHelper, final SavingsAccountChargeReadPlatformService savingsAccountChargeReadPlatformService, final FromJsonHelper fromJsonHelper, - final DepositAccountPreMatureCalculationPlatformService accountPreMatureCalculationPlatformService) { + final DepositAccountPreMatureCalculationPlatformService accountPreMatureCalculationPlatformService, + final BulkImportWorkbookService bulkImportWorkbookService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) { this.depositAccountReadPlatformService = depositAccountReadPlatformService; this.context = context; this.toApiJsonSerializer = toApiJsonSerializer; @@ -98,6 +110,8 @@ public class RecurringDepositAccountsApiResource { this.savingsAccountChargeReadPlatformService = savingsAccountChargeReadPlatformService; this.fromJsonHelper = fromJsonHelper; this.accountPreMatureCalculationPlatformService = accountPreMatureCalculationPlatformService; + this.bulkImportWorkbookService=bulkImportWorkbookService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; } @GET @@ -341,4 +355,42 @@ public class RecurringDepositAccountsApiResource { return this.toApiJsonSerializer.serialize(settings, account, DepositsApiConstants.RECURRING_DEPOSIT_ACCOUNT_RESPONSE_DATA_PARAMETERS); } + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getRecurringDepositTemplate(@QueryParam("officeId")final Long officeId, + @QueryParam("staffId")final Long staffId,@QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.RECURRING_DEPOSIT_ACCOUNTS.toString(),officeId,staffId,dateFormat); + } + + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postRecurringDepositTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, + @FormDataParam("locale") final String locale, @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId = this.bulkImportWorkbookService.importWorkbook(GlobalEntityType.RECURRING_DEPOSIT_ACCOUNTS.toString(), + uploadedInputStream,fileDetail,locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } + + @GET + @Path("transactions/downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getRecurringDepositTransactionTemplate(@QueryParam("officeId")final Long officeId, + @QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.RECURRING_DEPOSIT_ACCOUNTS_TRANSACTIONS.toString(),officeId, + null,dateFormat); + } + + @POST + @Path("transactions/uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postRecurringDepositTransactionsTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("locale") final String locale, + @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId = this. bulkImportWorkbookService.importWorkbook(GlobalEntityType.RECURRING_DEPOSIT_ACCOUNTS_TRANSACTIONS.toString(), + uploadedInputStream,fileDetail,locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/SavingsAccountsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/SavingsAccountsApiResource.java index 05feb6374..9169c9627 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/SavingsAccountsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/SavingsAccountsApiResource.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.portfolio.savings.api; +import java.io.InputStream; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -35,12 +36,18 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; import org.apache.commons.lang.StringUtils; 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.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.core.api.ApiParameterHelper; import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; @@ -73,19 +80,25 @@ public class SavingsAccountsApiResource { private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final ApiRequestParameterHelper apiRequestParameterHelper; private final SavingsAccountChargeReadPlatformService savingsAccountChargeReadPlatformService; + private final BulkImportWorkbookService bulkImportWorkbookService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; @Autowired public SavingsAccountsApiResource(final SavingsAccountReadPlatformService savingsAccountReadPlatformService, final PlatformSecurityContext context, final DefaultToApiJsonSerializer toApiJsonSerializer, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final ApiRequestParameterHelper apiRequestParameterHelper, - final SavingsAccountChargeReadPlatformService savingsAccountChargeReadPlatformService) { + final SavingsAccountChargeReadPlatformService savingsAccountChargeReadPlatformService, + final BulkImportWorkbookService bulkImportWorkbookService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService) { this.savingsAccountReadPlatformService = savingsAccountReadPlatformService; this.context = context; this.toApiJsonSerializer = toApiJsonSerializer; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.apiRequestParameterHelper = apiRequestParameterHelper; this.savingsAccountChargeReadPlatformService = savingsAccountChargeReadPlatformService; + this.bulkImportWorkbookService=bulkImportWorkbookService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; } @GET @@ -327,4 +340,42 @@ public class SavingsAccountsApiResource { return this.toApiJsonSerializer.serialize(result); } + + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getSavingsTemplate(@QueryParam("officeId")final Long officeId, + @QueryParam("staffId")final Long staffId,@QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.SAVINGS_ACCOUNT.toString(),officeId, staffId,dateFormat); + } + + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postSavingsTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, + @FormDataParam("locale") final String locale, + @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId = this. bulkImportWorkbookService.importWorkbook(GlobalEntityType.SAVINGS_ACCOUNT.toString(), uploadedInputStream, + fileDetail, locale, dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } + + @GET + @Path("transactions/downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getSavingsTransactionTemplate(@QueryParam("officeId")final Long officeId,@QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.SAVINGS_TRANSACTIONS.toString(),officeId, null,dateFormat); + } + + @POST + @Path("transactions/uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postSavingsTransactionTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, + @FormDataParam("locale") final String locale, @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId = this. bulkImportWorkbookService.importWorkbook(GlobalEntityType.SAVINGS_TRANSACTIONS.toString(), uploadedInputStream, + fileDetail,locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/ClosingOfSavingsAccounts.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/ClosingOfSavingsAccounts.java new file mode 100644 index 000000000..0304b76e4 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/ClosingOfSavingsAccounts.java @@ -0,0 +1,102 @@ +/** + * 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.portfolio.savings.data; + + +import org.joda.time.LocalDate; + +import java.util.Locale; + +public class ClosingOfSavingsAccounts { + + private final transient Integer rowIndex; + + private final transient Long accountId; + + private final LocalDate closedOnDate; + + private final Long onAccountClosureId; + + private final Long toSavingsAccountId; + + private final String dateFormat; + + private final String accountType; + + private final String locale; + + private final String note; + + public static ClosingOfSavingsAccounts importInstance(Long accountId, LocalDate closedOnDate, + Long onAccountClosureId,Long toSavingsAccountId, String accountType,Integer rowIndex, + String locale,String dateFormat){ + return new ClosingOfSavingsAccounts(accountId, closedOnDate,onAccountClosureId,toSavingsAccountId, accountType, + rowIndex,locale,dateFormat); + } + + private ClosingOfSavingsAccounts(Long accountId, LocalDate closedOnDate, + Long onAccountClosureId,Long toSavingsAccountId, String accountType,Integer rowIndex, + String locale,String dateFormat ) { + this.accountId = accountId; + this.closedOnDate = closedOnDate; + this.onAccountClosureId = onAccountClosureId; + this.toSavingsAccountId = toSavingsAccountId; + this.accountType=accountType; + this.rowIndex = rowIndex; + this.dateFormat = dateFormat; + this.locale = locale; + this.note = ""; + } + + public Integer getRowIndex() { + return rowIndex; + } + + public Long getAccountId() { + return accountId; + } + + public LocalDate getClosedOnDate() { + return closedOnDate; + } + + public Long getOnAccountClosureId() { + return onAccountClosureId; + } + + public Long getToSavingsAccountId() { + return toSavingsAccountId; + } + + public String getDateFormat() { + return dateFormat; + } + + public String getAccountType() { + return accountType; + } + + public String getLocale() { + return locale; + } + + public String getNote() { + return note; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/DepositAccountData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/DepositAccountData.java index 41880ddd4..817cf073b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/DepositAccountData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/DepositAccountData.java @@ -87,6 +87,59 @@ public class DepositAccountData { protected final DepositAccountInterestRateChartData chartTemplate; + //import fields + private Long productId; + + public DepositAccountData(Long clientId,Long productId,Long fieldOfficerId, + EnumOptionData interestCompoundingPeriodType, EnumOptionData interestPostingPeriodType, + EnumOptionData interestCalculationType,EnumOptionData interestCalculationDaysInYearType,Integer lockinPeriodFrequency, + EnumOptionData lockinPeriodFrequencyType,String externalId,Collection charges) { + this.id = null; + this.accountNo = null; + this.externalId = externalId; + this.groupId = null; + this.groupName = null; + this.clientId = clientId; + this.clientName = null; + this.depositProductId = null; + this.depositProductName = null; + this.fieldOfficerId = fieldOfficerId; + this.fieldOfficerName = null; + this.status = null; + this.timeline = null; + this.currency = null; + this.nominalAnnualInterestRate = null; + this.interestCompoundingPeriodType = interestCompoundingPeriodType; + this.interestPostingPeriodType = interestPostingPeriodType; + this.interestCalculationType = interestCalculationType; + this.interestCalculationDaysInYearType = interestCalculationDaysInYearType; + this.minRequiredOpeningBalance = null; + this.lockinPeriodFrequency = lockinPeriodFrequency; + this.lockinPeriodFrequencyType = lockinPeriodFrequencyType; + this.withdrawalFeeForTransfers = false; + this.depositType = null; + this.minBalanceForInterestCalculation = null; + this.withHoldTax = false; + this.taxGroup = null; + this.summary = null; + this.transactions = null; + this.charges = charges; + this.accountChart = null; + this.productOptions = null; + this.fieldOfficerOptions = null; + this.interestCompoundingPeriodTypeOptions = null; + this.interestPostingPeriodTypeOptions = null; + this.interestCalculationTypeOptions = null; + this.interestCalculationDaysInYearTypeOptions = null; + this.lockinPeriodFrequencyTypeOptions = null; + this.withdrawalFeeTypeOptions = null; + this.chargeOptions = null; + this.withdrawalFee = null; + this.annualFee = null; + this.chartTemplate = null; + this.productId=productId; + } + public static DepositAccountData instance(final Long id, final String accountNo, final String externalId, final Long groupId, final String groupName, final Long clientId, final String clientName, final Long productId, final String productName, final Long fieldOfficerId, final String fieldOfficerName, final SavingsAccountStatusEnumData status, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/DepositProductData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/DepositProductData.java index bf3680e43..bca51268c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/DepositProductData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/DepositProductData.java @@ -411,4 +411,49 @@ public class DepositProductData { public String getName() { return this.name; } -} \ No newline at end of file + + public EnumOptionData getLockinPeriodFrequencyType() { + return lockinPeriodFrequencyType; + } + + public Integer getLockinPeriodFrequency() { + return lockinPeriodFrequency; + } + + public Long getId() { + return id; + } + + public BigDecimal getNominalAnnualInterestRate() { + return nominalAnnualInterestRate; + } + + public EnumOptionData getInterestPostingPeriodType() { + return interestPostingPeriodType; + } + + public EnumOptionData getInterestCalculationType() { + return interestCalculationType; + } + + public EnumOptionData getInterestCalculationDaysInYearType() { + return interestCalculationDaysInYearType; + } + + public BigDecimal getMinBalanceForInterestCalculation() { + return minBalanceForInterestCalculation; + } + + public String getShortName() { + return shortName; + } + + public CurrencyData getCurrency() { + return currency; + } + + public EnumOptionData getInterestCompoundingPeriodType() { + return interestCompoundingPeriodType; + } +} + diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/FixedDepositAccountData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/FixedDepositAccountData.java index 60ee6a2a9..251e6b122 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/FixedDepositAccountData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/FixedDepositAccountData.java @@ -23,6 +23,7 @@ import java.util.Collection; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.organisation.monetary.data.CurrencyData; import org.apache.fineract.organisation.staff.data.StaffData; @@ -69,6 +70,69 @@ public class FixedDepositAccountData extends DepositAccountData { private Collection onAccountClosureOptions; private Collection paymentTypeOptions; + //import fields + private transient Integer rowIndex; + private String dateFormat; + private String locale; + private LocalDate submittedOnDate; + private Long depositPeriodFrequencyId; + + public static FixedDepositAccountData importInstance(Long clientId,Long productId,Long fieldOfficerId,LocalDate submittedOnDate, + EnumOptionData interestCompoundingPeriodTypeEnum,EnumOptionData interestPostingPeriodTypeEnum, + EnumOptionData interestCalculationTypeEnum,EnumOptionData interestCalculationDaysInYearTypeEnum, + Integer lockinPeriodFrequency,EnumOptionData lockinPeriodFrequencyTypeEnum,BigDecimal depositAmount, + Integer depositPeriod,Long depositPeriodFrequencyId,String externalId, + Collection charges,Integer rowIndex,String locale,String dateFormat){ + + return new FixedDepositAccountData(clientId, productId, fieldOfficerId, submittedOnDate, + interestCompoundingPeriodTypeEnum, interestPostingPeriodTypeEnum, interestCalculationTypeEnum, + interestCalculationDaysInYearTypeEnum, lockinPeriodFrequency, lockinPeriodFrequencyTypeEnum, + depositAmount, depositPeriod, depositPeriodFrequencyId, externalId, charges,rowIndex,locale,dateFormat); + } + + private FixedDepositAccountData(Long clientId,Long productId,Long fieldofficerId,LocalDate submittedOnDate, + EnumOptionData interestCompoundingPeriodType,EnumOptionData interestPostingPeriodType, + EnumOptionData interestCalculationType,EnumOptionData interestCalculationDaysInYearType, + Integer lockinPeriodFrequency,EnumOptionData lockinPeriodFrequencyType,BigDecimal depositAmount, + Integer depositPeriod,Long depositPeriodFrequencyId,String externalId, + Collection charges,Integer rowIndex,String locale,String dateFormat) { + super(clientId, productId, fieldofficerId, interestCompoundingPeriodType, interestPostingPeriodType, + interestCalculationType, interestCalculationDaysInYearType, lockinPeriodFrequency, + lockinPeriodFrequencyType, externalId, charges); + this.preClosurePenalApplicable = false; + this.preClosurePenalInterest = null; + this.preClosurePenalInterestOnType = null; + this.minDepositTerm = null; + this.maxDepositTerm = null; + this.minDepositTermType = null; + this.maxDepositTermType = null; + this.inMultiplesOfDepositTerm = null; + this.inMultiplesOfDepositTermType = null; + this.depositAmount = depositAmount; + this.maturityAmount = null; + this.maturityDate = null; + this.depositPeriod = depositPeriod; + this.depositPeriodFrequency = null; + this.activationCharge = null; + this.onAccountClosure = null; + this.linkedAccount = null; + this.transferInterestToSavings = null; + this.preClosurePenalInterestOnTypeOptions = null; + this.periodFrequencyTypeOptions = null; + this.savingsAccounts = null; + this.onAccountClosureOptions = null; + this.paymentTypeOptions = null; + this.rowIndex = rowIndex; + this.dateFormat= dateFormat; + this.locale= locale; + this.submittedOnDate = submittedOnDate; + this.depositPeriodFrequencyId = depositPeriodFrequencyId; + } + + public Integer getRowIndex() { + return rowIndex; + } + public static FixedDepositAccountData instance(final DepositAccountData depositAccountData, final boolean preClosurePenalApplicable, final BigDecimal preClosurePenalInterest, final EnumOptionData preClosurePenalInterestOnType, final Integer minDepositTerm, final Integer maxDepositTerm, final EnumOptionData minDepositTermType, final EnumOptionData maxDepositTermType, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/FixedDepositProductData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/FixedDepositProductData.java index f2b2d334b..31a67cade 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/FixedDepositProductData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/FixedDepositProductData.java @@ -404,4 +404,52 @@ public class FixedDepositProductData extends DepositProductData { this.periodFrequencyTypeOptions = periodFrequencyTypeOptions; } + public Integer getMinDepositTerm() { + return minDepositTerm; + } + + public EnumOptionData getMinDepositTermType() { + return minDepositTermType; + } + + public EnumOptionData getMaxDepositTermType() { + return maxDepositTermType; + } + + public Integer getMaxDepositTerm() { + return maxDepositTerm; + } + + public Integer getInMultiplesOfDepositTerm() { + return inMultiplesOfDepositTerm; + } + + public EnumOptionData getInMultiplesOfDepositTermType() { + return inMultiplesOfDepositTermType; + } + + public BigDecimal getMinDepositAmount() { + return minDepositAmount; + } + + public BigDecimal getDepositAmount() { + return depositAmount; + } + + public BigDecimal getMaxDepositAmount() { + return maxDepositAmount; + } + + public EnumOptionData getPreClosurePenalInterestOnType() { + return preClosurePenalInterestOnType; + } + + public BigDecimal getPreClosurePenalInterest() { + return preClosurePenalInterest; + } + + public boolean isPreClosurePenalApplicable() { + return preClosurePenalApplicable; + } + } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/RecurringDepositAccountData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/RecurringDepositAccountData.java index 6f61ef2e9..1b5dcf0c7 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/RecurringDepositAccountData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/RecurringDepositAccountData.java @@ -23,6 +23,7 @@ import java.util.Collection; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.organisation.monetary.data.CurrencyData; import org.apache.fineract.organisation.staff.data.StaffData; @@ -75,6 +76,82 @@ public class RecurringDepositAccountData extends DepositAccountData { private final Collection onAccountClosureOptions; private final Collection paymentTypeOptions; + //import fields + private transient Integer rowIndex; + private String dateFormat; + private String locale; + private LocalDate submittedOnDate; + private Long depositPeriodFrequencyId; + + public static RecurringDepositAccountData importInstance(Long clientId,Long productId,Long fieldOfficerId, + LocalDate submittedOnDate, + EnumOptionData interestCompoundingPeriodTypeEnum,EnumOptionData interestPostingPeriodTypeEnum, + EnumOptionData interestCalculationTypeEnum,EnumOptionData interestCalculationDaysInYearTypeEnum, + Integer lockinPeriodFrequency,EnumOptionData lockinPeriodFrequencyTypeEnum,BigDecimal depositAmount, + Integer depositPeriod,Long depositPeriodFrequencyId,LocalDate expectedFirstDepositOnDate, + Integer recurringFrequency,EnumOptionData recurringFrequencyTypeEnum,boolean isCalendarInherited, + boolean isMandatoryDeposit,boolean allowWithdrawal,boolean adjustAdvanceTowardsFuturePayments, + String externalId,Collection charges,Integer rowIndex,String locale, String dateFormat){ + + return new RecurringDepositAccountData(clientId, productId, fieldOfficerId, submittedOnDate, + interestCompoundingPeriodTypeEnum,interestPostingPeriodTypeEnum,interestCalculationTypeEnum, + interestCalculationDaysInYearTypeEnum, lockinPeriodFrequency, lockinPeriodFrequencyTypeEnum, + depositAmount, depositPeriod, depositPeriodFrequencyId, expectedFirstDepositOnDate, + recurringFrequency, recurringFrequencyTypeEnum, isCalendarInherited, isMandatoryDeposit, + allowWithdrawal, adjustAdvanceTowardsFuturePayments, externalId,charges, rowIndex,locale,dateFormat); + } + private RecurringDepositAccountData(Long clientId,Long productId,Long fieldofficerId,LocalDate submittedOnDate, + EnumOptionData interestCompoundingPeriodType,EnumOptionData interestPostingPeriodType, + EnumOptionData interestCalculationType,EnumOptionData interestCalculationDaysInYearType, + Integer lockinPeriodFrequency,EnumOptionData lockinPeriodFrequencyType,BigDecimal depositAmount, + Integer depositPeriod,Long depositPeriodFrequencyId,LocalDate expectedFirstDepositOnDate, + Integer recurringFrequency,EnumOptionData recurringFrequencyType,boolean isCalendarInherited, + boolean isMandatoryDeposit,boolean allowWithdrawal,boolean adjustAdvanceTowardsFuturePayments, + String externalId,Collection charges,Integer rowIndex,String locale, String dateFormat) { + super(clientId,productId,fieldofficerId,interestCompoundingPeriodType,interestPostingPeriodType,interestCalculationType, + interestCalculationDaysInYearType,lockinPeriodFrequency,lockinPeriodFrequencyType, externalId,charges); + + this.preClosurePenalApplicable = false; + this.preClosurePenalInterest = null; + this.preClosurePenalInterestOnType = null; + this.minDepositTerm = null; + this.maxDepositTerm = null; + this.minDepositTermType = null; + this.maxDepositTermType = null; + this.inMultiplesOfDepositTerm = null; + this.inMultiplesOfDepositTermType = null; + this.depositAmount = null; + this.maturityAmount = null; + this.maturityDate = null; + this.depositPeriod = depositPeriod; + this.depositPeriodFrequency = null; + this.mandatoryRecommendedDepositAmount = depositAmount; + this.totalOverdueAmount = null; + this.noOfOverdueInstallments = null; + this.isMandatoryDeposit = isMandatoryDeposit; + this.allowWithdrawal = allowWithdrawal; + this.adjustAdvanceTowardsFuturePayments = adjustAdvanceTowardsFuturePayments; + this.expectedFirstDepositOnDate = expectedFirstDepositOnDate; + this.isCalendarInherited = isCalendarInherited; + this.recurringFrequency = recurringFrequency; + this.recurringFrequencyType = recurringFrequencyType; + this.onAccountClosure = null; + this.preClosurePenalInterestOnTypeOptions = null; + this.periodFrequencyTypeOptions = null; + this.savingsAccounts = null; + this.onAccountClosureOptions = null; + this.paymentTypeOptions = null; + this.rowIndex = rowIndex; + this.dateFormat= dateFormat; + this.locale=locale; + this.submittedOnDate=submittedOnDate; + this.depositPeriodFrequencyId=depositPeriodFrequencyId; + } + + public Integer getRowIndex() { + return rowIndex; + } + public static RecurringDepositAccountData instance(final DepositAccountData depositAccountData, final boolean preClosurePenalApplicable, final BigDecimal preClosurePenalInterest, final EnumOptionData preClosurePenalInterestOnType, final Integer minDepositTerm, final Integer maxDepositTerm, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/RecurringDepositProductData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/RecurringDepositProductData.java index 184a7e7d3..e3b1b13a7 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/RecurringDepositProductData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/RecurringDepositProductData.java @@ -422,4 +422,63 @@ public class RecurringDepositProductData extends DepositProductData { this.periodFrequencyTypeOptions = periodFrequencyTypeOptions; } + public EnumOptionData getMinDepositTermType() { + return minDepositTermType; + } + + public boolean isPreClosurePenalApplicable() { + return preClosurePenalApplicable; + } + + public BigDecimal getPreClosurePenalInterest() { + return preClosurePenalInterest; + } + + public EnumOptionData getPreClosurePenalInterestOnType() { + return preClosurePenalInterestOnType; + } + + public Integer getMinDepositTerm() { + return minDepositTerm; + } + + public Integer getMaxDepositTerm() { + return maxDepositTerm; + } + + public EnumOptionData getMaxDepositTermType() { + return maxDepositTermType; + } + + public BigDecimal getMinDepositAmount() { + return minDepositAmount; + } + + public BigDecimal getDepositAmount() { + return depositAmount; + } + + public BigDecimal getMaxDepositAmount() { + return maxDepositAmount; + } + + public Integer getInMultiplesOfDepositTerm() { + return inMultiplesOfDepositTerm; + } + + public EnumOptionData getInMultiplesOfDepositTermType() { + return inMultiplesOfDepositTermType; + } + + public boolean isMandatoryDeposit() { + return isMandatoryDeposit; + } + + public boolean isAllowWithdrawal() { + return allowWithdrawal; + } + + public boolean isAdjustAdvanceTowardsFuturePayments() { + return adjustAdvanceTowardsFuturePayments; + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountApplicationTimelineData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountApplicationTimelineData.java index d24973bf9..e3f8e68a6 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountApplicationTimelineData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountApplicationTimelineData.java @@ -119,4 +119,8 @@ public class SavingsAccountApplicationTimelineData { this.closedByFirstname = closedByFirstname; this.closedByLastname = closedByLastname; } + + public LocalDate getActivatedOnDate() { + return activatedOnDate; + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountChargeData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountChargeData.java index 81245c000..ba158d01f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountChargeData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountChargeData.java @@ -78,6 +78,31 @@ public class SavingsAccountChargeData { private final Collection chargeOptions; + public SavingsAccountChargeData(Long chargeId, BigDecimal amount,LocalDate dueDate) { + this.chargeId = chargeId; + this.amount = amount; + this.dueDate = dueDate; + this.id=null; + this.accountId = null; + this.name = null; + this.chargeTimeType = null; + this.feeOnMonthDay = null; + this.feeInterval = null; + this.chargeCalculationType = null; + this.percentage = null; + this.amountPercentageAppliedTo = null; + this.currency = null; + this.amountPaid = null; + this.amountWaived = null; + this.amountWrittenOff = null; + this.amountOutstanding = null; + this.amountOrPercentage = null; + this.penalty = false; + this.isActive = null; + this.inactivationDate = null; + this.chargeOptions = null; + } + public static SavingsAccountChargeData template(final Collection chargeOptions) { final Long id = null; final Long chargeId = null; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountData.java index 32a0630fe..64ff43ae1 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountData.java @@ -19,12 +19,11 @@ package org.apache.fineract.portfolio.savings.data; import java.math.BigDecimal; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; +import java.util.*; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.infrastructure.dataqueries.data.DatatableData; import org.apache.fineract.organisation.monetary.data.CurrencyData; @@ -105,6 +104,222 @@ public class SavingsAccountData { private List datatables = null; + //import field + private Long productId; + private String locale; + private String dateFormat; + private transient Integer rowIndex; + private LocalDate submittedOnDate; + + public static SavingsAccountData importInstanceIndividual(Long clientId, Long productId, Long fieldOfficerId,LocalDate submittedOnDate, + BigDecimal nominalAnnualInterestRate, EnumOptionData interestCompoundingPeriodTypeEnum, + EnumOptionData interestPostingPeriodTypeEnum,EnumOptionData interestCalculationTypeEnum, + EnumOptionData interestCalculationDaysInYearTypeEnum,BigDecimal minRequiredOpeningBalance, + Integer lockinPeriodFrequency,EnumOptionData lockinPeriodFrequencyTypeEnum, boolean applyWithdrawalFeeForTransfers, + Integer rowIndex,String externalId,Collection charges,boolean allowOverdraft, + BigDecimal overdraftLimit,String locale, String dateFormat){ + return new SavingsAccountData(clientId, productId, fieldOfficerId, submittedOnDate, nominalAnnualInterestRate, + interestCompoundingPeriodTypeEnum, interestPostingPeriodTypeEnum, interestCalculationTypeEnum, + interestCalculationDaysInYearTypeEnum, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyTypeEnum, + applyWithdrawalFeeForTransfers, rowIndex, externalId, charges, allowOverdraft, overdraftLimit,locale,dateFormat); + + } + + private SavingsAccountData(Long clientId, Long productId, Long fieldOfficerId,LocalDate submittedOnDate, + BigDecimal nominalAnnualInterestRate, EnumOptionData interestCompoundingPeriodType, + EnumOptionData interestPostingPeriodType,EnumOptionData interestCalculationType, + EnumOptionData interestCalculationDaysInYearType,BigDecimal minRequiredOpeningBalance, + Integer lockinPeriodFrequency,EnumOptionData lockinPeriodFrequencyType, boolean withdrawalFeeForTransfers, + Integer rowIndex,String externalId,Collection charges,boolean allowOverdraft, + BigDecimal overdraftLimit,String locale, String dateFormat) { + this.id = null; + this.accountNo = null; + this.depositType = null; + this.externalId = externalId; + this.groupId = null; + this.groupName = null; + this.clientId = clientId; + this.clientName = null; + this.savingsProductId = null; + this.savingsProductName = null; + this.fieldOfficerId = fieldOfficerId; + this.fieldOfficerName = null; + this.status = null; + this.subStatus = null; + this.timeline = null; + this.currency = null; + this.nominalAnnualInterestRate = nominalAnnualInterestRate; + this.interestCompoundingPeriodType = interestCompoundingPeriodType; + this.interestPostingPeriodType = interestPostingPeriodType; + this.interestCalculationType = interestCalculationType; + this.interestCalculationDaysInYearType = interestCalculationDaysInYearType; + this.minRequiredOpeningBalance = minRequiredOpeningBalance; + this.lockinPeriodFrequency = lockinPeriodFrequency; + this.lockinPeriodFrequencyType = lockinPeriodFrequencyType; + this.withdrawalFeeForTransfers = withdrawalFeeForTransfers; + this.allowOverdraft = allowOverdraft; + this.overdraftLimit = overdraftLimit; + this.minRequiredBalance = null; + this.enforceMinRequiredBalance = false; + this.minBalanceForInterestCalculation = null; + this.onHoldFunds = null; + this.withHoldTax = false; + this.taxGroup = null; + this.lastActiveTransactionDate = null; + this.isDormancyTrackingActive = false; + this.daysToInactive = null; + this.daysToDormancy = null; + this.daysToEscheat = null; + this.summary = null; + this.transactions = null; + this.charges = charges; + this.productOptions = null; + this.fieldOfficerOptions = null; + this.interestCompoundingPeriodTypeOptions = null; + this.interestPostingPeriodTypeOptions = null; + this.interestCalculationTypeOptions = null; + this.interestCalculationDaysInYearTypeOptions = null; + this.lockinPeriodFrequencyTypeOptions = null; + this.withdrawalFeeTypeOptions = null; + this.chargeOptions = null; + this.withdrawalFee = null; + this.annualFee = null; + this.nominalAnnualInterestRateOverdraft = null; + this.minOverdraftForInterestCalculation = null; + this.datatables = null; + this.productId = productId; + this.dateFormat=dateFormat; + this.locale= locale; + this.rowIndex = rowIndex; + this.submittedOnDate=submittedOnDate; + this.savingsAmountOnHold=null; + } + + public static final Comparator ClientNameComparator = new Comparator() { + + @Override + public int compare(SavingsAccountData savings1, SavingsAccountData savings2) { + String clientOfSavings1 = savings1.getClientName().toUpperCase(Locale.ENGLISH); + String clientOfSavings2 = savings2.getClientName().toUpperCase(Locale.ENGLISH); + return clientOfSavings1.compareTo(clientOfSavings2); + } + }; + + public String getClientName() { + return clientName; + } + + public String getAccountNo() { + return accountNo; + } + + public Long getClientId() { + return clientId; + } + + public String getSavingsProductName() { + return savingsProductName; + } + + public BigDecimal getMinRequiredOpeningBalance() { + return minRequiredOpeningBalance; + } + + public SavingsAccountApplicationTimelineData getTimeline() { + return timeline; + } + + public static SavingsAccountData importInstanceGroup(Long groupId, Long productId, Long fieldOfficerId, + LocalDate submittedOnDate, + BigDecimal nominalAnnualInterestRate, EnumOptionData interestCompoundingPeriodTypeEnum, + EnumOptionData interestPostingPeriodTypeEnum,EnumOptionData interestCalculationTypeEnum, + EnumOptionData interestCalculationDaysInYearTypeEnum,BigDecimal minRequiredOpeningBalance, + Integer lockinPeriodFrequency,EnumOptionData lockinPeriodFrequencyTypeEnum, + boolean applyWithdrawalFeeForTransfers, + Integer rowIndex,String externalId,Collection charges, + boolean allowOverdraft, + BigDecimal overdraftLimit,String locale, String dateFormat){ + + return new SavingsAccountData(groupId, productId, fieldOfficerId, submittedOnDate, nominalAnnualInterestRate, + interestCompoundingPeriodTypeEnum, interestPostingPeriodTypeEnum, interestCalculationTypeEnum, + interestCalculationDaysInYearTypeEnum, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyTypeEnum, + applyWithdrawalFeeForTransfers, rowIndex, externalId, charges, allowOverdraft, overdraftLimit,null,locale,dateFormat); + + } + private SavingsAccountData(Long groupId, Long productId, Long fieldOfficerId,LocalDate submittedOnDate, + BigDecimal nominalAnnualInterestRate, EnumOptionData interestCompoundingPeriodType, + EnumOptionData interestPostingPeriodType,EnumOptionData interestCalculationType, + EnumOptionData interestCalculationDaysInYearType,BigDecimal minRequiredOpeningBalance, + Integer lockinPeriodFrequency,EnumOptionData lockinPeriodFrequencyType, boolean withdrawalFeeForTransfers, + Integer rowIndex,String externalId,Collection charges,boolean allowOverdraft, + BigDecimal overdraftLimit,Long id,String locale, String dateFormat) { + this.id = id; + this.accountNo = null; + this.depositType = null; + this.externalId = externalId; + this.groupId = groupId; + this.groupName = null; + this.clientId = null; + this.clientName = null; + this.savingsProductId = null; + this.savingsProductName = null; + this.fieldOfficerId = fieldOfficerId; + this.fieldOfficerName = null; + this.status = null; + this.subStatus = null; + this.timeline = null; + this.currency = null; + this.nominalAnnualInterestRate = nominalAnnualInterestRate; + this.interestCompoundingPeriodType = interestCompoundingPeriodType; + this.interestPostingPeriodType = interestPostingPeriodType; + this.interestCalculationType = interestCalculationType; + this.interestCalculationDaysInYearType = interestCalculationDaysInYearType; + this.minRequiredOpeningBalance = minRequiredOpeningBalance; + this.lockinPeriodFrequency = lockinPeriodFrequency; + this.lockinPeriodFrequencyType = lockinPeriodFrequencyType; + this.withdrawalFeeForTransfers = withdrawalFeeForTransfers; + this.allowOverdraft = allowOverdraft; + this.overdraftLimit = overdraftLimit; + this.minRequiredBalance = null; + this.enforceMinRequiredBalance = false; + this.minBalanceForInterestCalculation = null; + this.onHoldFunds = null; + this.withHoldTax = false; + this.taxGroup = null; + this.lastActiveTransactionDate = null; + this.isDormancyTrackingActive = false; + this.daysToInactive = null; + this.daysToDormancy = null; + this.daysToEscheat = null; + this.summary = null; + this.transactions = null; + this.charges = charges; + this.productOptions = null; + this.fieldOfficerOptions = null; + this.interestCompoundingPeriodTypeOptions = null; + this.interestPostingPeriodTypeOptions = null; + this.interestCalculationTypeOptions = null; + this.interestCalculationDaysInYearTypeOptions = null; + this.lockinPeriodFrequencyTypeOptions = null; + this.withdrawalFeeTypeOptions = null; + this.chargeOptions = null; + this.withdrawalFee = null; + this.annualFee = null; + this.nominalAnnualInterestRateOverdraft = null; + this.minOverdraftForInterestCalculation = null; + this.datatables = null; + this.productId = productId; + this.dateFormat= dateFormat; + this.locale= locale; + this.rowIndex = rowIndex; + this.submittedOnDate=submittedOnDate; + this.savingsAmountOnHold=null; + } + + public Integer getRowIndex() { + return rowIndex; + } + public static SavingsAccountData instance(final Long id, final String accountNo, final EnumOptionData depositType, final String externalId, final Long groupId, final String groupName, final Long clientId, final String clientName, final Long productId, final String productName, final Long fieldOfficerId, final String fieldOfficerName, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionData.java index bf066ed83..b3073ddc9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionData.java @@ -21,6 +21,7 @@ package org.apache.fineract.portfolio.savings.data; import java.math.BigDecimal; import java.util.Collection; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.organisation.monetary.data.CurrencyData; @@ -55,6 +56,73 @@ public class SavingsAccountTransactionData { // templates final Collection paymentTypeOptions; + //import fields + private transient Integer rowIndex; + private transient Long savingsAccountId; + private String dateFormat; + private String locale; + private LocalDate transactionDate; + private BigDecimal transactionAmount; + private Long paymentTypeId; + private String accountNumber; + private String checkNumber; + private String routingCode; + private String receiptNumber; + private String bankNumber; + + public static SavingsAccountTransactionData importInstance(BigDecimal transactionAmount,LocalDate transactionDate, + Long paymentTypeId,String accountNumber, String checkNumber, String routingCode, + String receiptNumber, String bankNumber,Long savingsAccountId, + SavingsAccountTransactionEnumData transactionType, Integer rowIndex,String locale,String dateFormat){ + return new SavingsAccountTransactionData(transactionAmount, transactionDate, paymentTypeId, accountNumber, + checkNumber, routingCode, receiptNumber, bankNumber, savingsAccountId, transactionType, rowIndex,locale,dateFormat); + } + + private SavingsAccountTransactionData(BigDecimal transactionAmount,LocalDate transactionDate, + Long paymentTypeId,String accountNumber, String checkNumber, String routingCode, + String receiptNumber, String bankNumber,Long savingsAccountId, + SavingsAccountTransactionEnumData transactionType, Integer rowIndex,String locale,String dateFormat){ + this.id = null; + this.transactionType = transactionType; + this.accountId = null; + this.accountNo = null; + this.date = null; + this.currency = null; + this.paymentDetailData = null; + this.amount = null; + this.outstandingChargeAmount = null; + this.runningBalance = null; + this.reversed = false; + this.transfer = null; + this.submittedOnDate = null; + this.interestedPostedAsOn = false; + this.rowIndex = rowIndex; + this.savingsAccountId=savingsAccountId; + this.dateFormat= dateFormat; + this.locale= locale; + this.transactionDate = transactionDate; + this.transactionAmount = transactionAmount; + this.paymentTypeId = paymentTypeId; + this.accountNumber = accountNumber; + this.checkNumber = checkNumber; + this.routingCode = routingCode; + this.receiptNumber = receiptNumber; + this.bankNumber = bankNumber; + this.paymentTypeOptions = null; + } + + public Integer getRowIndex() { + return rowIndex; + } + + public Long getSavingsAccountId() { + return savingsAccountId; + } + + public SavingsAccountTransactionEnumData getTransactionType() { + return transactionType; + } + public static SavingsAccountTransactionData create(final Long id, final SavingsAccountTransactionEnumData transactionType, final PaymentDetailData paymentDetailData, final Long savingsId, final String savingsAccountNo, final LocalDate date, final CurrencyData currency, final BigDecimal amount, final BigDecimal outstandingChargeAmount,final BigDecimal runningBalance, final boolean reversed, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsActivation.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsActivation.java new file mode 100644 index 000000000..d9d3f402d --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsActivation.java @@ -0,0 +1,60 @@ +/** + * 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.portfolio.savings.data; + +import org.joda.time.LocalDate; + +import java.util.Locale; + +public class SavingsActivation { + + private final transient Integer rowIndex; + + private final LocalDate activatedOnDate; + + private final String dateFormat; + + private final String locale; + + public static SavingsActivation importInstance(LocalDate activatedOnDate, Integer rowIndex,String locale,String dateFormat){ + return new SavingsActivation(activatedOnDate,rowIndex,locale,dateFormat); + } + private SavingsActivation(LocalDate activatedOnDate, Integer rowIndex,String locale,String dateFormat ) { + this.activatedOnDate = activatedOnDate; + this.rowIndex = rowIndex; + this.dateFormat = dateFormat; + this.locale = locale; + } + + public LocalDate getActivatedOnDate() { + return activatedOnDate; + } + + public String getLocale() { + return locale; + } + + public String getDateFormat() { + return dateFormat; + } + + public Integer getRowIndex() { + return rowIndex; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsApproval.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsApproval.java new file mode 100644 index 000000000..b24232045 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsApproval.java @@ -0,0 +1,67 @@ +/** + * 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.portfolio.savings.data; + +import org.joda.time.LocalDate; + +import java.util.Locale; + +public class SavingsApproval { + private final transient Integer rowIndex; + + private final LocalDate approvedOnDate; + + private final String dateFormat; + + private final String locale; + + private final String note; + + public static SavingsApproval importInstance(LocalDate approvedOnDate, Integer rowIndex,String locale,String dateFormat){ + return new SavingsApproval(approvedOnDate, rowIndex,locale,dateFormat); + } + + private SavingsApproval(LocalDate approvedOnDate, Integer rowIndex,String locale,String dateFormat ) { + this.approvedOnDate = approvedOnDate; + this.rowIndex = rowIndex; + this.dateFormat = dateFormat; + this.locale = locale; + this.note = ""; + } + + public LocalDate getApprovedOnDate() { + return approvedOnDate; + } + + public String getLocale() { + return locale; + } + + public String getDateFormat() { + return dateFormat; + } + + public Integer getRowIndex() { + return rowIndex; + } + + public String getNote() { + return note; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsProductData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsProductData.java index 277126ecc..99538b40b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsProductData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsProductData.java @@ -445,6 +445,60 @@ public class SavingsProductData { public void setDepositAccountType(String depositAccountType) { this.depositAccountType = depositAccountType; } - - + + public BigDecimal getNominalAnnualInterestRate() { + return nominalAnnualInterestRate; + } + + public CurrencyData getCurrency() { + return currency; + } + + public Integer getLockinPeriodFrequency() { + return lockinPeriodFrequency; + } + + public EnumOptionData getLockinPeriodFrequencyType() { + return lockinPeriodFrequencyType; + } + + public BigDecimal getOverdraftLimit() { + return overdraftLimit; + } + + public BigDecimal getMinRequiredOpeningBalance() { + return minRequiredOpeningBalance; + } + + public EnumOptionData getInterestCompoundingPeriodType() { + return interestCompoundingPeriodType; + } + + public EnumOptionData getInterestPostingPeriodType() { + return interestPostingPeriodType; + } + + public EnumOptionData getInterestCalculationType() { + return interestCalculationType; + } + + public EnumOptionData getInterestCalculationDaysInYearType() { + return interestCalculationDaysInYearType; + } + + public boolean isAllowOverdraft() { + return allowOverdraft; + } + + public BigDecimal getMinRequiredBalance() { + return minRequiredBalance; + } + + public Long getId() { + return id; + } + + public boolean isWithdrawalFeeForTransfers() { + return withdrawalFeeForTransfers; + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositTermDetail.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositTermDetail.java index ff2755471..954b6f7ff 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositTermDetail.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositTermDetail.java @@ -183,6 +183,7 @@ public class DepositTermDetail { final Integer inMultiplesOfInDays = this.convertToSafeDays(this.inMultiplesOfDepositTerm(), SavingsPeriodFrequencyType.fromInt(this.inMultiplesOfDepositTermType())); final Integer minDepositInDays = this.convertToSafeDays(minDepositTerm, SavingsPeriodFrequencyType.fromInt(minDepositTermType)); + if(inMultiplesOfInDays!=0) isValidInMultiplesOfPeriod = ((depositPeriodInDays - minDepositInDays) % inMultiplesOfInDays == 0); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountReadPlatformServiceImpl.java index a9704eba0..b4aeae43c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountReadPlatformServiceImpl.java @@ -160,7 +160,7 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead final Object[] queryParameters = new Object[] { clientId, depositAccountType.getValue(), currencyCode }; return this.jdbcTemplate.query(sqlBuilder.toString(), this.savingAccountMapper, queryParameters); } - + @Override public Page retrieveAll(final SearchParameters searchParameters) { @@ -178,35 +178,39 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead final Object[] objectArray = new Object[2]; objectArray[0] = hierarchySearchString; int arrayPos = 1; + if(searchParameters!=null) { + String sqlQueryCriteria = searchParameters.getSqlSearch(); + if (StringUtils.isNotBlank(sqlQueryCriteria)) { + sqlQueryCriteria = sqlQueryCriteria.replaceAll("accountNo", "sa.account_no"); + this.columnValidator.validateSqlInjection(sqlBuilder.toString(), sqlQueryCriteria); + sqlBuilder.append(" and (").append(sqlQueryCriteria).append(")"); + } - String sqlQueryCriteria = searchParameters.getSqlSearch(); - if (StringUtils.isNotBlank(sqlQueryCriteria)) { - sqlQueryCriteria = sqlQueryCriteria.replaceAll("accountNo", "sa.account_no"); - this.columnValidator.validateSqlInjection(sqlBuilder.toString(), sqlQueryCriteria); - sqlBuilder.append(" and (").append(sqlQueryCriteria).append(")"); - } + if (StringUtils.isNotBlank(searchParameters.getExternalId())) { + sqlBuilder.append(" and sa.external_id = ?"); + objectArray[arrayPos] = searchParameters.getExternalId(); + arrayPos = arrayPos + 1; + } + if(searchParameters.getOfficeId()!=null){ + sqlBuilder.append("and c.office_id =?"); + objectArray[arrayPos]=searchParameters.getOfficeId(); + arrayPos = arrayPos + 1; + } + if (searchParameters.isOrderByRequested()) { + sqlBuilder.append(" order by ").append(searchParameters.getOrderBy()); - if (StringUtils.isNotBlank(searchParameters.getExternalId())) { - sqlBuilder.append(" and sa.external_id = ?"); - objectArray[arrayPos] = searchParameters.getExternalId(); - arrayPos = arrayPos + 1; - } + if (searchParameters.isSortOrderProvided()) { + sqlBuilder.append(' ').append(searchParameters.getSortOrder()); + } + } - if (searchParameters.isOrderByRequested()) { - sqlBuilder.append(" order by ").append(searchParameters.getOrderBy()); - - if (searchParameters.isSortOrderProvided()) { - sqlBuilder.append(' ').append(searchParameters.getSortOrder()); + if (searchParameters.isLimited()) { + sqlBuilder.append(" limit ").append(searchParameters.getLimit()); + if (searchParameters.isOffset()) { + sqlBuilder.append(" offset ").append(searchParameters.getOffset()); + } } } - - if (searchParameters.isLimited()) { - sqlBuilder.append(" limit ").append(searchParameters.getLimit()); - if (searchParameters.isOffset()) { - sqlBuilder.append(" offset ").append(searchParameters.getOffset()); - } - } - final Object[] finalObjectArray = Arrays.copyOf(objectArray, arrayPos); final String sqlCountRows = "SELECT FOUND_ROWS()"; return this.paginationHelper.fetchPage(this.jdbcTemplate, sqlCountRows, sqlBuilder.toString(), finalObjectArray, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/data/ShareAccountChargeData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/data/ShareAccountChargeData.java index 41eaf7420..f1da9f450 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/data/ShareAccountChargeData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/data/ShareAccountChargeData.java @@ -65,6 +65,27 @@ public class ShareAccountChargeData { private final Collection chargeOptions; + public ShareAccountChargeData(Long chargeId, BigDecimal amount) { + this.chargeId = chargeId; + this.amount = amount; + this.id = null; + this.accountId = null; + this.name = null; + this.chargeTimeType = null; + this.chargeCalculationType = null; + this.percentage = null; + this.amountPercentageAppliedTo = null; + this.currency = null; + this.amountPaid = null; + this.amountWaived = null; + this.amountWrittenOff = null; + this.amountOutstanding = null; + this.amountOrPercentage = null; + this.isActive = null; + this.chargeOptions = null; + } + + public ShareAccountChargeData(final Long id, final Long chargeId, final Long accountId, final String name, final CurrencyData currency, final BigDecimal amount, final BigDecimal amountPaid, final BigDecimal amountWaived, final BigDecimal amountWrittenOff, final BigDecimal amountOutstanding, final EnumOptionData chargeTimeType, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/data/ShareAccountData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/data/ShareAccountData.java index d0e1f8474..86ca355cf 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/data/ShareAccountData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/data/ShareAccountData.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.Date; import org.apache.fineract.accounting.glaccount.data.GLAccountData; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.apache.fineract.organisation.monetary.data.CurrencyData; import org.apache.fineract.portfolio.accountdetails.data.ShareAccountSummaryData; @@ -31,6 +32,7 @@ import org.apache.fineract.portfolio.charge.data.ChargeData; import org.apache.fineract.portfolio.products.data.ProductData; import org.apache.fineract.portfolio.savings.data.SavingsAccountData; import org.apache.fineract.portfolio.shareproducts.data.ShareProductData; +import org.joda.time.LocalDate; @SuppressWarnings("unused") public class ShareAccountData implements AccountData { @@ -80,6 +82,75 @@ public class ShareAccountData implements AccountData { private Collection charges; private Collection dividends ; + + //import fields + private Integer requestedShares; + private LocalDate submittedDate; + private Integer minimumActivePeriodFrequencyType; + private Integer lockinPeriodFrequency; + private Integer lockinPeriodFrequencyType; + private LocalDate applicationDate; + private String locale; + private transient Integer rowIndex; + private String dateFormat; + + public static ShareAccountData importInstance(Long clientId,Long productId,Integer requestedShares,String externalId, + LocalDate submittedOnDate , Integer minimumActivePeriodDays,Integer minimumActivePeriodFrequencyType, + Integer lockinPeriodFrequency,Integer lockinPeriodFrequencyType,LocalDate applicationDate, + Boolean allowDividendCalculationForInactiveClients, Collection charges, + Long defaultSavingsAccountId,Integer rowIndex,String locale, String dateFormat){ + return new ShareAccountData(clientId,productId,requestedShares,externalId,submittedOnDate,minimumActivePeriodDays, + minimumActivePeriodFrequencyType,lockinPeriodFrequency,lockinPeriodFrequencyType,applicationDate,allowDividendCalculationForInactiveClients,charges, + defaultSavingsAccountId,rowIndex,locale,dateFormat); + } + private ShareAccountData(Long clientId,Long productId,Integer requestedShares,String externalId, + LocalDate submittedDate , Integer minimumActivePeriod,Integer minimumActivePeriodFrequencyType, + Integer lockinPeriodFrequency,Integer lockinPeriodFrequencyType,LocalDate applicationDate, + Boolean allowDividendCalculationForInactiveClients, Collection charges, + Long savingsAccountId,Integer rowIndex,String locale, String dateFormat) { + + this.clientId = clientId; + this.productId = productId; + this.requestedShares=requestedShares; + this.externalId = externalId; + this.submittedDate=submittedDate; + this.minimumActivePeriod = minimumActivePeriod; + this.minimumActivePeriodFrequencyType=minimumActivePeriodFrequencyType; + this.lockinPeriodFrequency=lockinPeriodFrequency; + this.lockinPeriodFrequencyType=lockinPeriodFrequencyType; + this.applicationDate=applicationDate; + this.allowDividendCalculationForInactiveClients = allowDividendCalculationForInactiveClients; + this.dateFormat= dateFormat; + this.locale=locale; + this.charges = charges; + this.savingsAccountId = savingsAccountId; + this.rowIndex=rowIndex; + this.clientName = null; + this.savingsAccountNumber = null; + this.defaultShares = null; + this.id = null; + this.accountNo = null; + this.productName = null; + this.status = null; + this.timeline = null; + this.currency = null; + this.summary = null; + this.purchasedShares = null; + this.currentMarketPrice = null; + this.lockinPeriod = null; + this.lockPeriodTypeEnum = null; + this.minimumActivePeriodTypeEnum = null; + this.dividends = null; + this.productOptions = null; + this.chargeOptions = null; + this.lockinPeriodFrequencyTypeOptions = null; + this.minimumActivePeriodFrequencyTypeOptions = null; + this.clientSavingsAccounts = null; + } + + public Integer getRowIndex() { + return rowIndex; + } // Data for template private Collection productOptions; diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/api/UsersApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/api/UsersApiResource.java index 481284a21..7103e2d89 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/api/UsersApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/api/UsersApiResource.java @@ -18,26 +18,27 @@ */ package org.apache.fineract.useradministration.api; +import java.io.InputStream; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Set; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; +import javax.ws.rs.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataParam; 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.UserConstants; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookPopulatorService; +import org.apache.fineract.infrastructure.bulkimport.service.BulkImportWorkbookService; import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; @@ -52,8 +53,6 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @Path("/users") -@Consumes({ MediaType.APPLICATION_JSON }) -@Produces({ MediaType.APPLICATION_JSON }) @Component @Scope("singleton") public class UsersApiResource { @@ -73,21 +72,29 @@ public class UsersApiResource { private final DefaultToApiJsonSerializer toApiJsonSerializer; private final ApiRequestParameterHelper apiRequestParameterHelper; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + private final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService; + private final BulkImportWorkbookService bulkImportWorkbookService; @Autowired public UsersApiResource(final PlatformSecurityContext context, final AppUserReadPlatformService readPlatformService, final OfficeReadPlatformService officeReadPlatformService, final DefaultToApiJsonSerializer toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper, - final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) { + final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, + final BulkImportWorkbookPopulatorService bulkImportWorkbookPopulatorService, + final BulkImportWorkbookService bulkImportWorkbookService) { this.context = context; this.readPlatformService = readPlatformService; this.officeReadPlatformService = officeReadPlatformService; this.toApiJsonSerializer = toApiJsonSerializer; this.apiRequestParameterHelper = apiRequestParameterHelper; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + this.bulkImportWorkbookPopulatorService=bulkImportWorkbookPopulatorService; + this.bulkImportWorkbookService=bulkImportWorkbookService; } @GET + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) public String retrieveAll(@Context final UriInfo uriInfo) { this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions); @@ -100,6 +107,8 @@ public class UsersApiResource { @GET @Path("{userId}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) public String retrieveOne(@PathParam("userId") final Long userId, @Context final UriInfo uriInfo) { this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions, userId); @@ -117,6 +126,8 @@ public class UsersApiResource { @GET @Path("template") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) public String template(@Context final UriInfo uriInfo) { this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions); @@ -128,6 +139,8 @@ public class UsersApiResource { } @POST + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) public String create(final String apiRequestBodyAsJson) { final CommandWrapper commandRequest = new CommandWrapperBuilder() // @@ -142,6 +155,8 @@ public class UsersApiResource { @PUT @Path("{userId}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) public String update(@PathParam("userId") final Long userId, final String apiRequestBodyAsJson) { final CommandWrapper commandRequest = new CommandWrapperBuilder() // @@ -156,6 +171,8 @@ public class UsersApiResource { @DELETE @Path("{userId}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) public String delete(@PathParam("userId") final Long userId) { final CommandWrapper commandRequest = new CommandWrapperBuilder() // @@ -166,4 +183,23 @@ public class UsersApiResource { return this.toApiJsonSerializer.serialize(result); } + + @GET + @Path("downloadtemplate") + @Produces("application/vnd.ms-excel") + public Response getUserTemplate(@QueryParam("officeId")final Long officeId,@QueryParam("staffId")final Long staffId, + @QueryParam("dateFormat") final String dateFormat) { + return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.USERS.toString(), officeId, staffId,dateFormat); + } + + @POST + @Path("uploadtemplate") + @Consumes(MediaType.MULTIPART_FORM_DATA) + public String postUsersTemplate(@FormDataParam("file") InputStream uploadedInputStream, + @FormDataParam("file") FormDataContentDisposition fileDetail, + @FormDataParam("locale") final String locale, @FormDataParam("dateFormat") final String dateFormat){ + final Long importDocumentId = this. bulkImportWorkbookService.importWorkbook(GlobalEntityType.USERS.toString(), uploadedInputStream,fileDetail, + locale,dateFormat); + return this.toApiJsonSerializer.serialize(importDocumentId); + } } \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/data/AppUserData.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/data/AppUserData.java index 075f4b0cb..9254dff3c 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/data/AppUserData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/data/AppUserData.java @@ -19,6 +19,7 @@ package org.apache.fineract.useradministration.data; import java.util.Collection; +import java.util.List; import java.util.Set; import org.apache.fineract.organisation.office.data.OfficeData; @@ -39,6 +40,12 @@ public class AppUserData { private final String email; private final Boolean passwordNeverExpires; + //import fields + private List roles; + private Boolean sendPasswordToEmail; + private Long staffId; + private transient Integer rowIndex; + @SuppressWarnings("unused") private final Collection allowedOffices; private final Collection availableRoles; @@ -49,6 +56,39 @@ public class AppUserData { @SuppressWarnings("unused") private Set clients; + public static AppUserData importInstance(Long officeId,Long staffId,String userName, String firstName, String lastName, + String email,Boolean sendPasswordToEmail,Boolean passwordNeverExpires, List roleIds, + Integer rowIndex){ + return new AppUserData(officeId,staffId,userName,firstName,lastName,email, + sendPasswordToEmail,passwordNeverExpires,roleIds,rowIndex); + } + private AppUserData(Long officeId,Long staffId,String username, String firstname, String lastname, + String email,Boolean sendPasswordToEmail,Boolean passwordNeverExpires, List roleIds, + Integer rowIndex) { + this.id = null; + this.username = username; + this.officeId = officeId; + this.officeName = null; + this.firstname = firstname; + this.lastname = lastname; + this.email = email; + this.passwordNeverExpires = passwordNeverExpires; + this.roles = roleIds; + this.sendPasswordToEmail = sendPasswordToEmail; + this.staffId = staffId; + this.rowIndex = rowIndex; + this.allowedOffices = null; + this.availableRoles = null; + this.selectedRoles = null; + this.staff = null; + this.isSelfServiceUser = null; + this.clients = null; + } + + public Integer getRowIndex() { + return rowIndex; + } + public static AppUserData template(final AppUserData user, final Collection officesForDropdown) { return new AppUserData(user.id, user.username, user.email, user.officeId, user.officeName, user.firstname, user.lastname, user.availableRoles, user.selectedRoles, officesForDropdown, user.staff, user.passwordNeverExpires, user.isSelfServiceUser); diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/data/RoleData.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/data/RoleData.java index fc5bebc49..7858ab929 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/data/RoleData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/data/RoleData.java @@ -52,4 +52,12 @@ public class RoleData implements Serializable { public int hashCode() { return this.id.hashCode(); } + + public Long getId() { + return id; + } + + public String getName() { + return name; + } } \ No newline at end of file diff --git a/fineract-provider/src/main/resources/sql/migrations/core_db/V336__m_import_document.sql b/fineract-provider/src/main/resources/sql/migrations/core_db/V336__m_import_document.sql new file mode 100644 index 000000000..386016e72 --- /dev/null +++ b/fineract-provider/src/main/resources/sql/migrations/core_db/V336__m_import_document.sql @@ -0,0 +1,39 @@ +-- +-- 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. +-- + +CREATE TABLE `m_import_document` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `document_id` int(20) NOT NULL, + `import_time` datetime NOT NULL, + `end_time` datetime DEFAULT NULL, + `entity_type` tinyint(3) NOT NULL, + `completed` tinyint(2) DEFAULT 0, + `total_records` bigint(20) DEFAULT 0, + `success_count` bigint(20) DEFAULT 0, + `failure_count` bigint(20) DEFAULT 0, + `createdby_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `import_document_id` (`document_id`), + CONSTRAINT `FK_m_import_m_document` FOREIGN KEY (`document_id`) REFERENCES `m_document` (`id`), + CONSTRAINT `FK_m_import_m_appuser` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`) +); + +INSERT INTO `m_permission` +(`grouping`,`code`,`entity_name`,`action_name`,`can_maker_checker`) VALUES +('infrastructure','READ_IMPORT','IMPORT','READ', 0); \ No newline at end of file