{"id":20254788,"url":"https://github.com/chippyash/go-simple-accounts","last_synced_at":"2026-05-12T06:33:07.619Z","repository":{"id":56854699,"uuid":"522475829","full_name":"chippyash/go-simple-accounts","owner":"chippyash","description":"Provides a Go client for the [Simple Accounts](https://github.com/chippyash/simple-accounts-3) system","archived":false,"fork":false,"pushed_at":"2022-11-01T15:01:23.000Z","size":53,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-14T03:34:03.993Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chippyash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-08T09:01:08.000Z","updated_at":"2022-08-08T09:03:40.000Z","dependencies_parsed_at":"2023-01-21T05:01:31.994Z","dependency_job_id":null,"html_url":"https://github.com/chippyash/go-simple-accounts","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2Fgo-simple-accounts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2Fgo-simple-accounts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2Fgo-simple-accounts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2Fgo-simple-accounts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chippyash","download_url":"https://codeload.github.com/chippyash/go-simple-accounts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241705908,"owners_count":20006398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T10:34:55.442Z","updated_at":"2026-05-12T06:33:07.567Z","avatar_url":"https://github.com/chippyash.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chippyash Simple Accounts Client for Go\n## github.com/chippyash/go-simple-accounts\n\nGo: 1.18\n\n## What\nProvides a Go client for the [Simple Accounts](https://github.com/chippyash/simple-accounts-3) system.\nPlease refer to that repository for full details.\n\n## How\nAll the notes and remarks from the original PHP client hold true for the Go client except where noted.\n\n#### Create an Accountant\n```go\nimport (\n\t\"database/sql\"\n\t\"github.com/chippyash/go-simple-accounts/sa\"\n\t\"github.com/go-sql-driver/mysql\"\n)\nconfig := mysql.Config{\n    User:                 os.Getenv(\"DBUID\"),\n    Passwd:               os.Getenv(\"DBPWD\"),\n    DBName:               os.Getenv(\"DBNAME\"),\n    AllowNativePasswords: true,\n    ParseTime:            true,\n}\ndba, err := sql.Open(\"mysql\", config.FormatDSN())\nif err != nil {\n\tpanic(err)\n}\n\naccountant = sa.NewAccountant(dba, 0, \"GBP\")\n```\nThe Go Accountant has an additional parameter, a 3 character currency code. This is held in the Accountant struct for reference\nonly and is not stored in the database.\n\n#### Create a new Chart\n```go\ndef, err := sa.NewChartDefinition(\"../tests/_data/personal.xml\")\nif err != nil {\n    panic(err)\n}\nlastId, err := accountant.CreateChart(\"Test\", \"GBP\", def)\nif err != nil {\n    panic(err)\n}\n\n```\n\nYou can alternatively set the chart definition from a string:\n```go\nxml := `some xml string`\ndef := sa.NewChartDefinitionFromString(xml)\n```\n\n#### Fetch an existing Chart\n```go\n//You will have previously saved your chart id somewhere for later retrieval\naccountant := sa.NewAccountant(db, chartId, \"GBP\")\nchart, err := accountant.FetchChart()\nif err != nil {\n    panic(err)\n}\n```\n\n#### Adding an Account ledger to the COA\n```go\nnom, _ := sa.NewNominal(\"1111\")\nprnt, _ := sa.NewNominal(\"0000\")\nerr := accountant.AddAccount(nom, sa.NewAcType().Asset(), \"foo\", \u0026prnt)\nif err != nil {\n    panic(err)\n}\n```\n\n#### Deleting an Account ledger from the COA\n```go\nnom, _ := sa.NewNominal(\"0001\")\nerr := accountant.DelAccount(nom)\nif err != nil {\n    panic(err)\n}\n```\n\n#### Operations on a Chart\n##### Get an account\n```go\naccount := chart.GetAccount(sa.MustNewNominal(\"1000\"))\naccount = chart.GetAccountByName(\"Liability\")\n```\n\n##### Get account parent\n```go\nnominal := chart.GetParentId(sa.MustNewNominal(\"1000\"))\naccount := chart.GetAccount(chart.GetParentId(sa.MustNewNominal(\"1000\")))\n```\n\n##### Testing if an account exists\n```go\nexists := chart.HasAccount(sa.MustNewNominal(\"1000\"))\n```\n\n##### Get the name of the Chart\n```go\nname := chart.Name()\n```\n\n##### Get the currency of the Chart\n```go\ncrcy := chart.Crcy()\n```\n\n##### Get a ledger account's values\n```go\naccount := chart.GetAccount(sa.MustNewNominal(\"1000\"))\ndr := account.Dr()\ncr := account.Cr()\nbalance, err := account.Balance()\nname := account.Name()\nacType := account.Type()\n```\n\n#### The COA as a Tree\nUnder the covers, the chart is kept as a [Hierarchy Tree](https://github.com/chippyash/go-hierarchy-tree).  You can\nretrieve the tree:\n```go\nchartTree := chart.Tree() //returns tree.NodeIFace\n```\n\n#### Transaction Entries\n##### Creating Entries\nTwo transaction builders are provided:\n- SplitTransactionBuilder\n- SimpleTransactionBuilder\n\nBy default both will build the transaction with the date set to now() and default values\nfor source, reference and note (i.e. empty values). Both builders support `With...` methods\nto set the additional information, e.g.:\n```go\ntxn := sa.NewSplitTransactionBuilder(0).\n    WithDate(dt).\n    WithNote(\"foo\").\n    WithReference(1).\n    WithSource(\"src\").\n    Build()\n```\n\n###### Split Transaction\n```go\ntxn := sa.NewSplitTransactionBuilder(0).\n\tWithEntries(\n        sa.NewEntry(sa.MustNewNominal(\"1000\"), 100, *sa.NewAcType().Dr()),\n        sa.NewEntry(sa.MustNewNominal(\"2000\"), 100, *sa.NewAcType().Cr()),\n        sa.NewEntry(sa.MustNewNominal(\"3000\"), 100, *sa.NewAcType().Dr()),\n        sa.NewEntry(sa.MustNewNominal(\"4000\"), 100, *sa.NewAcType().Cr()),\t\t\n\t).\n\tBuild()\n\ntxn := sa.NewSplitTransactionBuilder(0).\n\tWithEntry(*sa.NewEntry(sa.MustNewNominal(\"1000\"), 100, *sa.NewAcType().Dr())).\n\tWithEntry(*sa.NewEntry(sa.MustNewNominal(\"2000\"), 100, *sa.NewAcType().Cr())).\n\tBuild()\n```\n\nWhen creating new transactions, set the id == 0\n\n###### Simple Transaction\n```go\ntxn := sa.NewSimpleTransactionBuilder(0, sa.MustNewNominal(\"1000\"), sa.MustNewNominal(\"2000\"), 100).\n    Build()\n```\n\nNB. A simple transaction is a split transaction with 2 entries\n\n##### Transaction information\n```go\namt, err := txn.GetAmount() //sum(dr + cr) / 2\nnoms := txn.GetDrAc()  //[]*Nominals\nnoms := txn.GetCrAc()  //[]*Nominals\nsimple := txn.IsSimple()  //true if simple else false\nbalanced := txn.CheckBalance() //true if transaction is balanced else false\n```\n\n##### Writing transactions\n```go\ntxnId := accountant.WriteTransactionWithDate(txn, dt)\ntxnId := accountant.WriteTransaction(txn) //default date to now()  \n```\n\n##### Fetching transactions\n```go\ntxn, err := accountant.FetchTransaction(txnId)\nentries, err := accountant.FetchAccountJournals(\"0001\")\n```\n\n### For Development\n#### Setup\n\n- clone repository\n- cd to project directory\n- `go get ./...`\n\n##### Database\nSee [Simple Accounts Readme](https://github.com/chippyash/simple-accounts-3/blob/master/README.md) for instructions to build your database.\n\nSupport for [Golang Migrate](https://github.com/golang-migrate/migrate) is provided with migration files for the MySql Db variant\nin `./db/migrations`. You will need to install golang-migrate.\n\n`go install -tags 'mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest`\n\nFull install instruction for [go-migrate](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate)\n\n- create a database `sa_accounts`\n- run the migration\n\n`migrate -path ./db/migrations -database \"mysql://\u003cdbuid\u003e:\u003cdbpwd\u003e@tcp(localhost:3306)/sa_accounts?multiStatements=true\" up`\n\nreplacing `\u003cdbuid\u003e` and `\u003cdbpwd\u003e` with your root user name and password.\n\nWhilst for development, you certainly can continue to use the root user credentials, it is considered bad practice and\nyou should create a user that has access only to sa_accounts.\n\nIf you want to destroy the database content, just use the above command with `down` instead of `up`.\n\n\n#### Testing\n_To run unit tests:_\n\n`go test --tags=unit ./...`\n\n_To run integration tests:_\n\n- Integration tests require a MySql/MariaDb database server running and the simple accounts database set up\n\n`DBUID=\u003cuid\u003e DBPWD=\u003cpwd\u003e DBNAME=\u003cdbname\u003e go test --tags=integration ./...`\n\nreplacing `\u003cuid\u003e`, `\u003cpwd\u003e` and `\u003cdbname\u003e` with your credentials\n\nIntegration tests will run the unit tests as well\n\n\n#### Before you do a PR\n\n- update the readme if required\n- add new tests for your new/changed code\n- run the tests\n\n## References\n\n- [Github](https://github.com/chippyash/go-simple-accounts)\n- [PHP Version of Simple Accounts](https://github.com/chippyash/simple-accounts-3)\n- [Go Hierarchy Tree used by this library](https://github.com/chippyash/go-hierarchy-tree)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchippyash%2Fgo-simple-accounts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchippyash%2Fgo-simple-accounts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchippyash%2Fgo-simple-accounts/lists"}