public ForecastDataResponse GetCellValuesByGroupRecords(Guid forecastId, Guid[] periods,
                                                                GroupRecordsItem[] groupsCollection)
        {
            var response = new ForecastDataResponse();

            if (!UserConnection.GetIsFeatureEnabled("ForecastGroupSummary") || !groupsCollection.Any())
            {
                response.DataSource = new TreeTableDataItem[0];
                return(response);
            }
            var sheet = SheetRepository.GetSheet(forecastId);
            var sheetHierarchyList = sheet.GetHierarchyItems();
            var allRows            = new List <TreeTableDataItem>();

            try {
                groupsCollection.ForEach(groupItem => {
                    int level = groupItem.ParentIds?.Length ?? 0;
                    HierarchySettingItem hierarchyItem = sheetHierarchyList.FirstOrDefault(item => item.Level == level);
                    if (hierarchyItem == null)
                    {
                        string message = $"Could not get hierarchy item by level {level}. ForecastId: {forecastId}";
                        _log.Error(message);
                        throw new Exception(message);
                    }
                    IEnumerable <HierarchyFilterItem> hierarchyFilterItems =
                        sheet.FormHierarchyFilter(groupItem.ParentIds);
                    var cells = ForecastSummaryProvider.GetGroupsSummary(sheet, new FilterConfig()
                    {
                        PeriodIds       = periods,
                        RecordIds       = groupItem.RecordIds,
                        Hierarchy       = hierarchyFilterItems,
                        GroupColumnPath = hierarchyItem?.ColumnPath
                    });
                    var rows = ForecastDataMapper.GetMapTreeTableDataItems(cells, groupItem.ParentIds);
                    rows.ForEach(row => row.IsGroup = true);
                    allRows.AddRange(rows);
                });
                response.DataSource = allRows;
                if (UserConnection.GetIsFeatureEnabled("ForecastSummaryFormula"))
                {
                    SummaryColumnCalculator.ApplySummaryData(UserConnection, forecastId, response.DataSource);
                }
            } catch (Exception ex) {
                response.Exception = ex;
            }
            return(response);
        }
Example #2
0
 private string FormColumnName(HierarchySettingItem hierarchyItem)
 {
     return(hierarchyItem.ColumnPath.Replace(".", "_") + "Id");
 }