Skip to content

Commit

Permalink
Store firefly zero date transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
satraul committed Nov 22, 2021
1 parent 6af9c18 commit 6e2aef5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
25 changes: 8 additions & 17 deletions firefly.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -19,10 +18,6 @@ const (
reconciliationTimeLayout = "January 2, 2006"
)

var (
errDateIsZero = errors.New("date is zero")
)

func createFireflyTransactions(ctx context.Context, bal bca.Balance, trxs []bca.Entry) error {
ff := gofirefly.NewAPIClient(&gofirefly.APIConfiguration{
DefaultHeader: make(map[string]string),
Expand Down Expand Up @@ -117,13 +112,7 @@ func createFireflyReconciliation(ffBalance decimal.Decimal, accountID string, ba
}

func createFireflyTransaction(trx bca.Entry, account *gofirefly.AccountRead, ff *gofirefly.APIClient, auth context.Context) error {
fftrx, err := toFireflyTrx(trx, account.Id)
if err != nil {
if errors.Is(err, errDateIsZero) {
return nil
}
return err
}
fftrx := toFireflyTrx(trx, account.Id)

return storeTransaction(ff, auth, fftrx)
}
Expand Down Expand Up @@ -177,14 +166,16 @@ func toFireflyReconciliationTrx(ffBalance decimal.Decimal, bal bca.Balance, acco
return fftrx
}

func toFireflyTrx(trx bca.Entry, accountID string) (gofirefly.TransactionSplitStore, error) {
func toFireflyTrx(trx bca.Entry, accountID string) gofirefly.TransactionSplitStore {
fftrx := gofirefly.TransactionSplitStore{}
fftrx.Amount = trx.Amount.String()

if trx.Date.IsZero() {
return gofirefly.TransactionSplitStore{}, errDateIsZero
switch {
case trx.Date.IsZero():
fftrx.Date = time.Now()
default:
fftrx.Date = trx.Date
}
fftrx.Date = trx.Date

switch trx.Type {
case "DB":
Expand All @@ -204,7 +195,7 @@ func toFireflyTrx(trx bca.Entry, accountID string) (gofirefly.TransactionSplitSt
fftrx.Description = trx.Payee
}

return fftrx, nil
return fftrx
}

func getReconciliationAccount(ff *gofirefly.APIClient, auth context.Context) (*gofirefly.AccountRead, error) {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
Copyright: "(c) 2020 Ahmad Satryaji Aulia",
Description: "Synchronize your BCA transactions with YNAB",
EnableBashCompletion: true,
Version: "v1.3.3",
Version: "v1.3.4",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "username",
Expand Down

0 comments on commit 6e2aef5

Please sign in to comment.