This commit is contained in:
@@ -2,16 +2,22 @@ package cli
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"os/signal"
|
||||
"slices"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"gogs.inhome.blapointe.com/ana-ledger/src/ana"
|
||||
"gogs.inhome.blapointe.com/ana-ledger/src/bank"
|
||||
"gogs.inhome.blapointe.com/ana-ledger/src/bank/cache"
|
||||
"gogs.inhome.blapointe.com/ana-ledger/src/bank/teller"
|
||||
"gogs.inhome.blapointe.com/ana-ledger/src/ledger"
|
||||
|
||||
"github.com/guptarohit/asciigraph"
|
||||
@@ -219,6 +225,60 @@ func Main() {
|
||||
options = append(options, asciigraph.SeriesColors(seriesColors...))
|
||||
}
|
||||
fmt.Println(asciigraph.PlotMany(points, options...))
|
||||
case "rec":
|
||||
byDate := map[string]ledger.Deltas{}
|
||||
for _, delta := range deltas {
|
||||
delta := delta
|
||||
byDate[delta.Date] = append(byDate[delta.Date], delta)
|
||||
}
|
||||
|
||||
ctx, can := signal.NotifyContext(context.Background(), syscall.SIGINT)
|
||||
defer can()
|
||||
|
||||
teller, err := teller.New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := cache.New(teller)
|
||||
|
||||
accounts, err := client.Accounts(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
inDay := func(date string, transaction bank.Transaction) bool {
|
||||
return slices.ContainsFunc(byDate[date], func(d ledger.Delta) bool {
|
||||
return d.Value == transaction.Amount
|
||||
})
|
||||
}
|
||||
|
||||
for _, acc := range accounts {
|
||||
transactions, err := client.Transactions(ctx, acc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, transaction := range transactions {
|
||||
if inDay(transaction.Date, transaction) {
|
||||
continue
|
||||
}
|
||||
|
||||
err := "missing"
|
||||
|
||||
t, _ := time.ParseInLocation(transaction.Date, "2006-01-02", time.Local)
|
||||
dayBefore := t.Add(-24 * time.Hour).Format("2006-01-02")
|
||||
dayAfter := t.Add(-24 * time.Hour).Format("2006-01-02")
|
||||
if inDay(dayBefore, transaction) || inDay(dayAfter, transaction) {
|
||||
err = "1dayoff"
|
||||
}
|
||||
|
||||
prefix := " "
|
||||
if transaction.Status != "posted" {
|
||||
prefix = "! "
|
||||
}
|
||||
fmt.Printf("[%s] %s $%7.2f %s%s (%s)\n", err, transaction.Date, transaction.Amount, prefix, transaction.Details.CounterParty.Name, transaction.Description)
|
||||
}
|
||||
}
|
||||
case "reg":
|
||||
transactions := deltas.Transactions()
|
||||
cumulative := make(ledger.Balances)
|
||||
|
||||
Reference in New Issue
Block a user