-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
118 lines (96 loc) · 4.31 KB
/
types.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package goAba
import (
"fmt"
"time"
)
type Header struct {
Type string `json:"Type"` // should be "0"
BSB string `json:"BSB"` // Main account BSB. Ignored according to spec
Account string `json:"Account"` // Main account number, Up to 9 chars, ignored
Bank string `json:"Bank"` // Name of Financial institution processing the file, 3 char "ANZ", "WBC"
User string `json:"User"` // How the user will be shown in the transactions of the 3rd party banks
UserNumber string `json:"UserNumber"` // The ID of the user supplying this file
Description string `json:"Description"` // Description of this file entries, up to 12 chars
Date string `json:"Date"` // date to be processed
Time time.Time `json:"Time"` // time to be processed, ignored.
}
type SchemaField struct {
Name string `json:"Name"`
Boundaries []int `json:"Boundaries"`
Type string `json:"Type"`
}
type Schema struct {
RecordType string `json:"RecordType"`
Fields []SchemaField `json:"Fields"`
}
type Footer struct {
Type string `json:"Type"` // Default = "7", auto generated field, can override
BSB string `json:"BSB"` // Default = "999999" This is autogenerated, can override
NetTotal string `json:"NetTotal"` // This is auto generated, can override
CreditTotal string `json:"CreditTotal"` // This is auto generated, can override
DebitTotal string `json:"DebitTotal"` // this is auto generated, can override
NumberOfTransactions string `json:"NumberOfTransactions"` // this is autog generated, can override
}
type Transaction struct {
TransactionType string `json:"TransactionType"` //
BSB string `json:"BSB"` // the 3rd party account BSB
Tax string `json:"Tax"` //
TransactionCode string `json:"TransactionCode"` // Debit or Credit?
Account string `json:"Account"` // 3rd party account number
Amount float64 `json:"Amount"` //
AccountTitle string `json:"AccountTitle"` // 3rd party (recipient) account name, up to 32 chars
Reference string `json:"Reference"` // payment ref. e.g "Invoice #1", up to 18 chars
TraceBSB string `json:"TraceBSB"` // the transacting account BSB
TraceAccount string `json:"TraceAccount"` // the transacting account number
Remitter string `json:"Remitter"` // the transacting company name
TaxAmount float64 `json:"TaxAmount"` //
}
type ABA struct {
Header Header `json:"header"`
Schema []Schema `json:"schema"`
Footer Footer `json:"footer"`
Transactions []Transaction `json:"transactions"`
}
func (h *Header) ToString() string {
headerStr := fmt.Sprintf("0 01%s %s%s%s%s ", h.Bank, h.User, h.UserNumber, h.Description, h.Date)
return headerStr
}
func (t *Transaction) ToString() string {
var transactionStr string
// add record
transactionStr += "1"
// add bsb
bankNum := buildBankNumber(t.BSB)
transactionStr += bankNum
// add acc number
accNum := buildAccNumber(t.Account)
transactionStr += accNum
// add indicator
// dont have one right now (TODO:?)
transactionStr += " "
// add transaction code
transactionStr += t.TransactionCode
// add amount
amountStr := buildTotal(t.Amount)
amount := fillField(10, amountStr, "right", "0")
transactionStr += amount
// add title
titleStr := fillField(32, t.AccountTitle, "left", " ")
transactionStr += titleStr
// add reference
refStr := fillField(18, t.Reference, "left", " ")
transactionStr += refStr
//add trace record
transactionStr += buildBankNumber(t.TraceBSB)
//add trace acc
transactionStr += fillField(9, t.TraceAccount, "right", " ")
//add remitter
transactionStr += fillField(16, t.Remitter, "left", " ")
//add tax
transactionStr += fillField(8, buildTotal(t.TaxAmount), "right", "0")
return transactionStr
}
func (f *Footer) ToString() string {
footerStr := fmt.Sprintf("7999-999 %s%s%s %s ", f.NetTotal, f.CreditTotal, f.DebitTotal, f.NumberOfTransactions)
return footerStr
}