-
Notifications
You must be signed in to change notification settings - Fork 1
/
entry.go
45 lines (39 loc) · 808 Bytes
/
entry.go
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
package nacha
import (
"bytes"
"strconv"
)
type Entry struct {
data [][]byte
Remove bool
}
func (e *Entry) hash() int64 {
hash, err := strconv.ParseInt(string(e.data[0][3:11]), 10, 64)
if err != nil {
panic(err)
}
return hash
}
func (e *Entry) termId() string {
return string(bytes.TrimRight(e.data[0][39:54], " "))
}
func (e *Entry) seq() string {
return string(bytes.Trim(e.data[1][14:25], "0 "))
}
func (e *Entry) postAmt() (float64, error) {
value := []byte{'0'}
credit := false
value = e.data[0][29:39]
switch string(e.data[0][1:3]) {
case "21", "22", "23", "24", "31", "32", "33", "34", "41", "42", "43", "44", "51", "52", "53", "54":
credit = true
}
amt, err := parseCurrency(value)
if err != nil {
return 0, err
}
if credit {
amt *= -1
}
return amt / 100, nil
}