///<inheritdoc />
        public ForecastData GetData(Guid forecastId, FilterConfig filterConfig)
        {
            filterConfig.CheckArgumentNull(nameof(filterConfig));
            filterConfig.RecordIds.CheckArgumentNull(nameof(filterConfig.RecordIds));
            var sheet     = SheetRepository.GetSheet(forecastId);
            var recordIds = filterConfig.RecordIds;
            IEnumerable <Period> periods = PeriodRepository.GetForecastPeriods(filterConfig.PeriodIds, sheet.PeriodTypeId);
            var        periodIds         = periods.Select(p => p.Id);
            var        allCells          = EntityInForecastCellRepository.GetCellsByRecords(sheet, periodIds, recordIds);
            var        columns           = GetColumnInfos(forecastId, periods);
            List <Row> rows = new List <Row>();

            recordIds.ForEach(recordId => {
                IEnumerable <Cell> cells = allCells.Where(c => c.EntityId == recordId);
                rows.Add(new Row {
                    Id        = recordId,
                    Hierarchy = new [] { new HierarchyItem() },
                    Cells     = cells
                });
            });
            return(new ForecastData()
            {
                Rows = rows, Columns = columns
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the summary.
        /// </summary>
        /// <param name="sheetId">The sheet identifier.</param>
        /// <param name="periodIds">The period ids.</param>
        /// <returns>
        /// Collection of calculated summary cells.
        /// </returns>
        public IEnumerable <TableCell> GetSummary(Guid sheetId, IEnumerable <Guid> periodIds)
        {
            var sheet              = SheetRepository.GetSheet(sheetId);
            var cellValues         = new List <TableCell>();
            var columnsToCalculate = GetColumnsToCalculate(sheetId);

            if (columnsToCalculate.IsEmpty())
            {
                return(cellValues);
            }
            IEnumerable <Period> periodsInfo = PeriodRepository.GetForecastPeriods(periodIds, sheet.PeriodTypeId);
            EntitySchemaQuery    esq         = GetSummaryEsq(sheet, periodsInfo, columnsToCalculate);
            EntityCollection     collection  = esq.GetEntityCollection(UserConnection);

            foreach (var item in collection)
            {
                var periodName = item.GetTypedColumnValue <string>("PeriodName");
                var columnId   = item.GetTypedColumnValue <string>("ForecastColumnId");
                var summary    = item.GetTypedColumnValue <double>(_aggregationColumnName);
                cellValues.Add(new TableCell {
                    ColumnCode = columnId,
                    GroupCode  = periodName,
                    Value      = summary
                });
            }
            return(cellValues);
        }
        /// <summary>Gets the summary.</summary>
        /// <param name="sheet">The forecast sheet.</param>
        /// <param name="filterConfig">Configuration to filter records.</param>
        /// <returns>Summary table cells.</returns>
        public virtual IEnumerable <TableCell> GetSummary(Sheet sheet, FilterConfig filterConfig)
        {
            filterConfig.CheckArgumentNull(nameof(filterConfig));
            var columnsToCalculate = GetColumnsToCalculate(sheet.Id);

            if (columnsToCalculate.IsEmpty())
            {
                return(new TableCell[0]);
            }
            var periodIds  = filterConfig.PeriodIds;
            var cellValues = new List <TableCell>();
            IEnumerable <Period> periodsInfo = PeriodRepository.GetForecastPeriods(periodIds, sheet.PeriodTypeId);
            EntitySchemaQuery    esq         = GetSummaryEsq(sheet, periodsInfo, columnsToCalculate, filterConfig);
            EntityCollection     collection  = esq.GetEntityCollection(UserConnection);

            foreach (var item in collection)
            {
                cellValues.Add(FormTableCellFromEntity(item));
            }
            return(cellValues);
        }
        private ForecastData InnerGetData(Guid forecastId, IEnumerable <Guid> periodIds,
                                          PageableConfig pageableConfig)
        {
            forecastId.CheckArgumentEmpty(nameof(forecastId));
            Sheet sheet = SheetRepository.GetSheet(forecastId);
            IEnumerable <Period>       periods       = PeriodRepository.GetForecastPeriods(periodIds, sheet.PeriodTypeId);
            IEnumerable <ColumnInfo>   columns       = GetColumnInfos(forecastId, periods);
            IEnumerable <HierarchyRow> hierarchyRows = ForecastHierarchyRowDataRepository
                                                       .GetHierarchyRows(sheet, sheet.Setting?.Hierarchy, pageableConfig);
            List <Row>         rows      = new List <Row>();
            var                maxLevel  = sheet.Setting?.Hierarchy?.Count() ?? 0;
            IEnumerable <Cell> allCells  = new List <Cell>();
            var                hierarchy = new List <HierarchyItem>();

            if ((pageableConfig.HierarchyLevel == maxLevel) && (hierarchyRows.Any()))
            {
                allCells = EntityInForecastCellRepository.GetCellsByRecords(sheet,
                                                                            periods.Select(e => e.Id),
                                                                            hierarchyRows.Select(r => r.RecordId));
                hierarchy.Add(new HierarchyItem {
                    Id    = Guid.NewGuid(),
                    Level = maxLevel
                });
            }
            hierarchyRows.ForEach(hr => {
                IEnumerable <Cell> cells = allCells.Where(c => c.EntityId == hr.RecordId);
                rows.Add(new Row {
                    Id        = hr.RecordId,
                    Value     = hr.Value,
                    Hierarchy = hierarchy,
                    Cells     = cells
                });
            });
            return(new ForecastData {
                Columns = columns,
                Rows = rows
            });
        }
        private void InitPeriods(IDictionary <string, object> parameters)
        {
            var periodIds = parameters["PeriodIds"] as List <Guid>;

            Periods = PeriodRepository.GetPeriods(periodIds).Where(p => p.StartDate <= DateTime.Now).ToList();
        }