private static ProcessingResult ValidateFinPeriods(GLBudgetEntry graph, IEnumerable <GLBudgetLineDetail> records) { ProcessingResult generalResult = new ProcessingResult(); var recordsByPeriod = records.GroupBy(record => record.FinPeriodID); foreach (var recordsByPeriodGroup in recordsByPeriod) { string finPeriodID = recordsByPeriodGroup.Key; int?[] orgnizationIDs = recordsByPeriodGroup.GroupBy(t => PXAccess.GetParentOrganizationID(t.BranchID)) .Select(g => g.Key) .ToArray(); ICollection <OrganizationFinPeriod> finPeriods = PXSelect <OrganizationFinPeriod, Where <OrganizationFinPeriod.organizationID, In <Required <OrganizationFinPeriod.organizationID> >, And <OrganizationFinPeriod.finPeriodID, Equal <Required <OrganizationFinPeriod.finPeriodID> > > > > .Select(graph, orgnizationIDs, finPeriodID) .RowCast <OrganizationFinPeriod>() .ToArray(); if (finPeriods.Count != orgnizationIDs.Length) { string[] organizationCDs = orgnizationIDs.Except(finPeriods.Select(period => period.OrganizationID)) .Select(PXAccess.GetOrganizationCD) .ToArray(); generalResult.AddErrorMessage(Messages.FinPeriodDoesNotExistForCompanies, FinPeriodIDFormattingAttribute.FormatForError(finPeriodID), organizationCDs.JoinIntoStringForMessageNoQuotes(20)); } foreach (OrganizationFinPeriod finPeriod in finPeriods) { ProcessingResult result = new ProcessingResult(); if (finPeriod.Status == FinPeriod.status.Locked) { result.AddErrorMessage(Messages.FinPeriodIsLockedInCompany, FinPeriodIDFormattingAttribute.FormatForError(finPeriod.FinPeriodID), PXAccess.GetOrganizationCD(finPeriod.OrganizationID)); } generalResult.Aggregate(result); if (generalResult.Messages.Count > 20) { return(generalResult); } } } return(generalResult); }