public List <Product> GetMostPurchasedWith(string productBvin, SalesPeriod period, int maxItemsToReturn) { using (var context = Factory.CreateHccDbContext()) { var storeId = Context.CurrentStore.Id; var productGuid = DataTypeHelper.BvinToGuid(productBvin); var range = DateHelper.GetDateRange(period); var productGuids = context.hcc_Order .Where(o => o.StoreId == storeId && o.IsPlaced == 1 && o.TimeOfOrder >= range.StartDate && o.TimeOfOrder <= range.EndDate) .Join(context.hcc_LineItem, o => o.bvin, li => li.OrderBvin, (o, li) => new { o, li }) .Join(context.hcc_Product, j => j.li.ProductId, p => p.bvin, (j, p) => new { j.o, j.li, p }) .Where(j => j.p.bvin != productGuid) .Where( j => context.hcc_LineItem.Where(li => li.ProductId == productGuid) .Select(li => li.OrderBvin) .Contains(j.o.bvin)) .GroupBy(j => j.p.bvin) .Select(g => new { ProductId = g.Key, TotalOrdered = g.Sum(v => v.li.Quantity) }) .OrderBy(v => v.TotalOrdered) .Select(v => v.ProductId) .Take(maxItemsToReturn) .ToList(); var productIds = productGuids.Select(p => DataTypeHelper.GuidToBvin(p)).ToList(); return(FindManyWithCache(productIds)); } }
public async Task <IActionResult> SalesStatistics(SalesPeriod salePeriod) { try { MultiResult <List <string>, List <decimal>, List <int> > result = new MultiResult <List <string>, List <decimal>, List <int> >(); switch (salePeriod) { case SalesPeriod.Daily: result = await GetDaily(CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)); break; case SalesPeriod.Monthly: result = await GetMonthly(CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)); break; case SalesPeriod.Yearly: result = await GetYearly(CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)); break; default: break; } ; return(Ok(result)); } catch (Exception ex) { CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }
public Response GetTransLog(string token, [FromBody] SalesPeriod param) { Response response = new Response(); if (string.IsNullOrEmpty(token) || !token.Equals(_token)) { response.code = "404"; response.message = "Invild token"; } else { var data = SalesInvoiceHelper.GetTransLog(param); if (data == null) { response.code = "500"; response.message = "process failed"; } else { response.code = "200"; response.content = data; } } return(response); }
public ProductRepository() { this._products = new Dictionary <string, Product>(); var product = Product.CreateANewProduct("テスト", SalesPeriod.SellYearRound(), null, 3.5); this._products.Add(product.Describe().Id, product); product = Product.CreateANewProduct("テスト2", SalesPeriod.SellInLimitedTime(6, RoughDay.middle, 10, RoughDay.beginning), null, 2.8); this._products.Add(product.Describe().Id, product); }
public static DateRange GetDateRange(SalesPeriod period, bool previous = false) { var dr = new DateRange(); dr.EndDate = DateTime.UtcNow.Date.AddDays(1).AddSeconds(-1); switch (period) { case SalesPeriod.Year: if (previous) { dr.EndDate = dr.EndDate.AddMonths(-12); } dr.StartDate = dr.EndDate.AddMonths(-12); break; case SalesPeriod.Quarter: if (previous) { dr.EndDate = dr.EndDate.AddMonths(-3); } dr.StartDate = dr.EndDate.AddMonths(-3); break; case SalesPeriod.Month: if (previous) { dr.EndDate = dr.EndDate.AddDays(-30); } dr.StartDate = dr.EndDate.AddDays(-30); break; case SalesPeriod.Week: if (previous) { dr.EndDate = dr.EndDate.AddDays(-7); } dr.StartDate = dr.EndDate.AddDays(-7); break; default: break; } return(dr); }
private static string DateToLabel(DateTime date, SalesPeriod period) { switch (period) { case SalesPeriod.Week: case SalesPeriod.TwoWeeks: return(date.ToString("MM/dd")); break; case SalesPeriod.TwoMonth: return(date.ToString("MM/dd")); break; case SalesPeriod.Year: case SalesPeriod.Overall: return(date.ToString("yyyy/MM")); break; } return("-"); }
/// <summary> /// 根据传入的PeriodGuid取得SDK交易错误日志 /// </summary> /// <param name="param"></param> /// <returns></returns> public static List <TransLog> GetTransLog(SalesPeriod param) { try { if (param == null) { throw new Exception("SalesPeriod is null"); } // 执行设置开票区间 List <TransLog> lstTransLog = factory.GetTransLog(param); return(lstTransLog); } catch (Exception ex) { LogHelper.WriteLog(new Log() { message = ex.Message }, "GetTransLog"); return(null); } }
public PerformanceInfoJson(PerformanceInfo performanceInfo, SalesPeriod period, ILocalizationHelper localization) { BouncedName = localization.GetString("Bounced"); AbandonedName = localization.GetString("Abandoned"); PurchasedName = localization.GetString("Purchased"); BouncedData = performanceInfo.BouncedData; AbandonedData = performanceInfo.AbandonedData; PurchasedData = performanceInfo.PurchasedData; ChartLabels = performanceInfo.ChartLabels; Events = performanceInfo.Events; Views = performanceInfo.Views.ToString("N0"); AddsToCart = performanceInfo.AddsToCart.ToString("N0"); Purchases = performanceInfo.Purchases.ToString("N0"); var bouncesPercentageChange = 0D; if (performanceInfo.ViewsPrev != 0) { bouncesPercentageChange = Math.Abs(performanceInfo.Views - performanceInfo.ViewsPrev) / (double)performanceInfo.ViewsPrev; } else if (performanceInfo.Views != 0) { bouncesPercentageChange = 1; } bouncesPercentageChange = Math.Round(bouncesPercentageChange, 2); ViewsPercentageChange = bouncesPercentageChange.ToString("p0"); var abandomentsPercentageChange = 0D; if (performanceInfo.AddsToCartPrev != 0) { abandomentsPercentageChange = Math.Abs(performanceInfo.AddsToCart - performanceInfo.AddsToCartPrev) / (double)performanceInfo.AddsToCartPrev; } else if (performanceInfo.AddsToCart != 0) { abandomentsPercentageChange = 1; } abandomentsPercentageChange = Math.Round(abandomentsPercentageChange, 2); AddsToCartPercentageChange = abandomentsPercentageChange.ToString("p0"); var purchasesPercentageChange = 0D; if (performanceInfo.PurchasesPrev != 0) { purchasesPercentageChange = Math.Abs(performanceInfo.Purchases - performanceInfo.PurchasesPrev) / (double)performanceInfo.PurchasesPrev; } else if (performanceInfo.Purchases != 0) { purchasesPercentageChange = 1; } purchasesPercentageChange = Math.Round(purchasesPercentageChange, 2); PurchasesPercentageChange = purchasesPercentageChange.ToString("p0"); var periodString = LocalizationUtils.GetSalesPeriodLower(period); var noChange = localization.GetFormattedString("NoChangeSinceLast", periodString); var lessThan = localization.GetFormattedString("LessSinceLast", periodString); var moreThan = localization.GetFormattedString("MoreSinceLast", periodString); ViewsComparison = noChange; if (Math.Abs(bouncesPercentageChange) >= 0.01) { IsViewsGrowing = performanceInfo.Views >= performanceInfo.ViewsPrev; ViewsComparison = IsViewsGrowing.Value ? moreThan : lessThan; } AddsToCartComparison = noChange; if (Math.Abs(abandomentsPercentageChange) >= 0.01) { IsAddsToCartGrowing = performanceInfo.AddsToCart >= performanceInfo.AddsToCartPrev; AddsToCartComparison = IsAddsToCartGrowing.Value ? moreThan : lessThan; } PurchasesComparison = noChange; if (Math.Abs(purchasesPercentageChange) >= 0.01) { IsPurchasesGrowing = performanceInfo.Purchases >= performanceInfo.PurchasesPrev; PurchasesComparison = IsPurchasesGrowing.Value ? moreThan : lessThan; } }
public static string GetSalesPeriodLower(SalesPeriod period) { return(SalesPeriodsLocalization.GetFormattedString(period.ToString()).ToLower()); }
/// <summary> /// Get sales for requested period. /// </summary> /// <param name="period">Period - year, month</param> /// <returns>Sales in period.</returns> public async Task <SalesPeriodInfo> GetSalesAsync(SalesPeriod period) { return(await GetSalesAsync(period.Value)); }