openmeter / ledger /impact.go
Leon4gr45's picture
Upload folder using huggingface_hub (part 5)
cee2387 verified
Raw
History Blame Contribute Delete
610 Bytes
package ledger
import "github.com/alpacahq/alpacadecimal"
func TransactionImpact(tx Transaction, filter ImpactFilter) alpacadecimal.Decimal {
total := alpacadecimal.Zero
for _, entry := range tx.Entries() {
if EntryMatchesImpactFilter(entry, filter) {
total = total.Add(entry.Amount())
}
}
return total
}
func EntryMatchesImpactFilter(entry Entry, filter ImpactFilter) bool {
address := entry.PostingAddress()
if filter.AccountType != "" && address.AccountType() != filter.AccountType {
return false
}
if !address.Route().Route().Matches(filter.Route) {
return false
}
return true
}