~mendelmaleh/pfin

ref: 4b06f49cd6d4f9ffc730cc85847a1d7a2e22898c pfin/parser/capitalone/interface.go -rw-r--r-- 796 bytes
4b06f49cMendel E Make pfin.Transaction.Amount() consistent 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package capitalone

import (
	"fmt"
	"time"

	"git.sr.ht/~mendelmaleh/pfin/util"
)

func (tx Transaction) Date() time.Time {
	return tx.Raw.TransactionDate.Time
}

func (tx Transaction) Amount() float64 {
	if tx.Debit != 0 {
		return -tx.Debit
	}

	if tx.Credit != 0 {
		return tx.Credit
	}

	// TODO
	panic("both credit and debit are zero: " + fmt.Sprintln(tx))

	return -tx.Debit
}

func (tx Transaction) Name() string {
	return tx.Raw.Description
}

func (tx Transaction) Category() string {
	return tx.Raw.Category
}

func (tx Transaction) Card() string {
	return tx.Raw.CardNumber
}

func (tx Transaction) User() string {
	return tx.Fields.User
}

func (tx Transaction) Account() string {
	return tx.Fields.Account
}

func (tx Transaction) String() string {
	return util.FormatTx(tx, " ")
}