Skip to content

Commit

Permalink
ach-cli: Add short description next to digit codes (#883)
Browse files Browse the repository at this point in the history
* add descriptions next to cli digit codes

* update cli output example in docs

* add transaction mappings and move map transformers into new file

* print second instance of service code description using new mapping

Co-authored-by: Vincent Xiao <vincentx72@gmail.com>
  • Loading branch information
nlakritz and vxio authored Mar 30, 2021
1 parent a305249 commit 42bc05f
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 13 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ Describing ACH file 'test/testdata/ppd-debit.ach'
121042882 My Bank Name 231380104 Federal Reserve Bank 190624 0000
BatchNumber SECCode ServiceClassCode CompanyName DiscretionaryData Identification EntryDescription DescriptiveDate
1 PPD 225 Name on Account 121042882 REG.SALARY
1 PPD 225 (Debits Only) Name on Account 121042882 REG.SALARY
TransactionCode RDFIIdentification AccountNumber Amount Name TraceNumber Category
27 23138010 12345678 100000000 Receiver Account Name 121042880000001
TransactionCode RDFIIdentification AccountNumber Amount Name TraceNumber Category
27 (Checking Debit) 23138010 12345678 100000000 Receiver Account Name 121042880000001
ServiceClassCode EntryAddendaCount EntryHash TotalDebits TotalCredits MACCode ODFIIdentification BatchNumber
225 1 23138010 100000000 0 12104288 1
225 (Debits Only) 1 23138010 100000000 0 12104288 1
BatchCount BlockCount EntryAddendaCount TotalDebitAmount TotalCreditAmount
1 1 1 100000000 0
Expand Down
74 changes: 74 additions & 0 deletions cmd/achcli/code_map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package main

import (
"fmt"

"github.com/moov-io/ach"
)

var serviceClassCodes = map[int]string{
ach.MixedDebitsAndCredits: "(Mixed Debits and Credits)",
ach.CreditsOnly: "(Credits Only)",
ach.DebitsOnly: "(Debits Only)",
ach.AutomatedAccountingAdvices: "(Automated Accounting Analysis)",
}

type transactionType string

const (
debit transactionType = "Debit"
credit transactionType = "Credit"
)

var transactionCodes = map[int]string{
ach.CheckingCredit: entry("Checking", credit),
ach.CheckingReturnNOCCredit: noc("Checking", credit),
ach.CheckingPrenoteCredit: prenote("Checking", credit),
ach.CheckingZeroDollarRemittanceCredit: remittance("Checking", credit),

ach.CheckingDebit: entry("Checking", debit),
ach.CheckingReturnNOCDebit: noc("Checking", debit),
ach.CheckingPrenoteDebit: prenote("Checking", debit),
ach.CheckingZeroDollarRemittanceDebit: remittance("Checking", debit),

ach.SavingsCredit: entry("Savings", credit),
ach.SavingsReturnNOCCredit: noc("Savings", credit),
ach.SavingsPrenoteCredit: prenote("Savings", credit),
ach.SavingsZeroDollarRemittanceCredit: remittance("Savings", credit),

ach.SavingsDebit: entry("Savings", debit),
ach.SavingsReturnNOCDebit: noc("Savings", debit),
ach.SavingsPrenoteDebit: prenote("Savings", debit),
ach.SavingsZeroDollarRemittanceDebit: remittance("Savings", debit),

ach.GLCredit: entry("GL", credit),
ach.GLReturnNOCCredit: noc("GL", credit),
ach.GLPrenoteCredit: prenote("GL", credit),
ach.GLZeroDollarRemittanceCredit: remittance("Gl", credit),

ach.GLDebit: entry("GL", debit),
ach.GLReturnNOCDebit: noc("GL", debit),
ach.GLPrenoteDebit: prenote("GL", debit),
ach.GLZeroDollarRemittanceDebit: remittance("Gl", debit),

ach.LoanCredit: entry("Loan", credit),
ach.LoanReturnNOCCredit: noc("Loan", credit),
ach.LoanPrenoteCredit: prenote("Loan", credit),
ach.LoanZeroDollarRemittanceCredit: remittance("Loan", credit),

ach.LoanDebit: entry("Loan", debit),
ach.LoanReturnNOCDebit: noc("Loan", debit),
}

func entry(s string, t transactionType) string {
return fmt.Sprintf("(%s %s)", s, t)
}
func noc(s string, t transactionType) string {
return fmt.Sprintf("(%s Return NOC %s)", s, t)
}
func prenote(s string, t transactionType) string {
return fmt.Sprintf("(%s Prenote %s)", s, t)
}
func remittance(s string, t transactionType) string {
return fmt.Sprintf("(%s Zero Dollar Remittance %s)", s, t)
}
19 changes: 14 additions & 5 deletions cmd/achcli/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,17 @@ func dumpFile(file *ach.File) {

bh := file.Batches[i].GetHeader()
if bh != nil {
fmt.Fprintf(w, " %d\t%s\t%d\t%s\t%s\t%s\t%s\t%s\n",
bh.BatchNumber, bh.StandardEntryClassCode, bh.ServiceClassCode, bh.CompanyName,
bh.CompanyDiscretionaryData, bh.CompanyIdentification, bh.CompanyEntryDescription, bh.CompanyDescriptiveDate)
fmt.Fprintf(w, " %d\t%s\t%d %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.CompanyDescriptiveDate,
)
}

entries := file.Batches[i].GetEntries()
Expand All @@ -86,7 +94,8 @@ func dumpFile(file *ach.File) {
if *flagMask {
accountNumber = maskAccountNumber(strings.TrimSpace(accountNumber))
}
fmt.Fprintf(w, " %d\t%s\t%s\t%d\t%s\t%s\t%s\n", e.TransactionCode, e.RDFIIdentification, accountNumber, e.Amount, e.IndividualName, e.TraceNumber, e.Category)

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 {
Expand All @@ -102,7 +111,7 @@ func dumpFile(file *ach.File) {
bc := file.Batches[i].GetControl()
if bc != nil {
fmt.Fprintln(w, "\n ServiceClassCode\tEntryAddendaCount\tEntryHash\tTotalDebits\tTotalCredits\tMACCode\tODFIIdentification\tBatchNumber")
fmt.Fprintf(w, " %d\t%d\t%d\t%d\t%d\t%s\t%s\t%d\n", bc.ServiceClassCode, bc.EntryAddendaCount, bc.EntryHash, bc.TotalDebitEntryDollarAmount, bc.TotalCreditEntryDollarAmount, bc.MessageAuthenticationCode, bc.ODFIIdentification, bc.BatchNumber)
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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions docs/usage-command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ Describing ACH file 'test/testdata/ppd-debit.ach'
121042882 My Bank Name 231380104 Federal Reserve Bank 190624 0000
BatchNumber SECCode ServiceClassCode CompanyName DiscretionaryData Identification EntryDescription DescriptiveDate
1 PPD 225 Name on Account 121042882 REG.SALARY
1 PPD 225 (Debits Only) Name on Account 121042882 REG.SALARY
TransactionCode RDFIIdentification AccountNumber Amount Name TraceNumber Category
27 23138010 12345678 100000000 Receiver Account Name 121042880000001
TransactionCode RDFIIdentification AccountNumber Amount Name TraceNumber Category
27 (Checking Debit) 23138010 12345678 100000000 Receiver Account Name 121042880000001
ServiceClassCode EntryAddendaCount EntryHash TotalDebits TotalCredits MACCode ODFIIdentification BatchNumber
225 1 23138010 100000000 0 12104288 1
225 (Debits Only) 1 23138010 100000000 0 12104288 1
BatchCount BlockCount EntryAddendaCount TotalDebitAmount TotalCreditAmount
1 1 1 100000000 0
Expand Down

0 comments on commit 42bc05f

Please sign in to comment.