Adding chart of accounts.
diff --git a/build.gradle b/build.gradle
index 6644f9a..b472bcb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -78,6 +78,7 @@
[group: 'io.mifos.customer', name: 'api', version: versions.mifoscustomer],
[group: 'io.mifos.accounting', name: 'api', version: versions.mifosaccounting],
+ [group: 'io.mifos.accounting', name: 'importer', version: versions.mifosaccounting],
[group: 'io.mifos.portfolio', name: 'api', version: versions.mifosportfolio],
[group: 'io.mifos.deposit-account-management', name: 'api', version: versions.mifosdeposit],
diff --git a/src/main/java/io/mifos/dev/ServiceRunner.java b/src/main/java/io/mifos/dev/ServiceRunner.java
index 27e83ce..44140d5 100644
--- a/src/main/java/io/mifos/dev/ServiceRunner.java
+++ b/src/main/java/io/mifos/dev/ServiceRunner.java
@@ -18,6 +18,8 @@
import ch.vorburger.mariadb4j.DB;
import ch.vorburger.mariadb4j.DBConfigurationBuilder;
import io.mifos.accounting.api.v1.client.LedgerManager;
+import io.mifos.accounting.importer.AccountImporter;
+import io.mifos.accounting.importer.LedgerImporter;
import io.mifos.anubis.api.v1.domain.AllowedOperation;
import io.mifos.core.api.config.EnableApiFactory;
import io.mifos.core.api.context.AutoGuest;
@@ -67,12 +69,16 @@
import org.springframework.util.Base64Utils;
import java.io.IOException;
+import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
+import static io.mifos.accounting.api.v1.EventConstants.POST_ACCOUNT;
+import static io.mifos.accounting.api.v1.EventConstants.POST_LEDGER;
+
@SuppressWarnings("SpringAutowiredFieldsWarningInspection")
@RunWith(SpringRunner.class)
@SpringBootTest()
@@ -81,6 +87,7 @@
private static final String SCHEDULER_USER_NAME = "imhotep";
private static final String ADMIN_USER_NAME = "antony";
private static final String TEST_LOGGER = "test-logger";
+ private static final String LOAN_INCOME_LEDGER = "1100";
private static Microservice<Provisioner> provisionerService;
private static Microservice<IdentityManager> identityManager;
@@ -285,7 +292,7 @@
}
}
- private void provisionAppsViaSeshat() throws InterruptedException {
+ private void provisionAppsViaSeshat() throws InterruptedException, IOException {
final AuthenticationResponse authenticationResponse =
ServiceRunner.provisionerService.api().authenticate(ServiceRunner.CLIENT_ID, ApiConstants.SYSTEM_SU, "oS/0IiAME/2unkN1momDrhAdNKOhGykYFH/mJN20");
@@ -312,13 +319,13 @@
applicationsToCreate.forEach(application -> ServiceRunner.provisionerService.api().createApplication(application));
}
for (final Tenant tenant : tenantsToCreate) {
- try (final AutoSeshat ignored = new AutoSeshat(authenticationResponse.getToken())) {
- provisionAppsViaSeshatForTenant(tenant);
- }
+ try (final AutoSeshat ignored = new AutoSeshat(authenticationResponse.getToken())) {
+ provisionAppsViaSeshatForTenant(tenant);
+ }
}
}
- private String provisionAppsViaSeshatForTenant(final Tenant tenant) throws InterruptedException {
+ private String provisionAppsViaSeshatForTenant(final Tenant tenant) throws InterruptedException, IOException {
provisionerService.api().createTenant(tenant);
try (final AutoTenantContext ignored = new AutoTenantContext(tenant.getIdentifier())) {
@@ -387,12 +394,35 @@
provisionApp(tenant, depositAccountManager, io.mifos.deposit.api.v1.EventConstants.INITIALIZE);
- createOrgAdminRoleAndUser(tenantAdminPassword.getAdminPassword());
+ final UserWithPassword orgAdminUserPassword = createOrgAdminRoleAndUser(tenantAdminPassword.getAdminPassword());
+
+ createChartOfAccounts(orgAdminUserPassword);
return tenantAdminPassword.getAdminPassword();
}
}
+ private void createChartOfAccounts(final UserWithPassword userWithPassword) throws IOException, InterruptedException {
+ final Authentication authentication;
+ try (final AutoGuest ignored = new AutoGuest()) {
+ authentication = identityManager.api().login(userWithPassword.getIdentifier(), userWithPassword.getPassword());
+ }
+
+ try (final AutoUserContext ignored = new AutoUserContext(userWithPassword.getIdentifier(), authentication.getAccessToken())) {
+ final LedgerImporter ledgerImporter = new LedgerImporter(ledgerManager.api(), logger);
+ final URL ledgersUri = ClassLoader.getSystemResource("ledgers.csv");
+ ledgerImporter.importCSV(ledgersUri);
+ Assert.assertTrue(this.eventRecorder.wait(POST_LEDGER, LOAN_INCOME_LEDGER));
+
+ final AccountImporter accountImporter = new AccountImporter(ledgerManager.api(), logger);
+ final URL accountsUri = ClassLoader.getSystemResource("accounts.csv");
+ accountImporter.importCSV(accountsUri);
+ Assert.assertTrue(this.eventRecorder.wait(POST_ACCOUNT, "9330"));
+
+ identityManager.api().logout();
+ }
+ }
+
private <T> void provisionApp(
final Tenant tenant,
final Microservice<T> service,
@@ -451,14 +481,14 @@
return role;
}
- private void createOrgAdminRoleAndUser(final String tenantAdminPassword) throws InterruptedException {
+ private UserWithPassword createOrgAdminRoleAndUser(final String tenantAdminPassword) throws InterruptedException {
final Authentication adminAuthentication;
try (final AutoUserContext ignored = new AutoGuest()) {
adminAuthentication = ServiceRunner.identityManager.api().login(ADMIN_USER_NAME, tenantAdminPassword);
}
try (final AutoUserContext ignored = new AutoUserContext(ADMIN_USER_NAME, adminAuthentication.getAccessToken())) {
- final Role fimsAdministratorRole = createOrgAdministratorRole();
+ final Role fimsAdministratorRole = defineOrgAdministratorRole();
ServiceRunner.identityManager.api().createRole(fimsAdministratorRole);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.OPERATION_POST_ROLE, fimsAdministratorRole.getIdentifier()));
@@ -472,10 +502,13 @@
Assert.assertTrue(this.eventRecorder.wait(EventConstants.OPERATION_POST_USER, fimsAdministratorUser.getIdentifier()));
ServiceRunner.identityManager.api().logout();
+
+ enableUser(fimsAdministratorUser);
+ return fimsAdministratorUser;
}
}
- private Role createOrgAdministratorRole() {
+ private Role defineOrgAdministratorRole() {
final Permission employeeAllPermission = new Permission();
employeeAllPermission.setAllowedOperations(AllowedOperation.ALL);
employeeAllPermission.setPermittableEndpointGroupIdentifier(io.mifos.office.api.v1.PermittableGroupIds.EMPLOYEE_MANAGEMENT);
@@ -496,6 +529,14 @@
selfManagementPermission.setAllowedOperations(AllowedOperation.ALL);
selfManagementPermission.setPermittableEndpointGroupIdentifier(io.mifos.identity.api.v1.PermittableGroupIds.SELF_MANAGEMENT);
+ final Permission ledgerManagementPermission = new Permission();
+ ledgerManagementPermission.setAllowedOperations(AllowedOperation.ALL);
+ ledgerManagementPermission.setPermittableEndpointGroupIdentifier(io.mifos.accounting.api.v1.PermittableGroupIds.THOTH_LEDGER);
+
+ final Permission accountManagementPermission = new Permission();
+ accountManagementPermission.setAllowedOperations(AllowedOperation.ALL);
+ accountManagementPermission.setPermittableEndpointGroupIdentifier(io.mifos.accounting.api.v1.PermittableGroupIds.THOTH_ACCOUNT);
+
final Role role = new Role();
role.setIdentifier("orgadmin");
role.setPermissions(
@@ -504,7 +545,9 @@
officeAllPermission,
userAllPermission,
roleAllPermission,
- selfManagementPermission
+ selfManagementPermission,
+ ledgerManagementPermission,
+ accountManagementPermission
)
);
diff --git a/src/main/resources/accounts.csv b/src/main/resources/accounts.csv
new file mode 100644
index 0000000..d2ac4bd
--- /dev/null
+++ b/src/main/resources/accounts.csv
@@ -0,0 +1,79 @@
+parentIdentifier,identifier,name
+1100,1101,"Interest on Business Loans"
+1100,1102,"Interest on Agriculture Loans"
+1100,1103,"Interest on Consumer Loans"
+1100,1104,"Interest on Savings Secured"
+1100,1105,"Interest on Other Member Loans"
+1100,1120,"Interest on Lines of Credit"
+1100,1121,"Interest on Credit Cards"
+1100,1140,"Interest on Real Estate Loans"
+1100,1190,"Interest Refunds"
+1200,1210,"Income from Government Investments"
+1200,1220,"Income from Govenment Agency Securities"
+1200,1230,"Income from Savings/Deposits/Certificates"
+1200,1290,"Income from Other Investments"
+1300,1310,"Loan Origination Fees"
+1300,1311,"Loan Late Payment Fee"
+1300,1320,"Loan Refinance Fee"
+1300,1390,"Other Loan Fee"
+2800,2820,"Collection Expenses"
+2800,2830,"Recording Fees—Chattel Lien Insurance"
+2800,2840,"Credit Reports"
+2800,2850,"Refunds—Real Estate Service Charges"
+2800,2860,"Credit Card Program Expenses"
+2800,2870,"Service Fees on Loans Purchased"
+2800,2890,"Other Loan Servicing Expenses"
+3000,3010,"Provision for Loan Losses—Consumer Loans"
+3000,3020,"Provision for Loan Losses—Lines of Credit"
+3000,3030,"Provision for Loan Losses—Real Estate Loans"
+3000,3040,"Provision for Loan Losses—Other Loans"
+3000,3090,"Other Provision for Losses"
+3100,3110,"Saving Insurance"
+3100,3120,"Life Savings Insurance"
+3100,3130,"Borrowers' Insurance"
+3100,3190,"Other Members' Insurance"
+3800,3801,"Share Dividend"
+3800,3810,"Regular Saving Interest"
+3800,3820,"Checking Interest"
+3800,3830,"Club Account Interest"
+3800,3840,"Saving Certificate Interest"
+3800,3890,"Other Interest Expense"
+7000,7011,"Commercial Loans"
+7000,7012,"Agriculture Loans"
+7000,7013,"Consumer Loans"
+7000,7014,"Other Member Loans"
+7000,7015,"Home Equity Loans"
+7000,7021,"Lines of Credit to Members—Credit Cards"
+7000,7022,"Lines of Credit—Cash Advances in Process"
+7000,7023,"Net Origination Fees (Costs)—Lines of Credit"
+7000,7024,"Net Commitment Fees (Costs)—Lines of Credit"
+7000,7031,"Net Origination Fees (Costs)"
+7000,7070,"Loans—Collateral in Process of Liquidation"
+7300,7310,"Bank account one"
+7300,7311,"Bank account two"
+7300,7312,"Petty Cash"
+7300,7351,"Vault Cash"
+7300,7352,"Teller One"
+7300,7353,"Teller Two"
+7300,7353,"Teller Three"
+7800,7810,"Accrued Interest on Loans"
+7800,7820,"Accrued Income on Investments"
+7800,7830,"Accrued Credit Card Income"
+7800,7890,"Other Accrued Income"
+8200,8201,"Dividends Payable on Shares"
+8200,8202,"Interest Payable on Savings"
+8200,8203,"Interest Payable on Club Accounts"
+8200,8207,"Interest Payable on Other Accounts"
+8400,8410,"VAT Taxes payable"
+8400,8420,"Withholding taxes payable"
+8400,8490,"Other Taxes Payable"
+8500,8540,"Accrued Dividends Payable"
+8500,8550,"Accrued Interest Payable"
+8500,8590,"Other Accrued Expenses"
+9000,9010,"Share Account"
+9000,9020,"Savings"
+9000,9030,"Club Accounts"
+9000,9040,"Other Savings"
+9300,9310,"Regular Reserves"
+9300,9320,"Special Reserve for Losses"
+9300,9330,"Other Reserves"
\ No newline at end of file
diff --git a/src/main/resources/ledgers.csv b/src/main/resources/ledgers.csv
new file mode 100644
index 0000000..ec641d7
--- /dev/null
+++ b/src/main/resources/ledgers.csv
@@ -0,0 +1,53 @@
+parentIdentifier,identifier,description,type,show
+,1000,"Income",REVENUE,true
+1000,1100,"Income from Loans",REVENUE,true
+1000,1200,"Investment Income",REVENUE,true
+1000,1300,"Fees and Charges",REVENUE,true
+1000,1400,"Gain (Loss) on Sale of Loans",REVENUE,true
+1000,1500,"Miscellaneouse Income",REVENUE,true
+1000,1600,"Service Income on Loans",REVENUE,true
+1000,1700,"Trading Profits & Losses",REVENUE,true
+,2000,"Expenses",EXPENSE,true
+2000,2100,"Employee Compensation",EXPENSE,true
+2000,2200,"Employee Benefits",EXPENSE,true
+2000,2300,"Travel and Conference Expenses",EXPENSE,true
+2000,2400,"Association Dues",EXPENSE,true
+2000,2500,"Office Occupancy Expenses",EXPENSE,true
+2000,2600,"Office Operations Expenses",EXPENSE,true
+2000,2700,"Educational and Promotional Expenses",EXPENSE,true
+2000,2800,"Loan Servicing Expenses",EXPENSE,true
+2000,2900,"Professional and Outside Services",EXPENSE,true
+2000,3000,"Provision for Loan Losses",EXPENSE,true
+2000,3100,"Member Insurance",EXPENSE,true
+2000,3220,"Federal Operating Fee",EXPENSE,true
+2000,3300,"Cash Over and Short",EXPENSE,true
+2000,3400,"Interest on Borrowed Money",EXPENSE,true
+2000,3550,"Annual Meeting Expenses",EXPENSE,true
+2000,3700,"Miscellaneous Operating Expenses",EXPENSE,true
+2000,3800,"Interest (Dividend) Expense",EXPENSE,true
+,7000,"Assets",ASSET,true
+7000,7010,"Loans to Members",ASSET,true
+7000,7020,"Lines of Credit to Members",ASSET,true
+7000,7030,"Real Estate Loans",ASSET,true
+7000,7100,"Other Loans",ASSET,true
+7000,7200,"Other Receivables",ASSET,true
+7000,7300,"Cash Accounts",ASSET,true
+7000,7350,"Change Fund",ASSET,true
+7000,7400,"Investments",ASSET,true
+7000,7420,"Federal Agency Securities",ASSET,true
+7000,7500,"Investments—Investment Allowance",ASSET,true
+7000,7600,"Prepaid Expenses and Deferred Charges",ASSET,true
+7000,7700,"Fixed Assets",ASSET,true
+7000,7800,"Accrued Income",ASSET,true
+7000,7900,"Other Assets",ASSET,true
+,8000,"Accounts Payable",LIABILITY,true
+8000,8100,"Accounts Payable",LIABILITY,true
+8000,8200,"Interest Payable",LIABILITY,true
+8000,8400,"Taxes Payable",LIABILITY,true
+8000,8500,"Accrued Expenses",LIABILITY,true
+,9000,"Equity",EQUITY,true
+9000,9100,"Member Savings",EQUITY,true
+9000,9300,"Reserves",EQUITY,true
+9000,9400,"Undivided Earnings",EQUITY,true
+9000,9550,"Donated Equity",EQUITY,true
+9000,9560,"Net Income (Loss)",EQUITY,true
\ No newline at end of file