From 4d2da782693bf5764395cf50898f0791cb4063d1 Mon Sep 17 00:00:00 2001 From: sunportainer Date: Sun, 3 Jul 2022 20:48:13 +0800 Subject: [PATCH] init project and finish basic code --- data/data.json | 339 ++++++++++++++++++++++++++++++++++ data/test_error_data.json | 339 ++++++++++++++++++++++++++++++++++ data/test_no_liabilities.json | 276 +++++++++++++++++++++++++++ data/test_no_revenue.json | 326 ++++++++++++++++++++++++++++++++ go.mod | 5 + go.sum | 2 + main.go | 7 + service/challenge.go | 94 ++++++++++ 8 files changed, 1388 insertions(+) create mode 100644 data/data.json create mode 100644 data/test_error_data.json create mode 100644 data/test_no_liabilities.json create mode 100644 data/test_no_revenue.json create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 service/challenge.go diff --git a/data/data.json b/data/data.json new file mode 100644 index 00000000..2cbc614b --- /dev/null +++ b/data/data.json @@ -0,0 +1,339 @@ +{ + "object_category": "general-ledger", + "connection_id": "69260737-4c37-4f28-a9dc-270473a6d84a", + "user": "b0c9fe7c-915e-45e4-8e9e-49d4f27281a5", + "object_creation_date": "2020-10-30T01:58:16.723Z", + "data": [ + { + "account_category": "revenue", + "account_code": "200", + "account_currency": "AUD", + "account_identifier": "e2bacdc6-2006-43c2-a5da-3c0e5f43b452", + "account_status": "ACTIVE", + "value_type": "credit", + "account_name": "Sales", + "account_type": "sales", + "account_type_bank": "", + "system_account": "", + "total_value": 32431.0 + }, + { + "account_code": "400", + "account_currency": "AUD", + "account_identifier": "d392fe47-c99d-499e-a200-46709dd6b6e7", + "account_name": "Advertising", + "account_status": "ACTIVE", + "system_account": "", + "value_type": "debit", + "account_category": "expense", + "account_type_bank": "", + "total_value": 1830.18, + "account_type": "overheads" + }, + { + "account_currency": "AUD", + "account_identifier": "959af5f4-9925-44e8-b283-7ddf4b427238", + "account_status": "ACTIVE", + "value_type": "debit", + "system_account": "", + "total_value": 31.5, + "account_category": "expense", + "account_code": "404", + "account_name": "Bank Fees", + "account_type": "overheads", + "account_type_bank": "" + }, + { + "account_type_bank": "", + "value_type": "debit", + "total_value": 310.0, + "account_name": "Cleaning", + "account_type": "overheads", + "account_currency": "AUD", + "account_identifier": "ff09eac3-5b17-44fb-9eea-e2e9375e91b4", + "account_status": "ACTIVE", + "system_account": "", + "account_category": "expense", + "account_code": "408" + }, + { + "account_status": "ACTIVE", + "system_account": "", + "total_value": 49.0, + "account_category": "expense", + "account_code": "412", + "account_currency": "AUD", + "account_identifier": "6db51cfa-0326-4e63-a743-c78c4d99aba4", + "account_name": "Consulting & Accounting", + "account_type": "overheads", + "account_type_bank": "", + "value_type": "debit" + }, + { + "system_account": "", + "value_type": "debit", + "total_value": 477.2, + "account_status": "ACTIVE", + "account_type": "overheads", + "account_type_bank": "", + "account_category": "expense", + "account_code": "420", + "account_currency": "AUD", + "account_identifier": "18e27517-81e0-437c-bc21-fbba8e30d6bb", + "account_name": "Entertainment" + }, + { + "account_code": "429", + "account_currency": "AUD", + "account_status": "ACTIVE", + "account_type": "overheads", + "account_type_bank": "", + "account_category": "expense", + "account_identifier": "94882296-5acf-4350-8c5b-82bc9370ab78", + "account_name": "General Expenses", + "system_account": "", + "value_type": "debit", + "total_value": 966.87 + }, + { + "account_currency": "AUD", + "account_name": "Light, Power, Heating", + "account_status": "ACTIVE", + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "account_category": "expense", + "account_code": "445", + "account_identifier": "42a56c1a-6141-4bf2-913d-916dc1a35cfd", + "account_type_bank": "", + "total_value": 645.0 + }, + { + "account_currency": "AUD", + "account_type": "overheads", + "account_type_bank": "", + "system_account": "", + "account_category": "expense", + "account_code": "449", + "account_identifier": "005f380d-4a9c-497f-b9d7-817f0f02790e", + "account_name": "Motor Vehicle Expenses", + "account_status": "ACTIVE", + "value_type": "debit", + "total_value": 310.91 + }, + { + "account_code": "453", + "account_currency": "AUD", + "account_identifier": "8ab9d684-f897-4168-b5d1-2279bf74bb82", + "account_status": "ACTIVE", + "account_type": "overheads", + "account_type_bank": "", + "value_type": "debit", + "account_category": "expense", + "account_name": "Office Expenses", + "system_account": "", + "total_value": 1295.99 + }, + { + "account_code": "461", + "account_currency": "AUD", + "account_type_bank": "", + "account_status": "ACTIVE", + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "total_value": 160.54, + "account_category": "expense", + "account_identifier": "b18eaea6-4d11-462c-ac30-7975108b5859", + "account_name": "Printing & Stationery" + }, + { + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "account_currency": "AUD", + "account_code": "469", + "account_identifier": "f5f05ee3-f9cd-4bf9-9423-ed81de96b537", + "account_name": "Rent", + "account_status": "ACTIVE", + "account_type_bank": "", + "total_value": 3000.0, + "account_category": "expense" + }, + { + "account_type": "overheads", + "account_type_bank": "", + "system_account": "", + "value_type": "debit", + "total_value": 190.35, + "account_currency": "AUD", + "account_name": "Telephone & Internet", + "account_identifier": "266f40cc-5aa1-4f6c-b078-eb615171d6de", + "account_status": "ACTIVE", + "account_category": "expense", + "account_code": "489" + }, + { + "account_category": "expense", + "account_code": "493", + "account_currency": "AUD", + "account_name": "Travel - National", + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "total_value": 462.14, + "account_identifier": "25717024-5b50-4320-93b7-280c0614a613", + "account_status": "ACTIVE", + "account_type_bank": "" + }, + { + "account_category": "expense", + "account_code": "477", + "account_currency": "AUD", + "account_type_bank": "", + "system_account": "", + "total_value": 26800.0, + "account_identifier": "c4f12f09-846e-4f6f-b39c-dff3be3e49a7", + "account_name": "Wages and Salaries", + "account_status": "ACTIVE", + "account_type": "overheads", + "value_type": "debit" + }, + { + "account_category": "assets", + "account_code": "610", + "account_type": "current_accounts_receivable", + "account_type_bank": "", + "account_currency": "AUD", + "account_identifier": "3dd5c80d-e109-4313-8c61-41648e33704f", + "account_name": "Accounts Receivable", + "account_status": "ACTIVE", + "system_account": "DEBTORS", + "value_type": "debit", + "total_value": 10749.5 + }, + { + "system_account": "", + "account_code": "090", + "account_currency": "AUD", + "account_identifier": "13918178-849a-4823-9a31-57b7eac713d7", + "account_status": "ACTIVE", + "account_type": "bank", + "account_category": "assets", + "account_name": "Business Bank Account", + "account_type_bank": "BANK", + "value_type": "debit", + "total_value": 1065.85 + }, + { + "system_account": "", + "value_type": "debit", + "account_category": "assets", + "account_code": "091", + "account_currency": "AUD", + "account_status": "ACTIVE", + "account_type_bank": "BANK", + "account_identifier": "26028d3a-f981-44d6-a9ed-a522198870f8", + "account_name": "Business Savings Account", + "account_type": "bank", + "total_value": 15081.23 + }, + { + "account_category": "assets", + "account_name": "Office Equipment", + "total_value": 750.0, + "account_status": "ACTIVE", + "account_type": "fixed", + "account_type_bank": "", + "system_account": "", + "value_type": "debit", + "account_code": "710", + "account_currency": "AUD", + "account_identifier": "2d69b4ee-37d4-4f67-b950-32cbdd5765ed" + }, + { + "account_currency": "AUD", + "account_identifier": "24d010bf-5e4b-42dd-9aa3-a5484dd0686f", + "account_name": "Less Accumulated Depreciation on Office Equipment", + "account_type": "fixed", + "account_type_bank": "", + "account_category": "assets", + "account_status": "ACTIVE", + "system_account": "", + "value_type": "credit", + "total_value": 825.0, + "account_code": "711" + }, + { + "account_type": "current_accounts_payable", + "system_account": "CREDITORS", + "value_type": "credit", + "account_category": "liability", + "account_code": "800", + "account_identifier": "8e9c5166-d3fe-4e21-827a-f42753568e80", + "account_name": "Accounts Payable", + "account_status": "ACTIVE", + "account_currency": "AUD", + "account_type_bank": "", + "total_value": 3434.06 + }, + { + "account_category": "liability", + "account_identifier": "66e60a82-99d8-47d1-956b-5baea404acba", + "account_status": "ACTIVE", + "account_type_bank": "", + "system_account": "GST", + "total_value": 2245.99, + "account_code": "820", + "account_currency": "AUD", + "account_name": "GST", + "account_type": "tax", + "value_type": "credit" + }, + { + "account_code": "840", + "account_currency": "AUD", + "account_name": "Historical Adjustment", + "account_status": "ACTIVE", + "total_value": 19212.21, + "value_type": "credit", + "account_category": "liability", + "account_identifier": "305b05b3-01f3-4f47-a45d-edfa66ea03e7", + "account_type": "current", + "account_type_bank": "", + "system_account": "HISTORICAL" + }, + { + "account_name": "PAYG Withholdings Payable", + "account_status": "ACTIVE", + "account_type_bank": "", + "system_account": "", + "value_type": "credit", + "total_value": 6028.0, + "account_category": "liability", + "account_code": "825", + "account_currency": "AUD", + "account_identifier": "4d111d55-1c71-46b4-8cbc-d8b54d8d54c5", + "account_type": "payroll" + }, + { + "account_category": "liability", + "account_type": "current", + "value_type": "credit", + "system_account": "UNPAIDEXPCLM", + "total_value": 0.0, + "account_code": "801", + "account_currency": "AUD", + "account_identifier": "c11b84a9-e90a-4094-83d7-b8494d195ecc", + "account_name": "Unpaid Expense Claims", + "account_status": "ACTIVE", + "account_type_bank": "" + } + ], + "currency": "AUD", + "object_origin_type": "accounting", + "object_origin_category": "bookkeeping", + "object_type": "day", + "object_class": "timeline-balance", + "balance_date": "2020-09-30T00:00:00.000Z" +} \ No newline at end of file diff --git a/data/test_error_data.json b/data/test_error_data.json new file mode 100644 index 00000000..e102f98a --- /dev/null +++ b/data/test_error_data.json @@ -0,0 +1,339 @@ +{ + "object_category": "general-ledger", + "connection_id": "69260737-4c37-4f28-a9dc-270473a6d84a", + "user": "b0c9fe7c-915e-45e4-8e9e-49d4f27281a5", + "object_creation_date": "2020-10-30T01:58:16.723Z", + "data": + { + "account_category": "revenue", + "account_code": "200", + "account_currency": "AUD", + "account_identifier": "e2bacdc6-2006-43c2-a5da-3c0e5f43b452", + "account_status": "ACTIVE", + "value_type": "credit", + "account_name": "Sales", + "account_type": "sales", + "account_type_bank": "", + "system_account": "", + "total_value": 32431.0 + }, + { + "account_code": "400", + "account_currency": "AUD", + "account_identifier": "d392fe47-c99d-499e-a200-46709dd6b6e7", + "account_name": "Advertising", + "account_status": "ACTIVE", + "system_account": "", + "value_type": "debit", + "account_category": "expense", + "account_type_bank": "", + "total_value": 1830.18, + "account_type": "overheads" + }, + { + "account_currency": "AUD", + "account_identifier": "959af5f4-9925-44e8-b283-7ddf4b427238", + "account_status": "ACTIVE", + "value_type": "debit", + "system_account": "", + "total_value": 31.5, + "account_category": "expense", + "account_code": "404", + "account_name": "Bank Fees", + "account_type": "overheads", + "account_type_bank": "" + }, + { + "account_type_bank": "", + "value_type": "debit", + "total_value": 310.0, + "account_name": "Cleaning", + "account_type": "overheads", + "account_currency": "AUD", + "account_identifier": "ff09eac3-5b17-44fb-9eea-e2e9375e91b4", + "account_status": "ACTIVE", + "system_account": "", + "account_category": "expense", + "account_code": "408" + }, + { + "account_status": "ACTIVE", + "system_account": "", + "total_value": 49.0, + "account_category": "expense", + "account_code": "412", + "account_currency": "AUD", + "account_identifier": "6db51cfa-0326-4e63-a743-c78c4d99aba4", + "account_name": "Consulting & Accounting", + "account_type": "overheads", + "account_type_bank": "", + "value_type": "debit" + }, + { + "system_account": "", + "value_type": "debit", + "total_value": 477.2, + "account_status": "ACTIVE", + "account_type": "overheads", + "account_type_bank": "", + "account_category": "expense", + "account_code": "420", + "account_currency": "AUD", + "account_identifier": "18e27517-81e0-437c-bc21-fbba8e30d6bb", + "account_name": "Entertainment" + }, + { + "account_code": "429", + "account_currency": "AUD", + "account_status": "ACTIVE", + "account_type": "overheads", + "account_type_bank": "", + "account_category": "expense", + "account_identifier": "94882296-5acf-4350-8c5b-82bc9370ab78", + "account_name": "General Expenses", + "system_account": "", + "value_type": "debit", + "total_value": 966.87 + }, + { + "account_currency": "AUD", + "account_name": "Light, Power, Heating", + "account_status": "ACTIVE", + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "account_category": "expense", + "account_code": "445", + "account_identifier": "42a56c1a-6141-4bf2-913d-916dc1a35cfd", + "account_type_bank": "", + "total_value": 645.0 + }, + { + "account_currency": "AUD", + "account_type": "overheads", + "account_type_bank": "", + "system_account": "", + "account_category": "expense", + "account_code": "449", + "account_identifier": "005f380d-4a9c-497f-b9d7-817f0f02790e", + "account_name": "Motor Vehicle Expenses", + "account_status": "ACTIVE", + "value_type": "debit", + "total_value": 310.91 + }, + { + "account_code": "453", + "account_currency": "AUD", + "account_identifier": "8ab9d684-f897-4168-b5d1-2279bf74bb82", + "account_status": "ACTIVE", + "account_type": "overheads", + "account_type_bank": "", + "value_type": "debit", + "account_category": "expense", + "account_name": "Office Expenses", + "system_account": "", + "total_value": 1295.99 + }, + { + "account_code": "461", + "account_currency": "AUD", + "account_type_bank": "", + "account_status": "ACTIVE", + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "total_value": 160.54, + "account_category": "expense", + "account_identifier": "b18eaea6-4d11-462c-ac30-7975108b5859", + "account_name": "Printing & Stationery" + }, + { + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "account_currency": "AUD", + "account_code": "469", + "account_identifier": "f5f05ee3-f9cd-4bf9-9423-ed81de96b537", + "account_name": "Rent", + "account_status": "ACTIVE", + "account_type_bank": "", + "total_value": 3000.0, + "account_category": "expense" + }, + { + "account_type": "overheads", + "account_type_bank": "", + "system_account": "", + "value_type": "debit", + "total_value": 190.35, + "account_currency": "AUD", + "account_name": "Telephone & Internet", + "account_identifier": "266f40cc-5aa1-4f6c-b078-eb615171d6de", + "account_status": "ACTIVE", + "account_category": "expense", + "account_code": "489" + }, + { + "account_category": "expense", + "account_code": "493", + "account_currency": "AUD", + "account_name": "Travel - National", + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "total_value": 462.14, + "account_identifier": "25717024-5b50-4320-93b7-280c0614a613", + "account_status": "ACTIVE", + "account_type_bank": "" + }, + { + "account_category": "expense", + "account_code": "477", + "account_currency": "AUD", + "account_type_bank": "", + "system_account": "", + "total_value": 26800.0, + "account_identifier": "c4f12f09-846e-4f6f-b39c-dff3be3e49a7", + "account_name": "Wages and Salaries", + "account_status": "ACTIVE", + "account_type": "overheads", + "value_type": "debit" + }, + { + "account_category": "assets", + "account_code": "610", + "account_type": "current_accounts_receivable", + "account_type_bank": "", + "account_currency": "AUD", + "account_identifier": "3dd5c80d-e109-4313-8c61-41648e33704f", + "account_name": "Accounts Receivable", + "account_status": "ACTIVE", + "system_account": "DEBTORS", + "value_type": "debit", + "total_value": 10749.5 + }, + { + "system_account": "", + "account_code": "090", + "account_currency": "AUD", + "account_identifier": "13918178-849a-4823-9a31-57b7eac713d7", + "account_status": "ACTIVE", + "account_type": "bank", + "account_category": "assets", + "account_name": "Business Bank Account", + "account_type_bank": "BANK", + "value_type": "debit", + "total_value": 1065.85 + }, + { + "system_account": "", + "value_type": "debit", + "account_category": "assets", + "account_code": "091", + "account_currency": "AUD", + "account_status": "ACTIVE", + "account_type_bank": "BANK", + "account_identifier": "26028d3a-f981-44d6-a9ed-a522198870f8", + "account_name": "Business Savings Account", + "account_type": "bank", + "total_value": 15081.23 + }, + { + "account_category": "assets", + "account_name": "Office Equipment", + "total_value": 750.0, + "account_status": "ACTIVE", + "account_type": "fixed", + "account_type_bank": "", + "system_account": "", + "value_type": "debit", + "account_code": "710", + "account_currency": "AUD", + "account_identifier": "2d69b4ee-37d4-4f67-b950-32cbdd5765ed" + }, + { + "account_currency": "AUD", + "account_identifier": "24d010bf-5e4b-42dd-9aa3-a5484dd0686f", + "account_name": "Less Accumulated Depreciation on Office Equipment", + "account_type": "fixed", + "account_type_bank": "", + "account_category": "assets", + "account_status": "ACTIVE", + "system_account": "", + "value_type": "credit", + "total_value": 825.0, + "account_code": "711" + }, + { + "account_type": "current_accounts_payable", + "system_account": "CREDITORS", + "value_type": "credit", + "account_category": "liability", + "account_code": "800", + "account_identifier": "8e9c5166-d3fe-4e21-827a-f42753568e80", + "account_name": "Accounts Payable", + "account_status": "ACTIVE", + "account_currency": "AUD", + "account_type_bank": "", + "total_value": 3434.06 + }, + { + "account_category": "liability", + "account_identifier": "66e60a82-99d8-47d1-956b-5baea404acba", + "account_status": "ACTIVE", + "account_type_bank": "", + "system_account": "GST", + "total_value": 2245.99, + "account_code": "820", + "account_currency": "AUD", + "account_name": "GST", + "account_type": "tax", + "value_type": "credit" + }, + { + "account_code": "840", + "account_currency": "AUD", + "account_name": "Historical Adjustment", + "account_status": "ACTIVE", + "total_value": 19212.21, + "value_type": "credit", + "account_category": "liability", + "account_identifier": "305b05b3-01f3-4f47-a45d-edfa66ea03e7", + "account_type": "current", + "account_type_bank": "", + "system_account": "HISTORICAL" + }, + { + "account_name": "PAYG Withholdings Payable", + "account_status": "ACTIVE", + "account_type_bank": "", + "system_account": "", + "value_type": "credit", + "total_value": 6028.0, + "account_category": "liability", + "account_code": "825", + "account_currency": "AUD", + "account_identifier": "4d111d55-1c71-46b4-8cbc-d8b54d8d54c5", + "account_type": "payroll" + }, + { + "account_category": "liability", + "account_type": "current", + "value_type": "credit", + "system_account": "UNPAIDEXPCLM", + "total_value": 0.0, + "account_code": "801", + "account_currency": "AUD", + "account_identifier": "c11b84a9-e90a-4094-83d7-b8494d195ecc", + "account_name": "Unpaid Expense Claims", + "account_status": "ACTIVE", + "account_type_bank": "" + } + ], + "currency": "AUD", + "object_origin_type": "accounting", + "object_origin_category": "bookkeeping", + "object_type": "day", + "object_class": "timeline-balance", + "balance_date": "2020-09-30T00:00:00.000Z" +} \ No newline at end of file diff --git a/data/test_no_liabilities.json b/data/test_no_liabilities.json new file mode 100644 index 00000000..2e99f547 --- /dev/null +++ b/data/test_no_liabilities.json @@ -0,0 +1,276 @@ +{ + "object_category": "general-ledger", + "connection_id": "69260737-4c37-4f28-a9dc-270473a6d84a", + "user": "b0c9fe7c-915e-45e4-8e9e-49d4f27281a5", + "object_creation_date": "2020-10-30T01:58:16.723Z", + "data": [ + { + "account_category": "revenue", + "account_code": "200", + "account_currency": "AUD", + "account_identifier": "e2bacdc6-2006-43c2-a5da-3c0e5f43b452", + "account_status": "ACTIVE", + "value_type": "credit", + "account_name": "Sales", + "account_type": "sales", + "account_type_bank": "", + "system_account": "", + "total_value": 32431.0 + }, + { + "account_code": "400", + "account_currency": "AUD", + "account_identifier": "d392fe47-c99d-499e-a200-46709dd6b6e7", + "account_name": "Advertising", + "account_status": "ACTIVE", + "system_account": "", + "value_type": "debit", + "account_category": "expense", + "account_type_bank": "", + "total_value": 1830.18, + "account_type": "overheads" + }, + { + "account_currency": "AUD", + "account_identifier": "959af5f4-9925-44e8-b283-7ddf4b427238", + "account_status": "ACTIVE", + "value_type": "debit", + "system_account": "", + "total_value": 31.5, + "account_category": "expense", + "account_code": "404", + "account_name": "Bank Fees", + "account_type": "overheads", + "account_type_bank": "" + }, + { + "account_type_bank": "", + "value_type": "debit", + "total_value": 310.0, + "account_name": "Cleaning", + "account_type": "overheads", + "account_currency": "AUD", + "account_identifier": "ff09eac3-5b17-44fb-9eea-e2e9375e91b4", + "account_status": "ACTIVE", + "system_account": "", + "account_category": "expense", + "account_code": "408" + }, + { + "account_status": "ACTIVE", + "system_account": "", + "total_value": 49.0, + "account_category": "expense", + "account_code": "412", + "account_currency": "AUD", + "account_identifier": "6db51cfa-0326-4e63-a743-c78c4d99aba4", + "account_name": "Consulting & Accounting", + "account_type": "overheads", + "account_type_bank": "", + "value_type": "debit" + }, + { + "system_account": "", + "value_type": "debit", + "total_value": 477.2, + "account_status": "ACTIVE", + "account_type": "overheads", + "account_type_bank": "", + "account_category": "expense", + "account_code": "420", + "account_currency": "AUD", + "account_identifier": "18e27517-81e0-437c-bc21-fbba8e30d6bb", + "account_name": "Entertainment" + }, + { + "account_code": "429", + "account_currency": "AUD", + "account_status": "ACTIVE", + "account_type": "overheads", + "account_type_bank": "", + "account_category": "expense", + "account_identifier": "94882296-5acf-4350-8c5b-82bc9370ab78", + "account_name": "General Expenses", + "system_account": "", + "value_type": "debit", + "total_value": 966.87 + }, + { + "account_currency": "AUD", + "account_name": "Light, Power, Heating", + "account_status": "ACTIVE", + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "account_category": "expense", + "account_code": "445", + "account_identifier": "42a56c1a-6141-4bf2-913d-916dc1a35cfd", + "account_type_bank": "", + "total_value": 645.0 + }, + { + "account_currency": "AUD", + "account_type": "overheads", + "account_type_bank": "", + "system_account": "", + "account_category": "expense", + "account_code": "449", + "account_identifier": "005f380d-4a9c-497f-b9d7-817f0f02790e", + "account_name": "Motor Vehicle Expenses", + "account_status": "ACTIVE", + "value_type": "debit", + "total_value": 310.91 + }, + { + "account_code": "453", + "account_currency": "AUD", + "account_identifier": "8ab9d684-f897-4168-b5d1-2279bf74bb82", + "account_status": "ACTIVE", + "account_type": "overheads", + "account_type_bank": "", + "value_type": "debit", + "account_category": "expense", + "account_name": "Office Expenses", + "system_account": "", + "total_value": 1295.99 + }, + { + "account_code": "461", + "account_currency": "AUD", + "account_type_bank": "", + "account_status": "ACTIVE", + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "total_value": 160.54, + "account_category": "expense", + "account_identifier": "b18eaea6-4d11-462c-ac30-7975108b5859", + "account_name": "Printing & Stationery" + }, + { + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "account_currency": "AUD", + "account_code": "469", + "account_identifier": "f5f05ee3-f9cd-4bf9-9423-ed81de96b537", + "account_name": "Rent", + "account_status": "ACTIVE", + "account_type_bank": "", + "total_value": 3000.0, + "account_category": "expense" + }, + { + "account_type": "overheads", + "account_type_bank": "", + "system_account": "", + "value_type": "debit", + "total_value": 190.35, + "account_currency": "AUD", + "account_name": "Telephone & Internet", + "account_identifier": "266f40cc-5aa1-4f6c-b078-eb615171d6de", + "account_status": "ACTIVE", + "account_category": "expense", + "account_code": "489" + }, + { + "account_category": "expense", + "account_code": "493", + "account_currency": "AUD", + "account_name": "Travel - National", + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "total_value": 462.14, + "account_identifier": "25717024-5b50-4320-93b7-280c0614a613", + "account_status": "ACTIVE", + "account_type_bank": "" + }, + { + "account_category": "expense", + "account_code": "477", + "account_currency": "AUD", + "account_type_bank": "", + "system_account": "", + "total_value": 26800.0, + "account_identifier": "c4f12f09-846e-4f6f-b39c-dff3be3e49a7", + "account_name": "Wages and Salaries", + "account_status": "ACTIVE", + "account_type": "overheads", + "value_type": "debit" + }, + { + "account_category": "assets", + "account_code": "610", + "account_type": "current_accounts_receivable", + "account_type_bank": "", + "account_currency": "AUD", + "account_identifier": "3dd5c80d-e109-4313-8c61-41648e33704f", + "account_name": "Accounts Receivable", + "account_status": "ACTIVE", + "system_account": "DEBTORS", + "value_type": "debit", + "total_value": 10749.5 + }, + { + "system_account": "", + "account_code": "090", + "account_currency": "AUD", + "account_identifier": "13918178-849a-4823-9a31-57b7eac713d7", + "account_status": "ACTIVE", + "account_type": "bank", + "account_category": "assets", + "account_name": "Business Bank Account", + "account_type_bank": "BANK", + "value_type": "debit", + "total_value": 1065.85 + }, + { + "system_account": "", + "value_type": "debit", + "account_category": "assets", + "account_code": "091", + "account_currency": "AUD", + "account_status": "ACTIVE", + "account_type_bank": "BANK", + "account_identifier": "26028d3a-f981-44d6-a9ed-a522198870f8", + "account_name": "Business Savings Account", + "account_type": "bank", + "total_value": 15081.23 + }, + { + "account_category": "assets", + "account_name": "Office Equipment", + "total_value": 750.0, + "account_status": "ACTIVE", + "account_type": "fixed", + "account_type_bank": "", + "system_account": "", + "value_type": "debit", + "account_code": "710", + "account_currency": "AUD", + "account_identifier": "2d69b4ee-37d4-4f67-b950-32cbdd5765ed" + }, + { + "account_currency": "AUD", + "account_identifier": "24d010bf-5e4b-42dd-9aa3-a5484dd0686f", + "account_name": "Less Accumulated Depreciation on Office Equipment", + "account_type": "fixed", + "account_type_bank": "", + "account_category": "assets", + "account_status": "ACTIVE", + "system_account": "", + "value_type": "credit", + "total_value": 825.0, + "account_code": "711" + } + + + ], + "currency": "AUD", + "object_origin_type": "accounting", + "object_origin_category": "bookkeeping", + "object_type": "day", + "object_class": "timeline-balance", + "balance_date": "2020-09-30T00:00:00.000Z" +} \ No newline at end of file diff --git a/data/test_no_revenue.json b/data/test_no_revenue.json new file mode 100644 index 00000000..77273fb5 --- /dev/null +++ b/data/test_no_revenue.json @@ -0,0 +1,326 @@ +{ + "object_category": "general-ledger", + "connection_id": "69260737-4c37-4f28-a9dc-270473a6d84a", + "user": "b0c9fe7c-915e-45e4-8e9e-49d4f27281a5", + "object_creation_date": "2020-10-30T01:58:16.723Z", + "data": [ + { + "account_code": "400", + "account_currency": "AUD", + "account_identifier": "d392fe47-c99d-499e-a200-46709dd6b6e7", + "account_name": "Advertising", + "account_status": "ACTIVE", + "system_account": "", + "value_type": "debit", + "account_category": "expense", + "account_type_bank": "", + "total_value": 1830.18, + "account_type": "overheads" + }, + { + "account_currency": "AUD", + "account_identifier": "959af5f4-9925-44e8-b283-7ddf4b427238", + "account_status": "ACTIVE", + "value_type": "debit", + "system_account": "", + "total_value": 31.5, + "account_category": "expense", + "account_code": "404", + "account_name": "Bank Fees", + "account_type": "overheads", + "account_type_bank": "" + }, + { + "account_type_bank": "", + "value_type": "debit", + "total_value": 310.0, + "account_name": "Cleaning", + "account_type": "overheads", + "account_currency": "AUD", + "account_identifier": "ff09eac3-5b17-44fb-9eea-e2e9375e91b4", + "account_status": "ACTIVE", + "system_account": "", + "account_category": "expense", + "account_code": "408" + }, + { + "account_status": "ACTIVE", + "system_account": "", + "total_value": 49.0, + "account_category": "expense", + "account_code": "412", + "account_currency": "AUD", + "account_identifier": "6db51cfa-0326-4e63-a743-c78c4d99aba4", + "account_name": "Consulting & Accounting", + "account_type": "overheads", + "account_type_bank": "", + "value_type": "debit" + }, + { + "system_account": "", + "value_type": "debit", + "total_value": 477.2, + "account_status": "ACTIVE", + "account_type": "overheads", + "account_type_bank": "", + "account_category": "expense", + "account_code": "420", + "account_currency": "AUD", + "account_identifier": "18e27517-81e0-437c-bc21-fbba8e30d6bb", + "account_name": "Entertainment" + }, + { + "account_code": "429", + "account_currency": "AUD", + "account_status": "ACTIVE", + "account_type": "overheads", + "account_type_bank": "", + "account_category": "expense", + "account_identifier": "94882296-5acf-4350-8c5b-82bc9370ab78", + "account_name": "General Expenses", + "system_account": "", + "value_type": "debit", + "total_value": 966.87 + }, + { + "account_currency": "AUD", + "account_name": "Light, Power, Heating", + "account_status": "ACTIVE", + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "account_category": "expense", + "account_code": "445", + "account_identifier": "42a56c1a-6141-4bf2-913d-916dc1a35cfd", + "account_type_bank": "", + "total_value": 645.0 + }, + { + "account_currency": "AUD", + "account_type": "overheads", + "account_type_bank": "", + "system_account": "", + "account_category": "expense", + "account_code": "449", + "account_identifier": "005f380d-4a9c-497f-b9d7-817f0f02790e", + "account_name": "Motor Vehicle Expenses", + "account_status": "ACTIVE", + "value_type": "debit", + "total_value": 310.91 + }, + { + "account_code": "453", + "account_currency": "AUD", + "account_identifier": "8ab9d684-f897-4168-b5d1-2279bf74bb82", + "account_status": "ACTIVE", + "account_type": "overheads", + "account_type_bank": "", + "value_type": "debit", + "account_category": "expense", + "account_name": "Office Expenses", + "system_account": "", + "total_value": 1295.99 + }, + { + "account_code": "461", + "account_currency": "AUD", + "account_type_bank": "", + "account_status": "ACTIVE", + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "total_value": 160.54, + "account_category": "expense", + "account_identifier": "b18eaea6-4d11-462c-ac30-7975108b5859", + "account_name": "Printing & Stationery" + }, + { + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "account_currency": "AUD", + "account_code": "469", + "account_identifier": "f5f05ee3-f9cd-4bf9-9423-ed81de96b537", + "account_name": "Rent", + "account_status": "ACTIVE", + "account_type_bank": "", + "total_value": 3000.0, + "account_category": "expense" + }, + { + "account_type": "overheads", + "account_type_bank": "", + "system_account": "", + "value_type": "debit", + "total_value": 190.35, + "account_currency": "AUD", + "account_name": "Telephone & Internet", + "account_identifier": "266f40cc-5aa1-4f6c-b078-eb615171d6de", + "account_status": "ACTIVE", + "account_category": "expense", + "account_code": "489" + }, + { + "account_category": "expense", + "account_code": "493", + "account_currency": "AUD", + "account_name": "Travel - National", + "account_type": "overheads", + "system_account": "", + "value_type": "debit", + "total_value": 462.14, + "account_identifier": "25717024-5b50-4320-93b7-280c0614a613", + "account_status": "ACTIVE", + "account_type_bank": "" + }, + { + "account_category": "expense", + "account_code": "477", + "account_currency": "AUD", + "account_type_bank": "", + "system_account": "", + "total_value": 26800.0, + "account_identifier": "c4f12f09-846e-4f6f-b39c-dff3be3e49a7", + "account_name": "Wages and Salaries", + "account_status": "ACTIVE", + "account_type": "overheads", + "value_type": "debit" + }, + { + "account_category": "assets", + "account_code": "610", + "account_type": "current_accounts_receivable", + "account_type_bank": "", + "account_currency": "AUD", + "account_identifier": "3dd5c80d-e109-4313-8c61-41648e33704f", + "account_name": "Accounts Receivable", + "account_status": "ACTIVE", + "system_account": "DEBTORS", + "value_type": "debit", + "total_value": 10749.5 + }, + { + "system_account": "", + "account_code": "090", + "account_currency": "AUD", + "account_identifier": "13918178-849a-4823-9a31-57b7eac713d7", + "account_status": "ACTIVE", + "account_type": "bank", + "account_category": "assets", + "account_name": "Business Bank Account", + "account_type_bank": "BANK", + "value_type": "debit", + "total_value": 1065.85 + }, + { + "system_account": "", + "value_type": "debit", + "account_category": "assets", + "account_code": "091", + "account_currency": "AUD", + "account_status": "ACTIVE", + "account_type_bank": "BANK", + "account_identifier": "26028d3a-f981-44d6-a9ed-a522198870f8", + "account_name": "Business Savings Account", + "account_type": "bank", + "total_value": 15081.23 + }, + { + "account_category": "assets", + "account_name": "Office Equipment", + "total_value": 750.0, + "account_status": "ACTIVE", + "account_type": "fixed", + "account_type_bank": "", + "system_account": "", + "value_type": "debit", + "account_code": "710", + "account_currency": "AUD", + "account_identifier": "2d69b4ee-37d4-4f67-b950-32cbdd5765ed" + }, + { + "account_currency": "AUD", + "account_identifier": "24d010bf-5e4b-42dd-9aa3-a5484dd0686f", + "account_name": "Less Accumulated Depreciation on Office Equipment", + "account_type": "fixed", + "account_type_bank": "", + "account_category": "assets", + "account_status": "ACTIVE", + "system_account": "", + "value_type": "credit", + "total_value": 825.0, + "account_code": "711" + }, + { + "account_type": "current_accounts_payable", + "system_account": "CREDITORS", + "value_type": "credit", + "account_category": "liability", + "account_code": "800", + "account_identifier": "8e9c5166-d3fe-4e21-827a-f42753568e80", + "account_name": "Accounts Payable", + "account_status": "ACTIVE", + "account_currency": "AUD", + "account_type_bank": "", + "total_value": 3434.06 + }, + { + "account_category": "liability", + "account_identifier": "66e60a82-99d8-47d1-956b-5baea404acba", + "account_status": "ACTIVE", + "account_type_bank": "", + "system_account": "GST", + "total_value": 2245.99, + "account_code": "820", + "account_currency": "AUD", + "account_name": "GST", + "account_type": "tax", + "value_type": "credit" + }, + { + "account_code": "840", + "account_currency": "AUD", + "account_name": "Historical Adjustment", + "account_status": "ACTIVE", + "total_value": 19212.21, + "value_type": "credit", + "account_category": "liability", + "account_identifier": "305b05b3-01f3-4f47-a45d-edfa66ea03e7", + "account_type": "current", + "account_type_bank": "", + "system_account": "HISTORICAL" + }, + { + "account_name": "PAYG Withholdings Payable", + "account_status": "ACTIVE", + "account_type_bank": "", + "system_account": "", + "value_type": "credit", + "total_value": 6028.0, + "account_category": "liability", + "account_code": "825", + "account_currency": "AUD", + "account_identifier": "4d111d55-1c71-46b4-8cbc-d8b54d8d54c5", + "account_type": "payroll" + }, + { + "account_category": "liability", + "account_type": "current", + "value_type": "credit", + "system_account": "UNPAIDEXPCLM", + "total_value": 0.0, + "account_code": "801", + "account_currency": "AUD", + "account_identifier": "c11b84a9-e90a-4094-83d7-b8494d195ecc", + "account_name": "Unpaid Expense Claims", + "account_status": "ACTIVE", + "account_type_bank": "" + } + ], + "currency": "AUD", + "object_origin_type": "accounting", + "object_origin_category": "bookkeeping", + "object_type": "day", + "object_class": "timeline-balance", + "balance_date": "2020-09-30T00:00:00.000Z" +} \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..0bdae0d0 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module challenging + +go 1.18 + +require golang.org/x/text v0.3.7 diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..1f78e039 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= diff --git a/main.go b/main.go new file mode 100644 index 00000000..8534368a --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "challenging/service" + +func main() { + service.LoadFile() +} diff --git a/service/challenge.go b/service/challenge.go new file mode 100644 index 00000000..7a2bb008 --- /dev/null +++ b/service/challenge.go @@ -0,0 +1,94 @@ +package service + +import ( + "encoding/json" + "fmt" + "golang.org/x/text/language" + "golang.org/x/text/message" + "io/ioutil" + "os" +) + +//Generate Golang Struct to map json entity +type BookKeeping struct { + BalanceDate string `json:"balance_date"` + ConnectionID string `json:"connection_id"` + Currency string `json:"currency"` + Data []struct { + AccountCategory string `json:"account_category"` + AccountCode string `json:"account_code"` + AccountCurrency string `json:"account_currency"` + AccountIdentifier string `json:"account_identifier"` + AccountName string `json:"account_name"` + AccountStatus string `json:"account_status"` + AccountType string `json:"account_type"` + AccountTypeBank string `json:"account_type_bank"` + SystemAccount string `json:"system_account"` + TotalValue float64 `json:"total_value"` + ValueType string `json:"value_type"` + } `json:"data"` + ObjectCategory string `json:"object_category"` + ObjectClass string `json:"object_class"` + ObjectCreationDate string `json:"object_creation_date"` + ObjectOriginCategory string `json:"object_origin_category"` + ObjectOriginType string `json:"object_origin_type"` + ObjectType string `json:"object_type"` + User string `json:"user"` +} + +func LoadFile() { + + jsonFile, err := os.Open("./data/data.json") + if err != nil { + fmt.Println(err) + } + defer jsonFile.Close() + byteValue, _ := ioutil.ReadAll(jsonFile) + var books BookKeeping + + json.Unmarshal(byteValue, &books) + + var revenue, expense float64 + var grossProfitMarginTotal float64 + var workingCapitalRatio, liabilities float64 + + for _, record := range books.Data { + if record.AccountCategory == "revenue" { + revenue = revenue + record.TotalValue + } + if record.AccountCategory == "expense" { + expense = expense + record.TotalValue + } + if record.AccountType == "sales" && record.ValueType == "debit" { + grossProfitMarginTotal = grossProfitMarginTotal + record.TotalValue + } + + if record.AccountCategory == "assets" && + (record.AccountType == "current" || record.AccountType == "bank" || record.AccountType == "current_accounts_receivable") { + if record.ValueType == "debit" { + workingCapitalRatio = workingCapitalRatio + record.TotalValue + } + if record.ValueType == "credit" { + workingCapitalRatio = workingCapitalRatio - record.TotalValue + } + } + + if record.AccountCategory == "liability" && + (record.AccountType == "current" || record.AccountType == "current_accounts_payable") { + if record.ValueType == "debit" { + liabilities = liabilities - record.TotalValue + } + if record.ValueType == "credit" { + liabilities = liabilities + record.TotalValue + } + } + } + p := message.NewPrinter(language.English) + fmt.Printf(p.Sprintf("Revenue: $%.0f\n", revenue)) + fmt.Printf(p.Sprintf("Revenue: $%.0f\n", expense)) + grossProfitMargin := grossProfitMarginTotal / revenue + netProfitMargin := (revenue - expense) / revenue + fmt.Printf("Gross Profit Margin:%.0f%%\n", grossProfitMargin*100) + fmt.Printf("Net Profit Margin:%.0f%%\n", netProfitMargin*100) + fmt.Printf("Working Capital Ratio:%.0f%%", workingCapitalRatio/liabilities*100) +}