Skip to content

Commit

Permalink
Merge pull request #20 from mkobetic/coin2html
Browse files Browse the repository at this point in the history
coin2html: graphical viewer for the ledger
  • Loading branch information
mkobetic authored Apr 2, 2024
2 parents 4b38991 + c4fedfc commit e1cb479
Show file tree
Hide file tree
Showing 31 changed files with 58,051 additions and 539 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
bin/
tmp/
node_modules
node_modules
cmd/coin2html/test.html
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"javascript.preferences.importModuleSpecifier": "relative",
"typescript.preferences.importModuleSpecifier": "relative",
"typescript.tsserver.maxTsServerMemory": 8000,
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"javascript.updateImportsOnFileMove.enabled": "always",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true
}
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ LDFLAGS += -X "github.com/mkobetic/coin.GoVersion=$(GO_VERSION)"
BUILD := CGO_ENABLED=0 go install
TEST := CGO_ENABLED=0 go test

build: coin gc2coin ofx2coin csv2coin gen2coin
build: coin gc2coin ofx2coin csv2coin gen2coin coin2html

cmd/coin/charts.go: cmd/coin/charts/*.js cmd/coin/charts/*.css
go generate ./cmd/coin

coin: *.go cmd/coin/*.go cmd/coin/charts.go
coin: *.go cmd/coin/*.go
$(BUILD) -ldflags '$(LDFLAGS)' ./cmd/coin

gc2coin: *.go cmd/gc2coin/*.go
Expand All @@ -32,6 +29,14 @@ csv2coin: *.go cmd/csv2coin/*.go
gen2coin: *.go cmd/gen2coin/*.go
$(BUILD) -ldflags '$(LDFLAGS)' ./cmd/gen2coin

coin2html: *.go cmd/coin2html/*.go cmd/coin2html/js/src/*.ts cmd/coin2html/js/*.html
go generate ./cmd/coin2html
$(BUILD) -ldflags '$(LDFLAGS)' ./cmd/coin2html

examples/yearly/viewer.html: export COINDB=./examples/yearly
examples/yearly/viewer.html: coin2html
coin2html >$(COINDB)/viewer.html

dfa: dfa.bash
cp ./dfa.bash $(GOPATH1)/bin/

Expand Down Expand Up @@ -60,4 +65,4 @@ browse-coverage:
setup:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

.PHONY: test test-fixtures test-go fmt lint cover browse-coverage
.PHONY: test test-fixtures test-go fmt lint cover browse-coverage
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ csv import, see [`cmd/csv2coin/README.md`](https://github.com/mkobetic/coin/blob

generates ledger samples for testing or demos, see [`cmd/gen2coin/README.md`](https://github.com/mkobetic/coin/blob/master/cmd/gen2coin/README.md)

### coin2html

converts the ledger into a single-page html viewer, see [`cmd/coin2html/README.md`](https://github.com/mkobetic/coin/blob/master/cmd/coin2html/README.md)

## Assorted Ledger Differences
(besides vastly reduced set of commands/options and capabilities)
Expand Down
63 changes: 38 additions & 25 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
### Features

* thousand separator in amounts
* check for account/cc numbers in transactions
* balance: last reconciled posting date
* register: sorting by quantity to aid finding largest transactions
* register: show account balances with begin/end
* stats: check closed accounts have 0 balance
* register: show posting commodity (not just total commodity)
* register: recursive prints transactions within the parent tree twice
* register: recursive totals are useless
* balance: csv, json, chart output
* register/balance: markdown output
* register: more advanced filtering options
* stats: aggregate transaction/price stats by time (-y, -q, -m) and begin/end
- thousand separator in amounts
- check for account/cc numbers in transactions
- balance: last reconciled posting date
- register: sorting by quantity to aid finding largest transactions
- register: show account balances with begin/end
- stats: check closed accounts have 0 balance
- register: show posting commodity (not just total commodity)
- register: recursive prints transactions within the parent tree twice
- register: recursive totals are useless
- balance: csv, json, chart output
- register/balance: markdown output
- register: more advanced filtering options
- stats: aggregate transaction/price stats by time (-y, -q, -m) and begin/end

#### ofx2coin

* duplicate elimination too aggressive with identical transactions (e.g. 2x ROGERS top up for cell phones)
- duplicate elimination too aggressive with identical transactions (e.g. 2x ROGERS top up for cell phones)
? duplicate transactions from the same source/file should be kept?
* sanitize sensitive information, account/cc numbers
* commodity mismatches (USD vs CAD)
* use ofxid for deduping (need tags?)
- sanitize sensitive information, account/cc numbers
- commodity mismatches (USD vs CAD)
- use ofxid for deduping (need tags?)

### coin2html

- tooltips for columns, inputs and wherever useful
- show details of selected posting
- add location info
- show details of selected posting group
- filter subaccounts, payee, tag...
- preserve view selection across root changes
- preserve UI state in history (make back/forward buttons work)
- trim to time range on export (need to recalc posting balances!)
- balance charts
- show commodities and prices

### Issues

* how to match :Acct when there's :XAcct as well?
- how to match :Acct when there's :XAcct as well?

### Maybe

* backfill prices from transactions
* filter out closed accounts where it makes sense (ditch the 0 balance filtering)
* commodity renames?
* language server?
* lots/costs
* multiple commodities in single account?
* query language
- backfill prices from transactions
- filter out closed accounts where it makes sense (ditch the 0 balance filtering)
- commodity renames?
- language server?
- lots/costs
- multiple commodities in single account?
- query language
33 changes: 28 additions & 5 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package coin

import (
"bytes"
"encoding/json"
"fmt"
"io"
"sort"
Expand All @@ -17,8 +18,6 @@ import (
type Account struct {
Name string
FullName string // name with all the ancestors
Type string
Code string
Description string
CommodityId string
Closed time.Time // the date the account was closed
Expand All @@ -33,10 +32,12 @@ type Account struct {
line uint
file string

OFXBankId string
OFXAcctId string

OFXBankId string // obsolete; left here for backward compatibility
OFXAcctId string // obsolete; left here for backward compatibility
CSVAcctId string // obsolete; left here for backward compatibility
Type string // (obsolete) used for gnucash conversion only
Code string // (obsolete) used for gnucash conversion only

}

/*
Expand All @@ -56,6 +57,9 @@ func (a *Account) Write(w io.Writer, ledger bool) error {
lines = append(lines, " note ", a.Description, "\n")
}
lines = append(lines, ` commodity `, a.Commodity.SafeId(ledger), "\n")
if !a.Closed.IsZero() {
lines = append(lines, ` closed `, a.Closed.Format(DateFormat), "\n")
}
if a.OFXBankId != "" && !ledger {
lines = append(lines, ` ofx_bankid `, a.OFXBankId, "\n")
}
Expand Down Expand Up @@ -311,3 +315,22 @@ func min(a, b int) int {
}
return b
}

func (a *Account) MarshalJSON() ([]byte, error) {
value := map[string]interface{}{
"name": a.Name,
"fullName": a.FullName,
"commodity": a.Commodity.Id,
}
if !a.Closed.IsZero() {
value["closed"] = a.Closed.Format(DateFormat)
}
if a.Code != "" {
value["code"] = a.Code
}
if a.Parent != nil {
value["parent"] = a.Parent.FullName

}
return json.MarshalIndent(value, "", "\t")
}
5 changes: 5 additions & 0 deletions amount.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package coin

import (
"encoding/json"
"fmt"
"io"
"math/big"
Expand Down Expand Up @@ -193,3 +194,7 @@ func (a *Amount) Width(decimals int) int {
}
return w
}

func (a *Amount) MarshalJSON() ([]byte, error) {
return json.Marshal(fmt.Sprintf("%.*f %s", a.Commodity.Decimals, a, a.Commodity.Id))
}
5 changes: 0 additions & 5 deletions cmd/coin/charts/README.md

This file was deleted.

68 changes: 0 additions & 68 deletions cmd/coin/charts/embed.go

This file was deleted.

Loading

0 comments on commit e1cb479

Please sign in to comment.