private IList <SupplyRecord> CreateSupplyRecordsByARInvoices(DocumentIDGroup documentIDGroup, GAFPeriod gafPeriod) { var resultRecords = new List <SupplyRecord>(); IDocumentGafRecordCreator <ARInvoice, SupplyRecord> documentGafRecordCreator = null; var arInvoices = _gafRepository.GetARInvoicesByIDs(documentIDGroup.DocumentType, documentIDGroup.RefNbrs.ToArray()); //module of taxTran is not honest, it alwayes equals to AR for all Account Receivable documents var documentGroupsByModule = arInvoices.GroupBy(apReg => apReg.OrigModule); foreach (var documentGroupByModule in documentGroupsByModule) { var documentGroup = new DocumentGroup <ARInvoice>() { Module = documentIDGroup.Module, DocumentType = documentIDGroup.DocumentType }; if (documentGroupByModule.Key == BatchModule.SO) { documentGafRecordCreator = _arInvoiceFromSOGafRecordsCreator; } else { documentGafRecordCreator = _arInvoiceGAFRecordsCreator; } documentGroup.DocumentsByRefNbr = documentGroupByModule.ToDictionary(invoice => invoice.RefNbr, invoice => invoice); var supplyRecords = documentGafRecordCreator.CreateGAFRecordsForDocumentGroup(documentGroup, gafPeriod.TaxAgencyID, gafPeriod.TaxPeriodID); resultRecords.AddRange(supplyRecords); } return(resultRecords); }