MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / manyToOne

Method manyToOne

reconciliation.go:772–799  ·  view source on GitHub ↗

manyToOne handles the core logic of many-to-one reconciliation. It groups external transactions and processes them in batches, comparing them to internal transactions. Parameters: - ctx: The context controlling the operation. - internalTxns: The internal transactions to match against. - matchingRule

(ctx context.Context, internalTxns []*model.Transaction, uploadID string, matchingRules []model.MatchingRule, isExternalGrouped bool, wg *sync.WaitGroup, groupingCriteria string, batchSize int, matchChan chan model.Match, unMatchChan chan string)

Source from the content-addressed store, hash-verified

770// Returns:
771// - error: If any error occurs during processing.
772func (s *LedgerForge) manyToOne(ctx context.Context, internalTxns []*model.Transaction, uploadID string, matchingRules []model.MatchingRule, isExternalGrouped bool, wg *sync.WaitGroup, groupingCriteria string, batchSize int, matchChan chan model.Match, unMatchChan chan string) error {
773 offset := int64(0)
774 ctx, span := otel.Tracer("ledgerforge.reconciliation").Start(ctx, "ProcessManyToOne")
775 defer span.End()
776
777 // Loop to process transactions in batches.
778 for {
779 groupedExternalTxns, err := s.groupExternalTransactions(ctx, uploadID, groupingCriteria, batchSize, offset)
780 if err != nil {
781 logrus.Errorf("Error grouping external transactions: %v", err)
782 break
783 }
784 if len(groupedExternalTxns) == 0 {
785 span.AddEvent("No more grouped transactions to process")
786 break
787 }
788 groupMap := s.buildGroupMap(groupedExternalTxns)
789 err = s.processGroupedTransactions(internalTxns, groupedExternalTxns, groupMap, matchingRules, isExternalGrouped, wg, matchChan, unMatchChan)
790 if err != nil {
791 logrus.Errorf("Error processing grouped transactions: %v", err)
792 }
793 if len(groupMap) == 0 {
794 break
795 }
796 offset += int64(batchSize)
797 }
798 return nil
799}
800
801// groupExternalTransactions retrieves and groups external transactions based on the specified criteria.
802// This is used in many-to-one reconciliation.

Callers 1

Calls 4

buildGroupMapMethod · 0.95
StartMethod · 0.45

Tested by

no test coverage detected