public JsonResult TransactionsHighcharts(Guid dashboardId, Guid panelId)
        {
            var series = new List<Series>();
            var seriesDrilldown = new List<Series>();

            var panel = this.GetPanel(dashboardId, panelId);
            var transactions = transactionServiceOnlyTransaction.GetTransactionsFiltrated(panel.Filter);
            var hasOnlyOutputs = true;

            var type = panel.GetDataType();
            switch (type)
            {
                case Panel.PanelDataType.NonGroup:
                case Panel.PanelDataType.NonGroupAndSortDate:
                {
                    var group = new TransactionGroupDefinition
                    {
                        OrderBy = null,
                        OrderByClassification = null,
                        OrderByExpression = null,
                        OrderByName = null,
                        GroupBy = null,
                        //GroupByExpression = panel.GetGroupByExpression(panel.GroupBy, out groupByName),
                        GroupByExpression = f => f.Date.Date,
                        GroupByName = null,
                        OrderByGroup = null,
                        OrderByGroupClassification = null,
                        OrderByGroupExpression = null,
                        OrderByGroupName = null,
                    };

                    transactions = transactions.OrderBy(f => f.Date).ToList();
                    var transactionGroup = transactionServiceOnlyTransaction.GetTransactionGroupRoot(transactions, group);

                    //var transactionsDayGrouped = transactions.OrderBy(f => f.Date).GroupBy(f=>f.Date.Date).ToList();
                    //var total = transactions.Sum(f => f.Value);
                    //var count = transactions.Count();

                    var serieData = new SeriesData[transactionGroup.SubGroups.Count];
                    var serie = new Series
                    {
                        Name = " ",
                        Data = new DotNet.Highcharts.Helpers.Data(serieData),
                    };

                    series.Add(serie);

                    var index = 0;
                    foreach (var transactionDayGroup in transactionGroup.SubGroups)
                    {
                        var y = 0d;
                        switch(panel.DisplayY)
                        {
                            case TransactionDisplayY.Value:
                                y = (double)transactionDayGroup.Total;
                                break;
                            case TransactionDisplayY.ValuePercentage:
                                y = (double)transactionDayGroup.TotalPercentage.Last();
                                break;
                            case TransactionDisplayY.Count:
                                y = transactionDayGroup.Count;
                                break;
                            case TransactionDisplayY.CountPercentage:
                                y = (double)transactionDayGroup.CountPercentage.Last();
                                break;
                        }

                        var day = (DateTime)transactionDayGroup.Key;
                        serieData[index] = new SeriesData();
                        serieData[index].X = Helper.UnixTicks(day);
                        serieData[index].Y = (Number)y;
                        serieData[index].Name = day.ToString("d");

                        if (y > 0)
                            hasOnlyOutputs = false;

                        index++;
                    }
                    break;
                }
                case SpentBook.Domain.Panel.PanelDataType.OneGroup:
                case SpentBook.Domain.Panel.PanelDataType.TwoGroup:
                case SpentBook.Domain.Panel.PanelDataType.ThreeOrMoreGroup:
                {
                    var transactionGroup = transactionService.GetTransactionGroupRoot(transactions, panel.GetGroupDefinitions().ToArray());
                    var tryCategorize = true;

                    // Como só existe 1 nível, fica impossível criar categorização
                    if (type == Panel.PanelDataType.OneGroup)
                        tryCategorize = false;

                    var chartDataCategorizeds = transactionService.GetChartDataCategorized(transactionGroup, tryCategorize);

                    foreach (var item in chartDataCategorizeds)
                    {
                        var serieData = new SeriesData[item.Items.Length];
                        var serie = new Series
                        {
                            Id = item.ParentPath,
                            Name = string.IsNullOrWhiteSpace(item.ItemGroupName) ? "Todos" : item.ItemGroupName,
                            Data = new DotNet.Highcharts.Helpers.Data(serieData),
                        };

                        if (item.ParentPath == null)
                        {
                            series.Add(serie);
                        }
                        else
                        {
                            seriesDrilldown.Add(serie);
                            serie.PlotOptionsBar = new PlotOptionsBar { ColorByPoint = false };
                        }

                        var index = 0;
                        foreach (var data in item.Items)
                        {
                            if (data == null)
                            {
                                serieData[index++] = null;
                            }
                            else
                            {
                                var y = 0d;
                                switch (panel.DisplayY)
                                {
                                    case TransactionDisplayY.Value:
                                        y = (double)data.Total;
                                        break;
                                    case TransactionDisplayY.ValuePercentage:
                                        if (tryCategorize && item.ParentPath == null)
                                            y = (double)data.TotalPercentageGrandParentRelation;
                                        else
                                            y = (double)data.TotalPercentage;
                                        break;
                                    case TransactionDisplayY.Count:
                                        y = (double)data.Count;
                                        break;
                                    case TransactionDisplayY.CountPercentage:
                                        if (tryCategorize && item.ParentPath == null)
                                            y = (double)data.CountPercentageGrandParentRelation;
                                        else
                                            y = (double)data.CountPercentage;
                                        break;
                                }

                                serieData[index++] = new SeriesData
                                {
                                    Y = (Number)y,
                                    Name = data.Category,
                                    Id = data.Category,
                                    Drilldown = data.ItemPath
                                };

                                if (data.Category == "Despesa")
                                    serieData[index - 1].Color = System.Drawing.Color.Red;

                                if (data.Total > 0)
                                    hasOnlyOutputs = false;
                            }
                        }
                    }

                    break;
                }
            }

            return Json(new { Series = series, Drilldown = seriesDrilldown, Reversed = hasOnlyOutputs, DisplatY = panel.DisplayY }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult TransactionsTable(Guid dashboardId, Guid panelId)
        {
            var htmlTable = "";
            var panel = this.GetPanel(dashboardId, panelId);
            var transactions = transactionServiceOnlyTransaction.GetTransactionsFiltrated(panel.Filter);
            var type = panel.GetDataType();
            switch (type)
            {
                case Panel.PanelDataType.NonGroup:
                case Panel.PanelDataType.NonGroupAndSortDate:
                {
                    if (type == Panel.PanelDataType.NonGroupAndSortDate)
                    {
                        var group = new TransactionGroupDefinition {
                            OrderBy = null,
                            OrderByClassification = null,
                            OrderByExpression = null,
                            OrderByName = null,
                            GroupBy = null,
                            //GroupByExpression = panel.GetGroupByExpression(panel.GroupBy, out groupByName),
                            GroupByExpression = f => f.Date.Date,
                            GroupByName = null,
                            OrderByGroup = null,
                            OrderByGroupClassification = null,
                            OrderByGroupExpression =null,
                            OrderByGroupName = null,
                        };

                        var transactionGroup = transactionService.GetTransactionGroupRoot(transactions, group);
                        htmlTable = Helper.RenderPartialViewToString("~/Views/Templates/Tables/TransactionsGroupDay.cshtml", transactionGroup, this);

                        //var transactionsDayGrouped = transactions.GroupBy(f => f.Date.Date).ToList();
                        //htmlTable = Helper.RenderPartialViewToString("~/Views/Templates/Tables/TransactionsGroupDay.cshtml", transactionsDayGrouped, this);
                    }
                    else
                    {
                        var group = new TransactionGroupDefinition
                        {
                            OrderBy = null,
                            OrderByClassification = null,
                            OrderByExpression = null,
                            OrderByName = null,
                            GroupBy = null,
                            //GroupByExpression = panel.GetGroupByExpression(panel.GroupBy, out groupByName),
                            GroupByExpression = f => f.GetHashCode(),
                            GroupByName = null,
                            OrderByGroup = null,
                            OrderByGroupClassification = null,
                            OrderByGroupExpression = null,
                            OrderByGroupName = null,
                        };
                        var transactionGroup = transactionService.GetTransactionGroupRoot(transactions, group);
                        htmlTable = Helper.RenderPartialViewToString("~/Views/Templates/Tables/TransactionsSimple.cshtml", transactionGroup, this);
                    }

                    break;
                }
                case SpentBook.Domain.Panel.PanelDataType.OneGroup:
                case SpentBook.Domain.Panel.PanelDataType.TwoGroup:
                case SpentBook.Domain.Panel.PanelDataType.ThreeOrMoreGroup:
                {
                    var transactionGroup = transactionService.GetTransactionGroupRoot(transactions, panel.GetGroupDefinitions().ToArray());
                    var expressions = this.GetTransactionGroupToExpression(transactionGroup);
                    htmlTable = Helper.RenderPartialViewToString("~/Views/Templates/Tables/TransactionsGroupMulti.cshtml", expressions, this);
                    break;
                }
            }

            return Json(new { Table = htmlTable }, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 3
0
        public List<TransactionGroupDefinition> GetGroupDefinitions()
        {
            if (this._groupDefinitions == null)
            {
                this._groupDefinitions = new List<TransactionGroupDefinition>();
                //var onlyOutputs = this.Filter.TransactionType == TransactionType.Output;
                var groupByName = "";
                var orderByName = "";

                if (this.GroupBy != TransactionGroupBy.None)
                {
                    var groupBy1 = new TransactionGroupDefinition()
                    {
                        OrderBy = this.GroupByOrderBy,
                        OrderByClassification = this.GroupByOrderByClassification,
                        OrderByExpression = this.GetOrderByExpression(this.GroupByOrderBy, out orderByName),
                        OrderByName = orderByName,
                        GroupBy = this.GroupBy,
                        GroupByExpression = this.GetGroupByExpression(this.GroupBy, out groupByName),
                        GroupByName = groupByName,
                        OrderByGroup = this.GroupByOrderByGroup,
                        OrderByGroupClassification = this.GroupByOrderByGroupClassification,
                        OrderByGroupExpression = this.GetOrderByGroupExpression(this.GroupByOrderByGroup, out orderByName),
                        OrderByGroupName = orderByName,
                    };
                    this._groupDefinitions.Add(groupBy1);
                }

                if (this.GroupBy2 != TransactionGroupBy.None)
                {
                    var groupBy2 = new TransactionGroupDefinition()
                    {
                        OrderBy = this.GroupByOrderBy2,
                        OrderByClassification = this.GroupByOrderByClassification2,
                        OrderByExpression = this.GetOrderByExpression(this.GroupByOrderBy2, out orderByName),
                        OrderByName = orderByName,
                        GroupBy = this.GroupBy2,
                        GroupByExpression = this.GetGroupByExpression(this.GroupBy2, out groupByName),
                        GroupByName = groupByName,
                        OrderByGroup = this.GroupByOrderByGroup2,
                        OrderByGroupClassification = this.GroupByOrderByGroupClassification2,
                        OrderByGroupExpression = this.GetOrderByGroupExpression(this.GroupByOrderByGroup2, out orderByName),
                        OrderByGroupName = orderByName,
                    };
                    this._groupDefinitions.Add(groupBy2);
                }

                if (this.GroupBy3 != TransactionGroupBy.None)
                {
                    var groupBy3 = new TransactionGroupDefinition()
                    {
                        OrderBy = this.GroupByOrderBy3,
                        OrderByClassification = this.GroupByOrderByClassification3,
                        OrderByExpression = this.GetOrderByExpression(this.GroupByOrderBy3, out orderByName),
                        OrderByName = orderByName,
                        GroupBy = this.GroupBy3,
                        GroupByExpression = this.GetGroupByExpression(this.GroupBy3, out groupByName),
                        GroupByName = groupByName,
                        OrderByGroup = this.GroupByOrderByGroup3,
                        OrderByGroupClassification = this.GroupByOrderByGroupClassification3,
                        OrderByGroupExpression = this.GetOrderByGroupExpression(this.GroupByOrderByGroup3, out orderByName),
                        OrderByGroupName = orderByName,
                    };
                    this._groupDefinitions.Add(groupBy3);
                }

            }

            return this._groupDefinitions;
        }