oneToManyReconciliation performs a one-to-many reconciliation, where each external transaction can match multiple internal transactions grouped by specific criteria. Parameters are the same as `oneToOneReconciliation`, with additional support for grouping criteria and a flag to determine if the exte
(ctx context.Context, externalTxns []*model.Transaction, groupCriteria string, matchingRules []model.MatchingRule, isExternalGrouped bool)
| 679 | // - []model.Match: A list of matched transactions. |
| 680 | // - []string: A list of unmatched transaction IDs. |
| 681 | func (s *LedgerForge) oneToManyReconciliation(ctx context.Context, externalTxns []*model.Transaction, groupCriteria string, matchingRules []model.MatchingRule, isExternalGrouped bool) ([]model.Match, []string) { |
| 682 | conf, err := config.Fetch() |
| 683 | if err != nil { |
| 684 | logrus.Errorf("Error fetching configuration: %v", err) |
| 685 | } |
| 686 | |
| 687 | var matches []model.Match |
| 688 | var unmatched []string |
| 689 | |
| 690 | matchChan := make(chan model.Match, len(externalTxns)) |
| 691 | unmatchedChan := make(chan string, len(externalTxns)) |
| 692 | var wg sync.WaitGroup |
| 693 | |
| 694 | // Initiate the one-to-many reconciliation process. |
| 695 | err = s.oneToMany(ctx, externalTxns, matchingRules, isExternalGrouped, &wg, groupCriteria, conf.Transaction.BatchSize, matchChan, unmatchedChan) |
| 696 | if err != nil { |
| 697 | logrus.Errorf("Error in one-to-many reconciliation: %v", err) |
| 698 | } |
| 699 | |
| 700 | go func() { |
| 701 | wg.Wait() |
| 702 | close(matchChan) |
| 703 | close(unmatchedChan) |
| 704 | }() |
| 705 | |
| 706 | for match := range matchChan { |
| 707 | matches = append(matches, match) |
| 708 | } |
| 709 | for unmatchedID := range unmatchedChan { |
| 710 | unmatched = append(unmatched, unmatchedID) |
| 711 | } |
| 712 | |
| 713 | return matches, unmatched |
| 714 | } |
| 715 | |
| 716 | // manyToOneReconciliation performs a many-to-one reconciliation, where multiple internal transactions |
| 717 | // are grouped and matched against a single external transaction. |