Beispiel #1
0
        public ChartDataVm GetPortfolioChartData(PortfolioChartDataQueryParam queryParams)
        {
            var result = ChartDataVm.Default;

            result.Labels = TradeUtils.GetPeriodLabels(queryParams.Periods.ToPeriodList()).ToArray();

            switch (queryParams.ChartType)
            {
            case PortfolioChartType.Nav:
                result.Data = new[] { GetPortfolioNavChartData(queryParams) };
                break;

            case PortfolioChartType.OpenPositions:
                result.Data = new[] { GetPortfolioOpenPositionsChartData(queryParams) };
                break;

            case PortfolioChartType.TotalUn:
                result.Data = new[] { GetPortfolioTotalUnChartData(queryParams) };
                break;
            }

            return(result);
        }
Beispiel #2
0
        public ChartDataVm LoadInterest(IEnumerable <Period> periodsParam, long[] idMasterAccounts, long[] idTradeAccounts)
        {
            var result    = ChartDataVm.Default;
            var periods   = periodsParam.ToList();
            var endPeriod = periods.LastOrDefault()?.ToDate;

            if (endPeriod == null)
            {
                return(result);
            }

            result.Labels = TradeUtils.GetPeriodLabels(periods).ToArray();
            Dictionary <long, ChartDataVm.DataSet> data;

            var tradeInterestAccruaQuery = _tradeAccountRepository.TradeInterestAccrua();

            if (TradeUtils.IsSortingByTradeAccounts(idTradeAccounts))
            {
                data = GetDictionaryByTradeAccounts(idTradeAccounts);

                tradeInterestAccruaQuery = tradeInterestAccruaQuery.Where(nav => idTradeAccounts.Contains(nav.TradeAccountId));

                periods.ForEach(period =>
                {
                    var extractedData = tradeInterestAccruaQuery
                                        .Where(tradeNav =>
                                               DbFunctions.TruncateTime(tradeNav.ReportDate) == DbFunctions.TruncateTime(period.ToDate))
                                        .GroupBy(group => new
                    {
                        group.TradeAccount.Id,
                        group.TradeAccount.AccountName,
                        group.TradeAccount.AccountAlias,
                    })
                                        .Select(select => new ExtractedAccountData
                    {
                        Id           = select.Key.Id,
                        AccountName  = select.Key.AccountName,
                        AccountAlias = select.Key.AccountAlias,
                        Number       = select.Sum(tradeInterest => tradeInterest.EndingAccrualBalance)
                    })
                                        .ToList();

                    ProcessExtractedData(extractedData, data);
                });
            }
            else
            {
                data = GetDictionaryByMasterAccounts(idMasterAccounts);

                if (TradeUtils.IsSortingByMasterAccounts(idMasterAccounts))
                {
                    tradeInterestAccruaQuery = tradeInterestAccruaQuery.Where(nav =>
                                                                              idMasterAccounts.Contains(nav.TradeAccount.MasterAccountId));
                }

                periods.ForEach(period =>
                {
                    var extractedData = tradeInterestAccruaQuery
                                        .Where(tradeNav =>
                                               DbFunctions.TruncateTime(tradeNav.ReportDate) == DbFunctions.TruncateTime(period.ToDate))
                                        .GroupBy(group => new
                    {
                        group.TradeAccount.MasterAccount.Id,
                        group.TradeAccount.MasterAccount.AccountName,
                        group.TradeAccount.MasterAccount.AccountAlias
                    })
                                        .Select(select => new ExtractedAccountData
                    {
                        Id           = select.Key.Id,
                        AccountName  = select.Key.AccountName,
                        AccountAlias = select.Key.AccountAlias,
                        Number       = select.Sum(tradeInterest => tradeInterest.EndingAccrualBalance)
                    })
                                        .ToList();

                    ProcessExtractedData(extractedData, data);
                });
            }

            if (data.Any())
            {
                result.Data = data.Select(d => d.Value).ToArray();
            }

            return(result);
        }
Beispiel #3
0
        public ChartDataVm LoadTotalIncome(IEnumerable <Period> periodsParam, long[] idMasterAccounts,
                                           long[] idTradeAccounts)
        {
            var periods      = periodsParam.ToList();
            var startPeriods = periods.FirstOrDefault()?.FromDate;
            var endPeriods   = periods.LastOrDefault()?.ToDate;
            var result       = ChartDataVm.Default;

            if (startPeriods == null || endPeriods == null)
            {
                return(result);
            }

            result.Labels = TradeUtils.GetPeriodLabels(periods).ToArray();
            Dictionary <long, ChartDataVm.DataSet> data;

            var fees = _tradeRepository
                       .TradeFeesQuery()
                       .Include(f => f.TradeAccount.MasterAccount)
                       .Where(s => s.ExternalDate >= startPeriods && s.ExternalDate <= endPeriods);

            if (TradeUtils.IsSortingByTradeAccounts(idTradeAccounts))
            {
                fees = fees.Where(fee => idTradeAccounts.Contains(fee.TradeAccountId));
                data = GetDictionaryByTradeAccounts(idTradeAccounts);

                periods.ForEach(period =>
                {
                    var extractedData = fees
                                        .Where(fee => fee.ExternalDate >= period.FromDate && fee.ExternalDate <= period.ToDate)
                                        .GroupBy(group => new
                    {
                        group.TradeAccount.Id,
                        group.TradeAccount.AccountName,
                        group.TradeAccount.AccountAlias,
                    })
                                        .Select(select => new ExtractedAccountData
                    {
                        Id           = select.Key.Id,
                        AccountName  = select.Key.AccountName,
                        AccountAlias = select.Key.AccountAlias,
                        Number       = select.Sum(f => f.NetInBase)
                    })
                                        .ToList();

                    ProcessExtractedData(extractedData, data);
                });
            }
            else
            {
                data = GetDictionaryByMasterAccounts(idMasterAccounts);

                if (TradeUtils.IsSortingByMasterAccounts(idMasterAccounts))
                {
                    fees = fees.Where(fee => idMasterAccounts.Contains(fee.TradeAccount.MasterAccountId));
                }

                periods.ForEach(period =>
                {
                    var extractedData = fees
                                        .Where(fee => fee.ExternalDate >= period.FromDate && fee.ExternalDate <= period.ToDate)
                                        .GroupBy(group => new
                    {
                        group.TradeAccount.MasterAccount.Id,
                        group.TradeAccount.MasterAccount.AccountName,
                        group.TradeAccount.MasterAccount.AccountAlias
                    })
                                        .Select(select => new ExtractedAccountData
                    {
                        Id           = select.Key.Id,
                        AccountName  = select.Key.AccountName,
                        AccountAlias = select.Key.AccountAlias,
                        Number       = select.Sum(f => f.NetInBase)
                    })
                                        .ToList();


                    ProcessExtractedData(extractedData, data);
                });
            }

            if (data.Any())
            {
                result.Data = data.Select(d => d.Value).ToArray();
            }

            return(result);
        }
Beispiel #4
0
        public ChartDataVm LoadTotalClients(IEnumerable <Period> periodsParam, long[] idMasterAccounts,
                                            long[] idTradeAccounts)
        {
            var result    = ChartDataVm.Default;
            var periods   = periodsParam.ToList();
            var endPeriod = periods.LastOrDefault()?.ToDate;

            if (endPeriod == null)
            {
                return(result);
            }

            Dictionary <long, ChartDataVm.DataSet> data;

            result.Labels = TradeUtils.GetPeriodLabels(periods).ToArray();

            var accountsQuery = _tradeRepository
                                .TradeAccountsQuery()
                                .Include(a => a.MasterAccount)
                                .Where(account => account.DateOpened != null &&
                                       account.DateOpened <= endPeriod &&
                                       (account.DateClosed == null ||
                                        (account.DateClosed != null && account.DateClosed > endPeriod)));

            data = GetDictionaryByMasterAccounts(idMasterAccounts);

            // sorting by selected master accounts
            if (TradeUtils.IsSortingByMasterAccounts(idMasterAccounts))
            {
                accountsQuery = accountsQuery.Where(s => idMasterAccounts.Contains(s.MasterAccountId));
            }

            periods.ForEach(period =>
            {
                var extractedAccountData = accountsQuery
                                           .GroupBy(group => new
                {
                    group.MasterAccount.Id,
                    group.MasterAccount.AccountName,
                    group.MasterAccount.AccountAlias
                })
                                           .Select(select => new ExtractedAccountData
                {
                    Id           = select.Key.Id,
                    AccountName  = select.Key.AccountName,
                    AccountAlias = select.Key.AccountAlias,
                    Number       = select.Count(account => account.DateOpened != null &&
                                                account.DateOpened <= period.ToDate &&
                                                (account.DateClosed == null ||
                                                 account.DateClosed != null &&
                                                 account.DateClosed > period.ToDate))
                })
                                           .ToList();

                ProcessExtractedData(extractedAccountData, data);
            });

            if (data.Any())
            {
                result.Data = data.Select(d => d.Value).ToArray();
            }

            return(result);
        }
Beispiel #5
0
        public ChartDataVm GetChartData(AnalyticsChartDataParams @params)
        {
            var result = new ChartDataVm();

            var impQuery = ImportRepository.ImportedFilesQuery();
            var delQuery = ImportRepository.FileUploadQuery().Include(f => f.ImportedFile);

            if (@params.MasterAccountId != 0)
            {
                impQuery = impQuery.Where(f => f.MasterAccountId == @params.MasterAccountId);
                delQuery = delQuery.Where(f => f.ImportedFile.MasterAccountId == @params.MasterAccountId);
            }

            if (@params.FtpCredentialId != 0)
            {
                impQuery = impQuery.Where(f => f.FtpCredentialId == @params.FtpCredentialId);
                delQuery = delQuery.Where(f => f.ImportedFile.FtpCredentialId == @params.FtpCredentialId);
            }

            var srcFilesData = new ChartDataVm.DataSet {
                Label = "Source files"
            };
            var impFilesData = new ChartDataVm.DataSet {
                Label = "Imported files"
            };
            var delFilesData = new ChartDataVm.DataSet {
                Label = "ZOHO files"
            };
            var sentFilesData = new ChartDataVm.DataSet {
                Label = "Sent ZOHO files"
            };

            var periods = @params.Periods.ToPeriodList().ToList();

            periods.ToList().ForEach(period =>
            {
                var srcFiles = impQuery.Count(f =>
                                              DbFunctions.TruncateTime(f.FileCreateDate) >= DbFunctions.TruncateTime(period.FromDate) &&
                                              DbFunctions.TruncateTime(f.FileCreateDate) <= DbFunctions.TruncateTime(period.ToDate));

                var impFiles = impQuery.Count(f =>
                                              DbFunctions.TruncateTime(f.FileCreateDate) >= DbFunctions.TruncateTime(period.FromDate) &&
                                              DbFunctions.TruncateTime(f.FileCreateDate) <= DbFunctions.TruncateTime(period.ToDate) &&
                                              f.ImportedDate != null);

                var delFiles = delQuery.Count(f =>
                                              DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) >=
                                              DbFunctions.TruncateTime(period.FromDate) &&
                                              DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) <= DbFunctions.TruncateTime(period.ToDate));

                var sentFiles = delQuery.Count(f => f.IsSent &&
                                               DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) >=
                                               DbFunctions.TruncateTime(period.FromDate) &&
                                               DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) <=
                                               DbFunctions.TruncateTime(period.ToDate));

                srcFilesData.Data.Add(srcFiles);
                impFilesData.Data.Add(impFiles);
                delFilesData.Data.Add(delFiles);
                sentFilesData.Data.Add(sentFiles);
            });

            result.Data   = new[] { srcFilesData, impFilesData, delFilesData, sentFilesData };
            result.Labels = TradeUtils.GetPeriodLabels(periods).ToArray();

            return(result);
        }