-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use CSV for balance reports + add graphs (#59)
- Loading branch information
1 parent
ca293d1
commit a2c6461
Showing
21 changed files
with
648 additions
and
348 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,43 @@ | ||
{ | ||
"startDate": "2024", | ||
"period": "monthly" | ||
"period": "monthly", | ||
"reports": [ | ||
{ | ||
"name": "assets", | ||
"cmd": "hledger balance type:a" | ||
}, | ||
{ | ||
"name": "expenses", | ||
"cmd": "hledger balance type:x" | ||
}, | ||
{ | ||
"name": "revenue", | ||
"cmd": "hledger balance type:r" | ||
}, | ||
{ | ||
"name": "liabilities", | ||
"cmd": "hledger balance type:l" | ||
}, | ||
{ | ||
"name": "income statement", | ||
"cmd": "hledger incomestatement " | ||
}, | ||
{ | ||
"name": "balance sheet", | ||
"cmd": "hledger balancesheet " | ||
}, | ||
{ | ||
"name": "accounts", | ||
"cmd": "hledger accounts " | ||
}, | ||
{ | ||
"name": "register", | ||
"cmd": "hledger register" | ||
}, | ||
{ | ||
"name": "commodities", | ||
"cmd": "hledger commodities", | ||
"locked": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,60 @@ | ||
package ui | ||
|
||
import ( | ||
"io" | ||
"puffin/accounting" | ||
"fmt" | ||
"log" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/siddhantac/hledger" | ||
) | ||
|
||
func runCommand(cmd string) func(options hledger.Options) string { | ||
return func(options hledger.Options) string { | ||
buf, err := accounting.RunCommand(cmd, options) | ||
if err != nil { | ||
return err.Error() | ||
} | ||
b, err := io.ReadAll(buf) | ||
func runCommand(cmd string) func(id int, options hledger.Options) content { | ||
return func(id int, options hledger.Options) content { | ||
c := content{id: id} | ||
|
||
args := strings.Split(cmd, " ") | ||
|
||
opts := options.Build() | ||
args = append(args, opts...) | ||
log.Printf("cmd: %v", args) | ||
|
||
cmd := exec.Command(args[0], args[1:]...) | ||
result, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return err.Error() | ||
log.Printf("error: %v: %s", err, string(result)) | ||
c.err = fmt.Errorf("%s\n%v", string(result), err) | ||
return c | ||
} | ||
return string(b) | ||
|
||
c.msg = string(result) | ||
return c | ||
} | ||
} | ||
|
||
func detectCommand(id int, report Report, dataTransformers []dataTransformer) ContentModel { | ||
if report.Locked { | ||
pg := newPager(id, report.Name, report.Locked, runCommand(report.Cmd), cmdUnknown) | ||
return newMainView(id, report.Name, pg) | ||
} | ||
|
||
args := strings.Split(report.Cmd, " ") | ||
switch args[1] { | ||
case "balance", "bal": | ||
log.Printf("create tableGraph") | ||
tg := newTableGraph(id, report.Name, report.Locked, runCommand(report.Cmd), cmdBalance, dataTransformers) | ||
return newMainView(id, report.Name, tg) | ||
case "register", "reg": | ||
log.Printf("create table") | ||
tbl := newTable("register", nil, id, runCommand(report.Cmd), report.Locked, cmdRegister, nil) | ||
return newMainView(id, report.Name, tbl) | ||
case "accounts", "acc": | ||
log.Printf("create pager") | ||
pg := newPager(id, report.Name, report.Locked, runCommand(report.Cmd), cmdAccounts) | ||
return newMainView(id, report.Name, pg) | ||
default: | ||
log.Printf("create pager") | ||
pg := newPager(id, report.Name, report.Locked, runCommand(report.Cmd), cmdUnknown) | ||
return newMainView(id, report.Name, pg) | ||
} | ||
} |
Oops, something went wrong.