Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpret type codes #55

Open
barszcz opened this issue Jan 11, 2023 · 2 comments
Open

Interpret type codes #55

barszcz opened this issue Jan 11, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@barszcz
Copy link

barszcz commented Jan 11, 2023

Bai2 Version: 0.1.0

03 (Account Identifier) and 16 (Transaction Detail) records contain three-digit "type codes" that denote the type(s) of data the record contains. These are key to interpreting the data in the BAI2 file; therefore it makes sense that this library should return relevant information about them.

Type codes come in three broad categories:

  • Account Status: Pretty self explanatory, these describe things like ledger balance, available balance and float position. These show up in 03 records (and their continuations).
  • Activity Summary: These are summaries of credit and debit activity on the account. Again, these appear in 03 records (and their continuations).
  • Transaction Detail: These describe individual debits and credits on an account. As the name suggests, they show up on 16 records (and I assume their continuations, but the spec is mum on this).

Summary and Detail types also denote whether they refer to a debit or credit. The spec PDF has a large table detailing all the codes and their meanings. A kind person has helpfully transcribed them all into a CSV already.

We can probably convert that CSV into a hardcoded map without much difficulty. Something like

type TypeCode struct {
	TypeCode string // not int as leading zeros are significant
	Transaction string // "CR" "DB" or "NA"
	Level string // "Status" "Summary" or "Detail"
	Description string
}

var TypeCodes := map[string]TypeCode{
	"010": {
		TypeCode: "010",
		Transaction: "NA",
		Level: "Status",
		Description: "Opening Ledger",
	},
	// ...
}

Then it would be an easy lookup. We could also make type-aliased string enums for transaction and level, but unsure if it's really necessary.

In 03 records, we can also determine whether a type code should have item count and funds type by whether it's a status or summary type code, which may help in parsing that.

@barszcz
Copy link
Author

barszcz commented Jan 11, 2023

I could whip something up later this week to generate a Go file with the map from the CSV. Shouldn't be too bad to do with Go templates.

@adamdecaf adamdecaf added the enhancement New feature or request label Jan 11, 2023
@adamdecaf
Copy link
Member

Sounds good. If they don't change often we could just generate the code once. If you need examples there are a few in other codebases.

https://github.com/moov-io/ach/blob/master/internal/iso4217/iso4217_gen.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants