-
Notifications
You must be signed in to change notification settings - Fork 145
/
file.go
171 lines (141 loc) · 6.34 KB
/
file.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package describe
import (
"fmt"
"io"
"strings"
"text/tabwriter"
"unicode/utf8"
"github.com/moov-io/ach"
)
type Opts struct {
MaskNames bool
MaskAccountNumbers bool
}
func File(ww io.Writer, file *ach.File, opts *Opts) {
if file == nil {
return
}
if opts == nil {
opts = &Opts{}
}
w := tabwriter.NewWriter(ww, 0, 0, 2, ' ', 0)
defer w.Flush()
fh, fc := file.Header, file.Control
// FileHeader
fmt.Fprintln(w, " Origin\tOriginName\tDestination\tDestinationName\tFileCreationDate\tFileCreationTime")
fmt.Fprintf(w, " %s\t%s\t%s\t%s\t%s\t%s\n", fh.ImmediateOrigin, fh.ImmediateOriginName, fh.ImmediateDestination, fh.ImmediateDestinationName, fh.FileCreationDate, fh.FileCreationTime)
// Batches
for i := range file.Batches {
fmt.Fprintln(w, "\n BatchNumber\tSECCode\tServiceClassCode\tCompanyName\tDiscretionaryData\tIdentification\tEntryDescription\tEffectiveEntryDate\tDescriptiveDate")
bh := file.Batches[i].GetHeader()
if bh != nil {
fmt.Fprintf(w, " %d\t%s\t%d %s\t%s\t%s\t%s\t%s\t%s\t%s\n",
bh.BatchNumber,
bh.StandardEntryClassCode,
bh.ServiceClassCode,
serviceClassCodes[bh.ServiceClassCode],
bh.CompanyName,
bh.CompanyDiscretionaryData,
bh.CompanyIdentification,
bh.CompanyEntryDescription,
bh.EffectiveEntryDate,
bh.CompanyDescriptiveDate,
)
}
entries := file.Batches[i].GetEntries()
for j := range entries {
fmt.Fprintln(w, "\n TransactionCode\tRDFIIdentification\tAccountNumber\tAmount\tName\tTraceNumber\tCategory")
e := entries[j]
accountNumber := e.DFIAccountNumber
if opts.MaskAccountNumbers {
accountNumber = maskAccountNumber(strings.TrimSpace(accountNumber))
}
fmt.Fprintf(w, " %d %s\t%s\t%s\t%d\t%s\t%s\t%s\n", e.TransactionCode, transactionCodes[e.TransactionCode], e.RDFIIdentification, accountNumber, e.Amount, e.IndividualName, e.TraceNumber, e.Category)
dumpAddenda02(w, e.Addenda02)
for i := range e.Addenda05 {
if i == 0 {
fmt.Fprintln(w, "\n Addenda05")
}
dumpAddenda05(w, e.Addenda05[i])
}
dumpAddenda98(w, e.Addenda98)
dumpAddenda99(w, e.Addenda99)
dumpAddenda99Dishonored(w, e.Addenda99Dishonored)
dumpAddenda99Contested(w, e.Addenda99Contested)
}
bc := file.Batches[i].GetControl()
if bc != nil {
fmt.Fprintln(w, "\n ServiceClassCode\tEntryAddendaCount\tEntryHash\tTotalDebits\tTotalCredits\tMACCode\tODFIIdentification\tBatchNumber")
fmt.Fprintf(w, " %d %s\t%d\t%d\t%d\t%d\t%s\t%s\t%d\n", bc.ServiceClassCode, serviceClassCodes[bh.ServiceClassCode], bc.EntryAddendaCount, bc.EntryHash, bc.TotalDebitEntryDollarAmount, bc.TotalCreditEntryDollarAmount, bc.MessageAuthenticationCode, bc.ODFIIdentification, bc.BatchNumber)
}
}
// FileControl
fmt.Fprintln(w, "\n BatchCount\tBlockCount\tEntryAddendaCount\tTotalDebitAmount\tTotalCreditAmount")
fmt.Fprintf(w, " %d\t%d\t%d\t%d\t%d\n", fc.BatchCount, fc.BlockCount, fc.EntryAddendaCount, fc.TotalDebitEntryDollarAmountInFile, fc.TotalCreditEntryDollarAmountInFile)
}
func dumpAddenda02(w *tabwriter.Writer, a *ach.Addenda02) {
if a == nil {
return
}
fmt.Fprintln(w, "\n Addenda02")
fmt.Fprintln(w, " ReferenceInfoOne\tReferenceInfoTwo\tTerminalIdentification\tTransactionSerial\tDate\tAuthCodeOrExires\tLocation\tCity\tState\tTraceNumber")
fmt.Fprintf(w, " %s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
a.ReferenceInformationOne, a.ReferenceInformationTwo, a.TerminalIdentificationCode, a.TransactionSerialNumber,
a.TransactionDate, a.AuthorizationCodeOrExpireDate, a.TerminalLocation, a.TerminalCity, a.TerminalState, a.TraceNumber)
}
func dumpAddenda99Dishonored(w *tabwriter.Writer, a *ach.Addenda99Dishonored) {
if a == nil {
return
}
fmt.Fprintln(w, "\n Dishonored Addenda99")
fmt.Fprintln(w, " Dis. ReturnCode\tOrig. TraceNumber\tRDFI Identification\tTraceNumber\tSettlementDate\tReturnCode\tAddendaInformation\tTraceNumber")
fmt.Fprintf(w, " %s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
a.DishonoredReturnReasonCode, a.OriginalEntryTraceNumber, a.OriginalReceivingDFIIdentification, a.ReturnTraceNumber,
a.ReturnSettlementDate, a.ReturnReasonCode, a.AddendaInformation, a.TraceNumber)
}
func dumpAddenda99Contested(w *tabwriter.Writer, a *ach.Addenda99Contested) {
if a == nil {
return
}
fmt.Fprintln(w, "\n Contested Dishonored Addenda99")
fmt.Fprintln(w, " ContestedReturnCode\tOrig. TraceNumber\tOrig Date Returned\tOrig. RDFIIdentification\tOrig. SettlementDate\tReturnTraceNumber")
fmt.Fprintf(w, " %s\t%s\t%s\t%s\t%s\t%s\n",
a.ContestedReturnCode, a.OriginalEntryTraceNumber, a.DateOriginalEntryReturned, a.OriginalReceivingDFIIdentification,
a.OriginalSettlementDate, a.ReturnTraceNumber)
fmt.Fprintln(w, " ReturnSettlementDate\tReturnReasonCode\tDishonoredTraceNumber\tDishonoredSettlementDate\tDishonoredReasonCode\tTraceNumber")
fmt.Fprintf(w, " %s\t%s\t%s\t%s\t%s\t%s\n",
a.ReturnSettlementDate, a.ReturnReasonCode, a.DishonoredReturnTraceNumber, a.DishonoredReturnSettlementDate, a.DishonoredReturnReasonCode, a.TraceNumber)
}
func dumpAddenda05(w *tabwriter.Writer, a *ach.Addenda05) {
if a == nil {
return
}
fmt.Fprintln(w, " PaymentRelatedInformation\tSequenceNumber\tEntryDetailSequenceNumber")
fmt.Fprintf(w, " %s\t%d\t%d\n", a.PaymentRelatedInformation, a.SequenceNumber, a.EntryDetailSequenceNumber)
}
func dumpAddenda98(w *tabwriter.Writer, a *ach.Addenda98) {
if a == nil {
return
}
fmt.Fprintln(w, "\n Addenda98")
fmt.Fprintln(w, " ChangeCode\tOriginalTrace\tOriginalDFI\tCorrectedData\tTraceNumber")
fmt.Fprintf(w, " %s\t%s\t%s\t%s\t%s\n", a.ChangeCode, a.OriginalTrace, a.OriginalDFI, a.CorrectedData, a.TraceNumber)
}
func dumpAddenda99(w *tabwriter.Writer, a *ach.Addenda99) {
if a == nil {
return
}
fmt.Fprintln(w, "\n Addenda99")
fmt.Fprintln(w, " ReturnCode\tOriginalTrace\tDateOfDeath\tOriginalDFI\tAddendaInformation\tTraceNumber")
fmt.Fprintf(w, " %s\t%s\t%s\t%s\t%s\t%s\n", a.ReturnCode, a.OriginalTrace, a.DateOfDeath, a.OriginalDFI, a.AddendaInformation, a.TraceNumber)
}
func maskAccountNumber(s string) string {
length := utf8.RuneCountInString(s)
if length < 5 {
return "****" // too short, we can't keep anything
}
return strings.Repeat("*", length-4) + s[length-4:]
}