Ejemplo n.º 1
0
        public IEnumerable<IChartData> GetChartData( ChartGroupBy groupBy = ChartGroupBy.Week, TransactionGraphBy graphBy = TransactionGraphBy.Total, 
            DateTime? startDate = null, DateTime? endDate = null, decimal? minAmount = null, decimal? maxAmount = null, 
            string currencyTypeIds = null, string sourceTypeIds = null, string accountIds = null, int? dataViewId = null )
        {
            var numericCurrencyTypeIds = new List<int>();
            if ( currencyTypeIds != null )
            {
                currencyTypeIds.Split( ',' ).ToList().ForEach( i => numericCurrencyTypeIds.Add( i.AsInteger() ) );
            }

            var numericSourceTypeIds = new List<int>();
            if ( sourceTypeIds != null )
            {
                sourceTypeIds.Split( ',' ).ToList().ForEach( i => numericSourceTypeIds.Add( i.AsInteger() ) );
            }

            var numericAccountIds = new List<int>();
            if ( accountIds != null )
            {
                accountIds.Split( ',' ).ToList().ForEach( i => numericAccountIds.Add( i.AsInteger() ) );
            }

            return new FinancialTransactionDetailService( new RockContext() ).GetChartData(
                groupBy, graphBy, startDate, endDate, minAmount, maxAmount, numericCurrencyTypeIds,
                numericSourceTypeIds, numericAccountIds, dataViewId );
        }
        /// <summary>
        /// Gets the chart data.
        /// </summary>
        /// <param name="groupBy">The group by.</param>
        /// <param name="graphBy">The graph by.</param>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <param name="minAmount">The minimum amount.</param>
        /// <param name="maxAmount">The maximum amount.</param>
        /// <param name="currencyTypeIds">The currency type ids.</param>
        /// <param name="sourceTypeIds">The source type ids.</param>
        /// <param name="accountIds">The account ids.</param>
        /// <param name="dataViewId">The data view identifier.</param>
        /// <returns></returns>
        public IEnumerable<IChartData> GetChartData(
            ChartGroupBy groupBy, TransactionGraphBy graphBy, DateTime? start, DateTime? end, decimal? minAmount, decimal? maxAmount,
            List<int> currencyTypeIds, List<int> sourceTypeIds, List<int> accountIds, int? dataViewId )
        {
            var qry = GetGifts( start, end, minAmount, maxAmount, currencyTypeIds, sourceTypeIds, accountIds, dataViewId );

            var qryWithSummaryDateTime = qry.GetFinancialTransactionDetailWithSummaryDateTime( groupBy );

            var summaryQry = qryWithSummaryDateTime.Select( d => new
            {
                d.SummaryDateTime,
                Campus = new
                {
                    Id = d.FinancialTransactionDetail.Account.CampusId ?? 0,
                    Name = d.FinancialTransactionDetail.Account.Campus != null ?
                        d.FinancialTransactionDetail.Account.Campus.Name : "None"
                },
                Account = new
                {
                    Id = d.FinancialTransactionDetail.AccountId,
                    Name = d.FinancialTransactionDetail.Account.Name
                },
                Amount = d.FinancialTransactionDetail.Amount
            } );

            List<SummaryData> result = null;

            if ( graphBy == TransactionGraphBy.Total )
            {
                var groupByQry = summaryQry.GroupBy( d => new { d.SummaryDateTime } ).Select( s => new { s.Key, Amount = s.Sum( a => a.Amount ) } ).OrderBy( o => o.Key );
                result = groupByQry.ToList().Select( d => new SummaryData
                    {
                        DateTimeStamp = d.Key.SummaryDateTime.ToJavascriptMilliseconds(),
                        DateTime = d.Key.SummaryDateTime,
                        SeriesId = "Total",
                        YValue = d.Amount
                    } ).ToList();
            }
            else if ( graphBy == TransactionGraphBy.Campus )
            {
                var groupByQry = summaryQry.GroupBy( d => new { d.SummaryDateTime, Series = d.Campus } ).Select( s => new { s.Key, Amount = s.Sum( a => a.Amount ) } ).OrderBy( o => o.Key );
                result = groupByQry.ToList().Select( d => new SummaryData
                {
                    DateTimeStamp = d.Key.SummaryDateTime.ToJavascriptMilliseconds(),
                    DateTime = d.Key.SummaryDateTime,
                    SeriesId = d.Key.Series.Name,
                    YValue = d.Amount
                } ).ToList();
            }
            else if ( graphBy == TransactionGraphBy.FinancialAccount )
            {
                var groupByQry = summaryQry.GroupBy( d => new { d.SummaryDateTime, Series = d.Account } ).Select( s => new { s.Key, Amount = s.Sum( a => a.Amount ) } ).OrderBy( o => o.Key );
                result = groupByQry.ToList().Select( d => new SummaryData
                {
                    DateTimeStamp = d.Key.SummaryDateTime.ToJavascriptMilliseconds(),
                    DateTime = d.Key.SummaryDateTime,
                    SeriesId = d.Key.Series.Name,
                    YValue = d.Amount
                } ).ToList();
            }

            if ( result.Count == 1 )
            {
                var dummyZeroDate = start ?? DateTime.MinValue;
                result.Insert( 0, new SummaryData { DateTime = dummyZeroDate, DateTimeStamp = dummyZeroDate.ToJavascriptMilliseconds(), SeriesId = result[0].SeriesId, YValue = 0 } );
            }

            return result;
        }
        public IEnumerable <IChartData> GetChartData(ChartGroupBy groupBy   = ChartGroupBy.Week, TransactionGraphBy graphBy = TransactionGraphBy.Total,
                                                     DateTime?startDate     = null, DateTime?endDate     = null, decimal?minAmount = null, decimal?maxAmount = null,
                                                     string currencyTypeIds = null, string sourceTypeIds = null, string accountIds = null, int?dataViewId    = null)
        {
            var numericCurrencyTypeIds = new List <int>();

            if (currencyTypeIds != null)
            {
                currencyTypeIds.Split(',').ToList().ForEach(i => numericCurrencyTypeIds.Add(i.AsInteger()));
            }

            var numericSourceTypeIds = new List <int>();

            if (sourceTypeIds != null)
            {
                sourceTypeIds.Split(',').ToList().ForEach(i => numericSourceTypeIds.Add(i.AsInteger()));
            }

            var numericAccountIds = new List <int>();

            if (accountIds != null)
            {
                accountIds.Split(',').ToList().ForEach(i => numericAccountIds.Add(i.AsInteger()));
            }

            return(new FinancialTransactionDetailService(new RockContext()).GetChartData(
                       groupBy, graphBy, startDate, endDate, minAmount, maxAmount, numericCurrencyTypeIds,
                       numericSourceTypeIds, numericAccountIds, dataViewId));
        }
        /// <summary>
        /// Gets the chart data.
        /// </summary>
        /// <param name="groupBy">The group by.</param>
        /// <param name="graphBy">The graph by.</param>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <param name="minAmount">The minimum amount.</param>
        /// <param name="maxAmount">The maximum amount.</param>
        /// <param name="currencyTypeIds">The currency type ids.</param>
        /// <param name="sourceTypeIds">The source type ids.</param>
        /// <param name="accountIds">The account ids.</param>
        /// <param name="dataViewId">The data view identifier.</param>
        /// <returns></returns>
        public IEnumerable <IChartData> GetChartData(
            ChartGroupBy groupBy, TransactionGraphBy graphBy, DateTime?start, DateTime?end, decimal?minAmount, decimal?maxAmount,
            List <int> currencyTypeIds, List <int> sourceTypeIds, List <int> accountIds, int?dataViewId)
        {
            var qry = GetGifts(start, end, minAmount, maxAmount, currencyTypeIds, sourceTypeIds, accountIds, dataViewId);

            var qryWithSummaryDateTime = qry.GetFinancialTransactionDetailWithSummaryDateTime(groupBy);

            var summaryQry = qryWithSummaryDateTime.Select(d => new
            {
                d.SummaryDateTime,
                Campus = new
                {
                    Id   = d.FinancialTransactionDetail.Account.CampusId ?? 0,
                    Name = d.FinancialTransactionDetail.Account.Campus != null ?
                           d.FinancialTransactionDetail.Account.Campus.Name : "None"
                },
                Account = new
                {
                    Id   = d.FinancialTransactionDetail.AccountId,
                    Name = d.FinancialTransactionDetail.Account.Name
                },
                Amount = d.FinancialTransactionDetail.Amount
            });

            List <SummaryData> result = null;

            if (graphBy == TransactionGraphBy.Total)
            {
                var groupByQry = summaryQry.GroupBy(d => new { d.SummaryDateTime }).Select(s => new { s.Key, Amount = s.Sum(a => a.Amount) }).OrderBy(o => o.Key);
                result = groupByQry.ToList().Select(d => new SummaryData
                {
                    DateTimeStamp = d.Key.SummaryDateTime.ToJavascriptMilliseconds(),
                    DateTime      = d.Key.SummaryDateTime,
                    SeriesId      = "Total",
                    YValue        = d.Amount
                }).ToList();
            }
            else if (graphBy == TransactionGraphBy.Campus)
            {
                var groupByQry = summaryQry.GroupBy(d => new { d.SummaryDateTime, Series = d.Campus }).Select(s => new { s.Key, Amount = s.Sum(a => a.Amount) }).OrderBy(o => o.Key);
                result = groupByQry.ToList().Select(d => new SummaryData
                {
                    DateTimeStamp = d.Key.SummaryDateTime.ToJavascriptMilliseconds(),
                    DateTime      = d.Key.SummaryDateTime,
                    SeriesId      = d.Key.Series.Name,
                    YValue        = d.Amount
                }).ToList();
            }
            else if (graphBy == TransactionGraphBy.FinancialAccount)
            {
                var groupByQry = summaryQry.GroupBy(d => new { d.SummaryDateTime, Series = d.Account }).Select(s => new { s.Key, Amount = s.Sum(a => a.Amount) }).OrderBy(o => o.Key);
                result = groupByQry.ToList().Select(d => new SummaryData
                {
                    DateTimeStamp = d.Key.SummaryDateTime.ToJavascriptMilliseconds(),
                    DateTime      = d.Key.SummaryDateTime,
                    SeriesId      = d.Key.Series.Name,
                    YValue        = d.Amount
                }).ToList();
            }

            return(result);
        }