public List <List <string> > GeneratePreviewReport(int id) { var items = new List <List <string> >(); items.Add(new PromotionFeedDataItem().Header); // create the join using (var db = new ToolsContext()) { var input = (from i in db.BccSourceFeedItems // where i.AccountId == accountId select new { i.ClientProductId, i.CategoryLevel1, i.CategoryLevel2, i.CategoryLevel3, i.Brand, i.Price, i.ProductName, i.Type, i.AccountId, i.StockQuantity, i.SourceFeedPromoLine, i.PricePreviously, i.Link }).ToList(); var peProject = db.PromotionExtensionProjects.SingleOrDefault(x => x.Id == id); foreach (var r in input) { var lac = new PromotionFeedDataItem(); lac.FinalUrl = r.Link; lac.SetEndDate(DateTime.Now.AddDays(peProject.DefaultPromoDurationInDays)); lac.SetStartDate(DateTime.Now); lac.Language = "nl"; lac.MinimumOrderValue = ""; lac.Occasion = ""; lac.PromotionDiscountModifier = ""; var promotionText = GeneratePromotionTarget(r.ProductName, r.Brand, r.Type, r.CategoryLevel2, r.CategoryLevel3); if (promotionText == "") { promotionText = "-- TOO LONG -- " + r.ProductName; } if ("AEG,BEKO,LENOVO,LG,LIEBHERR,BABYLISS,NESPRESSO".Split(new[] { ',' }).Contains(r.Brand.ToUpper())) { promotionText = "-- TRADEMARK ISSUE -- " + r.ProductName; } lac.PromotionText = promotionText; var price = String.IsNullOrWhiteSpace(r.Price) ? (decimal)0 : Convert.ToDecimal(r.Price, CultureInfo.CreateSpecificCulture("en-us")); decimal priceOld = String.IsNullOrWhiteSpace(r.PricePreviously) ? (decimal)0 : Convert.ToDecimal(r.PricePreviously, CultureInfo.CreateSpecificCulture("en-us")); if (priceOld == (decimal)0 || price >= priceOld) { continue; } var discountPercentage = Math.Round(((priceOld - price) / priceOld) * 100); var discountAmount = Math.Round(priceOld - price, 2); lac.PromotionMoneyAmoutOff = ""; if (peProject.UseAmounts) { if (Convert.ToInt32(discountAmount) >= peProject.MinimumAmout || discountPercentage >= peProject.OrMinimumAmountPercentage) { lac.PromotionMoneyAmoutOff = lac.ConvertToPromotionExtensionPrice(discountAmount.ToString()); items.Add(lac.Row); } } lac.PromotionPercentOff = ""; if (peProject.UsePercentages && discountPercentage >= peProject.MinimumPercentage) { lac.PromotionPercentOff = discountPercentage.ToString(); items.Add(lac.Row); } } } return(items); }
public void GenerateReport(string accountId, string accountName, PromotionExtensionProject pep) { var items = new List <List <string> >(); var headers = new PromotionFeedDataItem().Header; // create the join using (var db = new ToolsContext()) { var input = (from i in db.BccSourceFeedItems // where i.AccountId == accountId select new { i.ClientProductId, i.CategoryLevel1, i.CategoryLevel2, i.CategoryLevel3, i.Brand, i.Price, i.ProductName, i.Type, i.AccountId, i.StockQuantity, i.SourceFeedPromoLine, i.PricePreviously, i.Link }).ToList(); var peProject = pep; foreach (var r in input) { if (accountId != null && r.AccountId != accountId) { continue; } int stock = 0; if (!Int32.TryParse(r.StockQuantity, out stock) || stock == 0) { continue; } if ("AEG,BEKO,LENOVO,LG,LIEBHERR,BABYLISS,NESPRESSO".Split(new[] { ',' }).Contains(r.Brand.ToUpper())) { continue; } var lac = new PromotionFeedDataItem(); lac.FinalUrl = r.Link; lac.SetEndDate(DateTime.Now.AddDays(peProject.DefaultPromoDurationInDays)); lac.SetStartDate(DateTime.Now); lac.Language = "nl"; lac.MinimumOrderValue = ""; lac.Occasion = ""; lac.PromotionDiscountModifier = ""; var promotionText = GeneratePromotionTarget(r.ProductName, r.Brand, r.Type, r.CategoryLevel2, r.CategoryLevel3); if (promotionText == "") { continue; } lac.PromotionText = promotionText; var price = String.IsNullOrWhiteSpace(r.Price) ? (decimal)0 : Convert.ToDecimal(r.Price, CultureInfo.CreateSpecificCulture("en-us")); decimal priceOld = String.IsNullOrWhiteSpace(r.PricePreviously) ? (decimal)0 : Convert.ToDecimal(r.PricePreviously, CultureInfo.CreateSpecificCulture("en-us")); if (priceOld == (decimal)0 || price >= priceOld) { continue; } var discountPercentage = Math.Round(((priceOld - price) / priceOld) * 100); var discountAmount = Math.Round(priceOld - price, 2); lac.PromotionMoneyAmoutOff = ""; if (peProject.UseAmounts) { if (Convert.ToInt32(discountAmount) >= peProject.MinimumAmout || discountPercentage >= peProject.OrMinimumAmountPercentage) { lac.PromotionMoneyAmoutOff = lac.ConvertToPromotionExtensionPrice(discountAmount.ToString()); items.Add(lac.Row); } } lac.PromotionPercentOff = ""; if (peProject.UsePercentages && discountPercentage >= peProject.MinimumPercentage) { lac.PromotionMoneyAmoutOff = ""; lac.PromotionPercentOff = Convert.ToInt32(discountPercentage).ToString() + ",000,000"; items.Add(lac.Row); } } } AddToFile(items, pep.PromotionExtensionFeedDestinationLocation.Replace(".csv", "-" + accountName.ToUpper() + ".csv"), headers, false); }