moov-io / bai2

BAI2 file format is a cash management balance reporting standard
Apache License 2.0
15 stars 9 forks source link

Add aggregation helper functions for setting record trailer fields #110

Closed brian-pickens closed 4 months ago

brian-pickens commented 5 months ago

Adds the following methods

func (a *Account) SumRecords(opts ...int64) int64 maps to Account Trailer: Number of Record func (a *Account) SumDetailAmounts() (string, error) maps to Account Trailer: Account Control Total func (g *Group) SumRecords() int64 maps to Group Trailer: Number of Records func (g *Group) SumNumberOfAccounts() int64 maps to Group Trailer: Number of Accounts func (a *Group) SumAccountControlTotals() (string, error) maps to Group Trailer: Group Control Total func (f *Bai2) SumRecords() int64 maps to File Trailer: Number of Records func (g *Bai2) SumNumberOfGroups() maps to File Trailer: Number of Accounts func (a *Bai2) SumGroupControlTotals() (string, error) maps to File Trailer: Group Control Total

An example of how the methods are meant to be used

account := Account{}
account.Details = append(account.Details, details...)
controlTotal, _ := account.SumDetailAmounts()
account.AccountControlTotal = controlTotal
account.NumberRecords = account1.SumRecords(80)

109