Merge pull request #18 from Anh3h/my-work

Create chart of accounts
diff --git a/bash_scripts/accounts.csv b/bash_scripts/accounts.csv
new file mode 100644
index 0000000..a8d9183
--- /dev/null
+++ b/bash_scripts/accounts.csv
@@ -0,0 +1,85 @@
+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,1312,"Processing Fee"
+1300,1313,"Disbursement 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"
+7310,7310.1,"Bank account one general"
+7310,7310.2,"Bank account one Pending Disbursal"
+7310,7311.1,"Bank account two general"
+7310,7311.2,"Bank account two Pending Disbursal"
+7300,7312,"Petty Cash"
+7300,7351,"Vault Cash"
+7300,7352,"Teller One"
+7300,7353,"Teller Two"
+7300,7354,"Teller Three"
+7800,7810,"Accrued Interest on Loans"
+7800,7820,"Accrued Income on Investments"
+7800,7830,"Accrued Credit Card Income"
+7800,7840,"Accrued Late Fee 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,8530,"Loans 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/bash_scripts/ledgers.csv b/bash_scripts/ledgers.csv
new file mode 100644
index 0000000..b9db7ca
--- /dev/null
+++ b/bash_scripts/ledgers.csv
@@ -0,0 +1,55 @@
+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,"Miscellaneous 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
+7300,7310,"Bank account one",ASSET,true
+7300,7311,"Bank account two",ASSET,true
+7300,7350,"Change Fund",ASSET,true
+7000,7400,"Investments",ASSET,true
+7400,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
diff --git a/bash_scripts/provision.sh b/bash_scripts/provision.sh
index 1ba12f3..d7bf0f9 100755
--- a/bash_scripts/provision.sh
+++ b/bash_scripts/provision.sh
@@ -261,6 +261,122 @@
     echo "Enabled permission, $permission for service $service"
 }
 
+function create_chart_of_accounts {
+    local ledger_file="ledgers.csv"
+    local accounts_file="accounts.csv"
+    local tenant="$1"
+    local user="$2"
+
+    create_ledgers "$ledger_file" "$tenant" "$user"
+    create_accounts "$accounts_file" "$tenant" "$user"
+}
+
+function create_accounts {
+    local accounts_file="$1"
+    local tenant="$2"
+    local user="$3"
+
+    echo ""
+    echo "Creating accounts..."
+    while IFS="," read -r parent_id id name; do
+        if [ "$parent_id" != "parentIdentifier" ]; then
+            local ledger_arr
+            local ledger_type
+
+            IFS=',' read -ra ledger_arr <<< $( grep $parent_id -m 1 ledgers.csv )
+            ledger_type=${ledger_arr[3]}
+            create_account "$tenant" "$user" "$parent_id" "$id" "$name" "$ledger_type"
+        fi
+    done < "$accounts_file"
+}
+
+function create_ledgers {
+    local ledger_file="$1"
+    local tenant="$2"
+    local user="$3"
+
+    echo ""
+    echo "Creating ledgers..."
+    while IFS="," read -r parent_id id description ledger_type show; do
+        if [ "$parent_id" != "parentIdentifier" ]; then
+            if [ -z "$parent_id" ]; then
+                create_ledger "$tenant" "$user" "$id" "$description" "$ledger_type" "$show"
+                sleep 5s
+            else
+                update_ledger "$tenant" "$user" "$id" "$parent_id" "$description" "$ledger_type" "$show"
+            fi
+        fi
+
+    done < "$ledger_file"
+}
+
+function create_account {
+    local tenant="$1"
+    local user="$2"
+    local parent_id="$3"
+    local id="$4"
+    local name="$5"
+    local type="$6"
+
+    curl -X POST -H "Content-Type: application/json" -H "User: $user" -H "Authorization: ${ACCESS_TOKEN}" -H "X-Tenant-Identifier: $tenant" \
+        --data '{
+            "type": "'"$type"'",
+            "identifier": "'"$id"'",
+            "name": '"$name"',
+            "name": '"$name"',
+            "holders": [],
+            "signatureAuthorities": [],
+            "balance": 0.0,
+            "ledger": "'"$parent_id"'"
+        }' \
+        ${ACCOUNTING_URL}/accounts
+    echo ""
+    echo "Created account $id : $name"
+}
+
+function create_ledger {
+    local tenant="$1"
+    local user="$2"
+    local id="$3"
+    local description="$4"
+    local ledger_type="$5"
+    local show="$6"
+
+    curl -X POST -H "Content-Type: application/json" -H "User: $user" -H "Authorization: ${ACCESS_TOKEN}" -H "X-Tenant-Identifier: $tenant" \
+        --data '{
+            "type": "'"$ledger_type"'",
+            "identifier": "'"$id"'",
+            "name": "'"$id"'",
+            "description": '"$description"',
+            "showAccountsInChart": '$show'
+        }' \
+        ${ACCOUNTING_URL}/ledgers
+    echo ""
+    echo "Created ledge account $id : $description"
+}
+
+function update_ledger {
+    local tenant="$1"
+    local user="$2"
+    local id="$3"
+    local parent_id="$4"
+    local description="$5"
+    local ledger_type="$6"
+    local show="$7"
+
+    curl -X POST -H "Content-Type: application/json" -H "User: $user" -H "Authorization: ${ACCESS_TOKEN}" -H "X-Tenant-Identifier: $tenant" \
+        --data '{
+            "type": "'"$ledger_type"'",
+            "identifier": "'"$id"'",
+            "name": "'"$id"'",
+            "description": '"$description"',
+            "parentLedgerIdentifier": "'"$parent_id"'",
+            "showAccountsInChart": '$show'
+        }' \
+        ${ACCOUNTING_URL}/ledgers/${parent_id}
+    echo "Add ledge account $id : $description to $parent_id"
+}
+
 init-variables
 auto-seshat
 create-application "$IDENTITY_MS_NAME" "" "$MS_VENDOR" "$IDENTITY_URL"
@@ -277,7 +393,7 @@
 create-application "$GROUP_MS_NAME" "" "$MS_VENDOR" "$GROUP_URL"
 create-application "$NOTIFICATIONS_MS_NAME" "" "$MS_VENDOR" "$NOTIFICATIONS_URL"
 
-#Set tenant identifier
+# # Set tenant identifier
 TENANT=$1
 create-tenant ${TENANT} "${TENANT}" "All in one Demo Server" ${TENANT}
 assign-identity-ms ${TENANT}
@@ -312,4 +428,6 @@
 provision-app ${TENANT} $PAYROLL_MS_NAME
 provision-app ${TENANT} $GROUP_MS_NAME
 provision-app ${TENANT} $NOTIFICATIONS_MS_NAME
+login ${TENANT} "operator" "aW5pdDFAbDIz"
+create_chart_of_accounts ${TENANT} "operator"
 echo "COMPLETED PROVISIONING PROCESS."