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

Discussion: Calculating trailer aggregates #109

Open
brian-pickens opened this issue Apr 1, 2024 · 3 comments
Open

Discussion: Calculating trailer aggregates #109

brian-pickens opened this issue Apr 1, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@brian-pickens
Copy link
Contributor

brian-pickens commented Apr 1, 2024

I am investigating how one might update the library to generate the trailer record aggregates. At first this seemed to me like it should be a relatively simple task by following some of the ACH library Create() patterns and iterating through the hierarchy.

However as I've come to understand the file specification more, and from reading through the bai2 library code, I can see counting the continuation records is becoming a bit of a foil. In particular, reading through string() in pkg/lib/record_transaction_detail.go#L114 and reading through util.WriteBuffer() pkg/util/write.go#L16, I can see that the total number of records is also directly tied to the file's Physical Record Length which follows the rules of the file spec.

I have some ideas of how I could count the number or records, which I can present both here and/or in a PR but I am curious, what are your thoughts on this issue, and why weren't the aggregate fields calculated in the design of the library to this point?

@brian-pickens
Copy link
Contributor Author

brian-pickens commented Apr 2, 2024

Here is one idea I had. Give each record type a recordCount() function like this. You would reuse the existing compile logic in string() to find the total records.

var accountIdentifierCountExpression = regexp.MustCompile(`(?m:^(?:(?:03)|(?:16)|(?:88)))`)
func (r *accountIdentifier) recordCount(opts ...int64) int {
	records := r.string(opts...)
	result := accountIdentifierCountExpression.FindAllStringSubmatch(records, 10000)
	return len(result)
}

@adamdecaf adamdecaf added the enhancement New feature or request label Apr 3, 2024
@adamdecaf
Copy link
Member

Adding recordCount makes sense to me. I'm also wondering if we should hide some of those computed fields/records and only offer Getter's to them.

@brian-pickens
Copy link
Contributor Author

Actually I have a PR incoming. Feel free to critique it. My approach is to offer a non-breaking change.

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