Beispiel #1
0
        public List <DashboardPayoutToken> GetNextPayout(int userId)
        {
            try
            {
                var now      = DateTime.Now;
                var previous = now.AddMonths(-1);

                using (var context = new lfeAuthorEntities())
                {
                    var currentPayout = context.sp_PO_GetMonthlyPayoutReport(now.Year, now.Month, LFE_COMMISSION_PERCENT, userId, null).Select(x => x.Entity2DashboardPayoutToken()).ToList();

                    if (currentPayout.Count.Equals(0))
                    {
                        return new List <DashboardPayoutToken>
                               {
                                   new DashboardPayoutToken
                                   {
                                       Sales  = 0
                                       , Fees = 0
                                       , Mbg  = 0
                                                // ,TotalPayout = 0
                                       , Currency = ActiveCurrencies.FirstOrDefault(x => x.CurrencyId == DEFAULT_CURRENCY_ID)
                                   }
                               }
                    }
                    ;

                    var previousPayout = context.sp_PO_GetMonthlyPayoutReport(previous.Year, previous.Month, LFE_COMMISSION_PERCENT, userId, null).Select(x => x.Entity2DashboardPayoutToken()).ToList();

                    foreach (var token in currentPayout)
                    {
                        var t = token;

                        var previousToken = previousPayout.FirstOrDefault(x => x.Currency.CurrencyId == t.Currency.CurrencyId);

                        token.IsUp = previousToken == null || previousToken.TotalPayout <= t.TotalPayout;
                    }


                    return(currentPayout);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GetNextPayout", ex, CommonEnums.LoggerObjectTypes.Dashboard);

                return(new List <DashboardPayoutToken>());
            }
        }
Beispiel #2
0
        public List <PayoutCurrencySummaryDTO> GetPayoutCurrencySummaryRows(int year, int month, int?userId, short?currencyId, int executionId)
        {
            try
            {
                var list = new List <PayoutCurrencySummaryDTO>();

                using (var context = new lfeAuthorEntities())
                {
                    var rows = context.sp_PO_GetMonthlyPayoutReport(year, month, LFE_COMMISSION_PERCENT, userId, currencyId).ToList();

                    var currencies = rows.GroupBy(x => new{ x.CurrencyId, x.CurrencyName, x.ISO, x.Symbol }).Select(x => new BaseCurrencyDTO
                    {
                        CurrencyId     = x.Key.CurrencyId
                        , CurrencyName = x.Key.CurrencyName
                        , ISO          = x.Key.ISO
                        , Symbol       = x.Key.Symbol
                    }).ToList();
                    foreach (var currency in currencies)
                    {
                        var cur = currency;
                        list.Add(new PayoutCurrencySummaryDTO
                        {
                            Currency = currency
                            , Rows   = rows.Where(x => x.CurrencyId == cur.CurrencyId).Select(x => x.Entity2ReportRowDto(year, month, GetPayoutStatus(x.UserId, executionId))).OrderByDescending(x => x.TotalSales).ToList()
                        });
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                Logger.Error("GetPayoutCurrencySummaryRows", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new List <PayoutCurrencySummaryDTO>());
            }
        }