public void Save(ProductPricingTierViewModel productPricingTierViewModel) { ProductPricingTier pptVM = new ProductPricingTier(productPricingTierViewModel.Id) { Name = productPricingTierViewModel.Name, Code=productPricingTierViewModel.TierCode, Description=productPricingTierViewModel.Description }; _productPricingTierRepository.Save(pptVM); }
private ProductPricingTierViewModel Map(ProductPricingTier productPricingTier) { return new ProductPricingTierViewModel { Id = productPricingTier.Id, Name = productPricingTier.Name, Description=productPricingTier.Description, TierCode=productPricingTier.Code, IsActive = productPricingTier._Status == EntityStatus.Active ? true : false }; }
// mapping the entity ProductPricingTier public static ProductPricingTier Map(this tblPricingTier tier) { ProductPricingTier ppTier = new ProductPricingTier(tier.id) { Name = tier.Name, Code=tier.Code, Description=tier.Description }; ppTier._SetStatus((EntityStatus)tier.IM_Status); ppTier._SetDateCreated(tier.IM_DateCreated); ppTier._SetDateLastUpdated(tier.IM_DateLastUpdated); return ppTier; }
public decimal GetUnitPrice(Product p, ProductPricingTier tier) { decimal unitPrice; if (_freeOfChargeDiscountRepository.IsProductFreeOfCharge(p.Id)) { return 0m; } if (p is ConsolidatedProduct) try { unitPrice = ((ConsolidatedProduct)p).ProductPrice(tier); } catch { unitPrice = 0m; } else try { unitPrice = p.ProductPrice(tier); } catch { unitPrice = 0m; } return unitPrice; }
private IEnumerable<ProductPricing> ConstructDomainEntities(IEnumerable<PricingImport> entities) { var newpricing = new List<ProductPricing>(); foreach (var importentity in entities) { try { var product = ObjectFactory.GetInstance<IPricingMapper>().GetProduct(importentity.ProductCode); if (product != null) { if (!string.IsNullOrEmpty(importentity.PricingTireCode)) { ProductPricingTier tire = ObjectFactory.GetInstance<IProductPricingTierRepository>().GetAll(true). FirstOrDefault( p => p.Code != null && p.Code.ToLower() == importentity.PricingTireCode.ToLower()); if (tire == null) { tire = new ProductPricingTier(Guid.NewGuid()) { Name = importentity.PricingTireCode, Code = importentity.PricingTireCode, Description = importentity.PricingTireCode, }; try { ObjectFactory.GetInstance<IProductPricingTierRepository>().Save(tire); } catch { } } if (Update(tire.Id, product.id, importentity.SellingPrice, product.ExFactoryPrice)) { var pricing = ObjectFactory.GetInstance<IProductPricingRepository>().GetByProductAndTierId( product.id, tire.Id); if (pricing != null) { pricing.ProductPricingItems.Clear(); pricing.ProductPricingItems.Add( new ProductPricing.ProductPricingItem(Guid.NewGuid()) { EffectiveDate = DateTime.Now, ExFactoryRate = product.ExFactoryPrice, SellingPrice = importentity.SellingPrice }); ObjectFactory.GetInstance<IPricingMapper>().Update(pricing); } else { var newprice = ObjectFactory.GetInstance<IProductPricingFactory>().CreateProductPricing( product.id, tire.Id, product.ExFactoryPrice, importentity.SellingPrice, DateTime.Now); if (newprice != null) newpricing.Add(newprice); } } } else { #region default pricing tier var pricingTierDefault = ObjectFactory.GetInstance<IProductPricingTierRepository>().GetAll(true). FirstOrDefault( p => p.Name == "DefaultPricingTier"); if (pricingTierDefault == null) { pricingTierDefault = new ProductPricingTier(Guid.NewGuid()) { Name = "DefaultPricingTier", Code = "DefaultPricingTier", Description = "DefaultPricingTier", }; try { ObjectFactory.GetInstance<IProductPricingTierRepository>().Save( pricingTierDefault); } catch { } } if (Update(pricingTierDefault.Id, product.id, product.ExFactoryPrice, product.ExFactoryPrice)) { var defaultPrice = ObjectFactory.GetInstance<IProductPricingRepository>().GetByProductAndTierId( product.id, pricingTierDefault.Id); if (defaultPrice != null) { defaultPrice.ProductPricingItems.Clear(); defaultPrice.ProductPricingItems.Add( new ProductPricing.ProductPricingItem(Guid.NewGuid()) { EffectiveDate = DateTime.Now, ExFactoryRate = product.ExFactoryPrice, SellingPrice = product.ExFactoryPrice }); ObjectFactory.GetInstance<IPricingMapper>().Update(defaultPrice); } else { defaultPrice = ObjectFactory.GetInstance<IProductPricingFactory>().CreateProductPricing( product.id, pricingTierDefault.Id, product.ExFactoryPrice, product.ExFactoryPrice, DateTime.Now); if (defaultPrice != null && !newpricing.Any( p => p.Tier.Id == pricingTierDefault.Id && p.ProductRef.ProductId == product.id)) newpricing.Add(defaultPrice); } } #endregion } } else { if ( !_failedPricings.Any( p => p.Equals(importentity.ProductCode, StringComparison.CurrentCultureIgnoreCase))) { _failedPricings.Add(importentity.ProductCode); } } } catch (Exception ex) { } } return newpricing; }
public override decimal ProductPrice(ProductPricingTier tier) { return ProductDetails.Sum(n => n.Product.ProductPrice(tier) * n.QuantityPerConsolidatedProduct); }
private void AssertProductPricingTier(ProductPricingTier productPricingTierX, ProductPricingTier ProductPricingTierY) { Assert.IsNotNull(productPricingTierX); Assert.AreEqual(productPricingTierX.Code, ProductPricingTierY.Code); Assert.AreEqual(productPricingTierX.Name, ProductPricingTierY.Name); Assert.AreEqual(productPricingTierX.Description, ProductPricingTierY.Description); Assert.AreEqual(productPricingTierX._Status, ProductPricingTierY._Status); }
protected ProductPricingTier Map(PricingTierImport pricingTierImport) { var exists = Queryable.FirstOrDefault(_context.tblPricingTier, p => p.Code == pricingTierImport.Code); Guid id = exists != null ? exists.id : Guid.NewGuid(); var productPricingTier = new ProductPricingTier(id); productPricingTier.Description = pricingTierImport.Description; productPricingTier.Name = pricingTierImport.Name; productPricingTier.Code = pricingTierImport.Code; return productPricingTier; }
private Outlet[] ContsructEntities(IEnumerable<OutletImport> entities) { var temp = new List<Outlet>(); var defaultDistributr =ObjectFactory.GetInstance<ICostCentreRepository>() .GetByCode("PZ Cussons EA", CostCentreType.Distributor); var allRoutes = ObjectFactory.GetInstance<IRouteRepository>().GetAll().ToList(); var outletCategories = ObjectFactory.GetInstance<IOutletCategoryRepository>().GetAll().ToList(); foreach (var importentity in entities) { var domainEntity = ObjectFactory.GetInstance<ICostCentreRepository>().GetByCode(importentity.OutletCode, CostCentreType.Outlet, true) as Outlet; bool IsNew = false; if(domainEntity==null) { domainEntity = new Outlet(Guid.NewGuid()); IsNew = true; } #region Routes if (domainEntity != null && domainEntity.Route == null) { domainEntity.Route = allRoutes.FirstOrDefault( p => p.Name != null && p.Name.ToLower().Trim() == importentity.RouteName.Trim().ToLower()); } if (domainEntity.Route != null && !string.IsNullOrEmpty(importentity.RouteName)) { var newRoute = allRoutes.FirstOrDefault(p => p.Name.Trim().ToLower() == importentity.RouteName.Trim().ToLower()); if (newRoute != null) domainEntity.Route = newRoute; } if (domainEntity.Route == null && importentity.RouteName.StartsWith("SALES VA")) domainEntity.Route = allRoutes.FirstOrDefault(p => p.Name.Contains("SALES VA")); if (domainEntity.Route == null && !string.IsNullOrEmpty(importentity.RouteName)) { var region = ObjectFactory.GetInstance<IRegionRepository>().GetAll(true).FirstOrDefault(p => p.Name == "Region A"); if (region == null) { region = new Region(Guid.NewGuid()) { Country = ObjectFactory.GetInstance<ICountryRepository>().GetAll(true).FirstOrDefault(p => p.Name == "Kenya"), Name = "", Description = "" }; try { ObjectFactory.GetInstance<IRegionRepository>().Save(region); } catch { } } var route = new Route(Guid.NewGuid()) { Name = importentity.RouteName, Code = importentity.RouteName, Region = region }; try { ObjectFactory.GetInstance<IRouteRepository>().Save(route); } catch { } domainEntity.Route = route; } try { ObjectFactory.GetInstance<IRouteRepository>().Save(domainEntity.Route); } catch { } #endregion if (defaultDistributr == null) throw new ArgumentNullException("distributor"); domainEntity.ParentCostCentre = new CostCentreRef() { Id = defaultDistributr.Id }; if (domainEntity.OutletCategory == null) { OutletCategory category = outletCategories .FirstOrDefault( s => s.Name != null && s.Name == "defaultoutletcategory"); if (category == null) { category = new OutletCategory(Guid.NewGuid()) { Name = string.IsNullOrEmpty(importentity.Name) ? "defaultoutletcategory" : importentity.Name, Code = string.IsNullOrEmpty(importentity.Name) ? "defaultoutletcategory" : importentity.Name }; try { ObjectFactory.GetInstance<IOutletCategoryRepository>().Save(category,true); } catch { } } domainEntity.OutletCategory = category; } if (domainEntity.OutletType == null) { OutletType type =ObjectFactory.GetInstance<IOutletTypeRepository>().GetAll(true).FirstOrDefault( p => p.Name != null && p.Name == "defaultoutlettype"); if (type == null) { type = new OutletType(Guid.NewGuid()) { Name = string.IsNullOrEmpty(importentity.Name) ? "defaultoutlettype" : importentity.Name, Code = string.IsNullOrEmpty(importentity.Name) ? "defaultoutlettype" : importentity.Name }; try { ObjectFactory.GetInstance<IOutletTypeRepository>().Save(type); } catch { } } domainEntity.OutletType = type; } if (domainEntity.OutletProductPricingTier == null) { ProductPricingTier tire =ObjectFactory.GetInstance<IProductPricingTierRepository>() .GetAll(true).FirstOrDefault( p => p.Code != null && p.Code.Trim() == importentity.Currency.Trim()); if (tire == null) { tire = new ProductPricingTier(Guid.NewGuid()) { Name = importentity.Currency.Trim(), Code = importentity.Currency.Trim(), Description = importentity.Currency.Trim(), }; try { ObjectFactory.GetInstance<IProductPricingTierRepository>().Save(tire); } catch { } } domainEntity.OutletProductPricingTier = tire; } if (domainEntity.VatClass == null) { VATClass productVat = ObjectFactory.GetInstance<IVATClassRepository>().GetAll(true). FirstOrDefault( p => p.Name != null && p.Name == "defaultVAT"); if (productVat == null) { var viatItem = new VATClass.VATClassItem(Guid.NewGuid()) { EffectiveDate = DateTime.Now, Rate = 0, }; productVat = new VATClass(Guid.NewGuid()) { Name = "defaultVAT", VatClass = "defaultVAT", }; productVat.VATClassItems.Add(viatItem); try { ObjectFactory.GetInstance<IVATClassRepository>().Save(productVat); } catch { } } domainEntity.VatClass = productVat; } domainEntity._Status =EntityStatus.Active; //GetStatus(importentity.Status); domainEntity.Name = importentity.Name.Trim(); domainEntity.CostCentreCode = importentity.OutletCode.Trim(); temp.Add(domainEntity); } return temp.ToArray(); }
private async Task<IEnumerable<ProductPricing>> ConstructPricingDomainEntities(IEnumerable<AfcoProductPricingImport> entities) { return await Task.Run(() => { var newpricing = new List<ProductPricing>(); var exisitingPricing = _productPricingRepository.GetAll(true).ToList(); var products = _productRepository.GetAll(true).ToList(); var tiers = _productPricingTierRepository.GetAll(true).ToList(); foreach (var entity in entities) { var product = products .FirstOrDefault(p => p.ProductCode.ToLower() == entity.ProductCode.ToLower()); if (product != null) { var pricingExist = exisitingPricing.FirstOrDefault( p => p.ProductRef.ProductId == product.Id && (p.Tier.Code != null && p.Tier.Code.ToLower()== "afco")); if (pricingExist == null) { var tire = tiers .FirstOrDefault( p => p.Code.Equals("Afco", StringComparison.CurrentCultureIgnoreCase)); if (tire == null) { tire = new ProductPricingTier(Guid.NewGuid()) { Name = "Afco", Code = "Afco", Description = "Afco", }; try { _productPricingTierRepository.Save(tire); } catch { } } pricingExist = new ProductPricing(Guid.NewGuid()) { ProductRef = new ProductRef() { ProductId = product.Id }, Tier = tire }; } pricingExist.ProductPricingItems .Add(new ProductPricing.ProductPricingItem(Guid.NewGuid()) { EffectiveDate = DateTime.Now, ExFactoryRate =product.ExFactoryPrice, SellingPrice = entity.SellingPrice }); newpricing.Add(pricingExist); } else { if (!_failedImpoprts.Any(p => p.Equals(entity.ProductCode,StringComparison.CurrentCultureIgnoreCase))) { _failedImpoprts.Add(entity.ProductCode); } } } return newpricing; }); }
private void UpdateDefaultTierPricing(Guid productId, decimal exfactory, decimal sellingprice) { var pricingTierDefault = ObjectFactory.GetInstance<IProductPricingTierRepository>().GetAll(true). FirstOrDefault( p => p.Name == "DefaultPricingTier"); if (pricingTierDefault == null) { pricingTierDefault = new ProductPricingTier(Guid.NewGuid()) { Name = "DefaultPricingTier", Code = "DefaultPricingTier", Description = "DefaultPricingTier", }; try { ObjectFactory.GetInstance<IProductPricingTierRepository>().Save(pricingTierDefault); } catch { } } // var exist = ObjectFactory.GetInstance<IProductPricingRepository>().GetByProductAndTierId(productId, // pricingTierDefault. // Id); // if (exist == null) // { // exist = ObjectFactory.GetInstance<IProductPricingFactory>().CreateProductPricing( // productId, pricingTierDefault.Id, // exfactory, // sellingprice, // DateTime.Now); // ObjectFactory.GetInstance<IProductPricingRepository>().Save(exist); // } // else // { // exist.ProductPricingItems.Clear(); // exist.ProductPricingItems.Add( // new ProductPricing.ProductPricingItem(Guid.NewGuid()) // { // EffectiveDate = DateTime.Now, // ExFactoryRate = exfactory, // SellingPrice = sellingprice // }); // ObjectFactory.GetInstance<IPricingMapper>().Update(exist); // } }
public override bool IsAvailableForSale(ProductPricingTier tier) { bool available = false; available = ProductDetails.Any(n => !n.Product.IsAvailableForSale(tier)); return available ? false : true; }
//cn public decimal ProductVATRate(ProductPricingTier ppt, Outlet outlet = null) { decimal vatRate = 0; decimal totalVat = 0; foreach (var item in ProductDetails) { decimal itemVATRate = 0; decimal itemUnitVATValue = 0; decimal itemTotalVATValue = 0; if (item.Product.VATClass != null) { itemVATRate = GetProductVATRate(item.Product, outlet); itemUnitVATValue = item.Product.ProductPrice(ppt) * itemVATRate; itemTotalVATValue = itemUnitVATValue*item.QuantityPerConsolidatedProduct; } totalVat += itemTotalVATValue; } decimal unitPrice = this.ProductPrice(ppt); if (unitPrice > 0) vatRate = (totalVat/unitPrice); return vatRate; }
public void ProductDiscountRepositoryUnitTest() { using (var tra = new TransactionScope()) { Trace.WriteLine("START PRODUCT DISCOUNT REPOSITORY UNIT TEST...."); //Create ProductDiscount newProductDiscount = _testHelper.BuildProductDiscount(); Guid newProductDiscountId = _productDiscountRepository.Save(newProductDiscount); //GetById ProductDiscount createdProductDiscount = _productDiscountRepository.GetById(newProductDiscountId); AssertProductDiscount(createdProductDiscount, newProductDiscount); Trace.WriteLine(string.Format("ProductDiscount GetById[{0}], ProductRef[{1}]", createdProductDiscount.Id, createdProductDiscount.ProductRef)); //Update var productPricingTier = new ProductPricingTier() { Id = Guid.NewGuid(), _DateCreated = DateTime.Now, _DateLastUpdated = DateTime.Now, _Status = EntityStatus.Active, Code = "ppTierCode0013", Description = "Tier0012", Name = "Tier00023" }; Guid productPricingTierId = _testHelper.Ioc<IProductPricingTierRepository>().Save(productPricingTier); ProductPricingTier productPricingTierUpedate = _testHelper.Ioc<IProductPricingTierRepository>().GetById(productPricingTierId); var productDiscountToUpdate = createdProductDiscount; productDiscountToUpdate._DateCreated = DateTime.Now; productDiscountToUpdate._DateLastUpdated = DateTime.Now; productDiscountToUpdate._Status = EntityStatus.Active; productDiscountToUpdate.Tier = productPricingTierUpedate; Guid updatedProductDiscountId = _productDiscountRepository.Save(productDiscountToUpdate); ProductDiscount updatedProductDiscount = _productDiscountRepository.GetById(updatedProductDiscountId); AssertProductDiscountUpdate(updatedProductDiscount, productDiscountToUpdate); Trace.WriteLine(string.Format("Updated ProductDiscountId[{0}]", updatedProductDiscountId)); //Query var queryResult = _productDiscountRepository.Query(new QueryStandard() { }); Assert.GreaterOrEqual(queryResult.Count, 1); Trace.WriteLine(string.Format("Product Discount Repository Query Count[{0}]", queryResult.Count)); //Set As Inactive _productDiscountRepository.SetInactive(updatedProductDiscount); ProductDiscount inactiveProductDiscount = _productDiscountRepository.GetById(updatedProductDiscountId); Assert.AreEqual(inactiveProductDiscount._Status, EntityStatus.Inactive); Trace.WriteLine(string.Format("Product Discount Status[{0}]", inactiveProductDiscount._Status)); //Set As Active _productDiscountRepository.SetActive(updatedProductDiscount); ProductDiscount activeProductDiscount = _productDiscountRepository.GetById(updatedProductDiscountId); Assert.AreEqual(activeProductDiscount._Status, EntityStatus.Active); Trace.WriteLine(string.Format("Product Discount Status[{0}]", activeProductDiscount._Status)); //Set As Deleted _productDiscountRepository.SetAsDeleted(updatedProductDiscount); ProductDiscount deletedProductDiscount = _productDiscountRepository.GetById(updatedProductDiscountId); Assert.AreEqual(deletedProductDiscount._Status, EntityStatus.Deleted); Trace.WriteLine(string.Format("Deleted Product Discount Status[{0}]", deletedProductDiscount._Status)); Trace.WriteLine(string.Format("Product Discount Repository Unit Tests Successful")); _testHelper.Ioc<ICacheProvider>().Reset(); } }
protected Guid AddPricingTier(string name, string code, string description) { ProductPricingTier pptier = new ProductPricingTier(Guid.NewGuid()) { Name = name, Code = code, Description = description }; return _ProductPricingTierRepository.Save(pptier); }
protected ValidationResultInfo Validate(ProductPricingTier productPricingTier) { return _productPricingTierRepository.Validate(productPricingTier); }
public void LoadById(Guid id) { if (id == Guid.Empty) { InitializeBlank(); } else { using (StructureMap.IContainer c = NestedContainer) { outlet = Using<ICostCentreRepository>(c).GetById(id) as Outlet; if (outlet == null) { InitializeBlank(); } else { PageTitle = GetLocalText("sl.outlet.edit.editing.title"); // "Edit Outlet"; Id = outlet.Id; Name = outlet.Name; OutletCode = outlet.CostCentreCode; Latitude = outlet.Latitude; Longitude = outlet.Longitude; IsApproved = outlet._Status ==EntityStatus.Active; CanApprove = !IsApproved; //load all items to combos DistributorRoutes.Clear(); var route = new Route(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.route.default") /* "--Please Select A Route --"*/ }; DistributorRoutes.Add(route); Using<IRouteRepository>(c).GetAll() .ToList() .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorRoutes.Add(n)); try { SelectedRoute = DistributorRoutes.FirstOrDefault(n => n.Id == outlet.Route.Id); } catch { //route deactivated! SelectedRoute = route; } DistributorOutletCategories.Clear(); Using<IOutletCategoryRepository>(c).GetAll() .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorOutletCategories.Add(n)); SelectedOutletCategory = DistributorOutletCategories.FirstOrDefault(n => n.Id == outlet.OutletCategory.Id); DistributorOutletType.Clear(); Using<IOutletTypeRepository>(c).GetAll() .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorOutletType.Add(n)); SelectedOutletType = DistributorOutletType.FirstOrDefault(n => n.Id == outlet.OutletType.Id); DistributorProductPricingTier.Clear(); Using<IProductPricingTierRepository>(c).GetAll() .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorProductPricingTier.Add(n)); var ppt = new ProductPricingTier(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.tier.default") /* "--Please Select Product Pricing Tier--"*/ }; DistributorProductPricingTier.Add(ppt); try { SelectedProductPricingTier = DistributorProductPricingTier.FirstOrDefault( n => n.Id == outlet.OutletProductPricingTier.Id); } catch { SelectedProductPricingTier = ppt; } VATClasses.Clear(); var vatClass = new VATClass(Guid.Empty) { VatClass = GetLocalText("sl.outlet.edit.vatclass.default") /*"--NONE--"*/ }; VATClasses.Add(vatClass); Using<IVATClassRepository>(c).GetAll().OrderBy(n => n.VatClass).ToList().ForEach(n => VATClasses.Add(n)); try { SelectedVATRate = VATClasses.First(n => n.Id == outlet.VatClass.Id); } catch { SelectedVATRate = vatClass; } DiscountGroups.Clear(); var discountGroup = new DiscountGroup(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.discgp") /*"--NONE--"*/ }; SelectedDiscountGroup = discountGroup; DiscountGroups.Add(discountGroup); Using<IDiscountGroupRepository>(c).GetAll().OrderBy(n => n.Name).ToList().ForEach(n => DiscountGroups.Add(n)); try { SelectedDiscountGroup = DiscountGroups.First(n => n.Id == outlet.DiscountGroup.Id); } catch { SelectedDiscountGroup = discountGroup; } LoadShipToAddress(); } } } }
/*>*/ public ProductPricingTierDTO Map(ProductPricingTier productPricingTier) { if (productPricingTier == null) return null; return Mapper.Map<ProductPricingTier, ProductPricingTierDTO>(productPricingTier); }
void DoLoad() { using (StructureMap.IContainer c = NestedContainer) { Config config = GetConfigParams(); DistributorRoutes.Clear(); var route = new Route(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.route.default") /* "--Please Select A Route --"*/ }; SelectedRoute = route; DistributorRoutes.Add(route); //should only get for current distributor Region region =null; if(config.AppId == Core.VirtualCityApp.Agrimanagr) region = ((Hub) Using<ICostCentreRepository>(c).GetById(Using<IConfigService>(c).Load().CostCentreId)). Region; else if(config.AppId == Core.VirtualCityApp.Ditributr) region = ((Distributor) Using<ICostCentreRepository>(c).GetById(Using<IConfigService>(c).Load().CostCentreId)). Region; Using<IRouteRepository>(c).GetAll().Where(q => q.Region.Id == region.Id) .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorRoutes.Add(n)); DistributorOutletCategories.Clear(); var outletCategory = new OutletCategory(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.category.default") /*"--Please Select an Outlet--"*/ }; SelectedOutletCategory = outletCategory; DistributorOutletCategories.Add(outletCategory); Using<IOutletCategoryRepository>(c).GetAll() .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorOutletCategories.Add(n)); DistributorOutletType.Clear(); var outletType = new OutletType(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.type.default") /*"--Please Select an Outlet Type--"*/ }; SelectedOutletType = outletType; DistributorOutletType.Add(outletType); Using<IOutletTypeRepository>(c).GetAll().OrderBy(n => n.Name).ToList().ForEach(n => DistributorOutletType.Add(n)); DistributorProductPricingTier.Clear(); var ppt = new ProductPricingTier(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.tier.default") /* "--Please Select Product Pricing Tier--"*/ }; SelectedProductPricingTier = ppt; DistributorProductPricingTier.Add(ppt); Using<IProductPricingTierRepository>(c).GetAll() .OrderBy(n => n.Name) .ToList() .ForEach(n => DistributorProductPricingTier.Add(n)); VATClasses.Clear(); var vatClass = new VATClass(Guid.Empty) { VatClass = GetLocalText("sl.outlet.edit.vatclass.default") /*"--NONE--"*/ }; SelectedVATRate = vatClass; VATClasses.Add(vatClass); Using<IVATClassRepository>(c).GetAll().OrderBy(n => n.VatClass).ToList().ForEach(n => VATClasses.Add(n)); DiscountGroups.Clear(); var discountGroup = new DiscountGroup(Guid.Empty) { Name = GetLocalText("sl.outlet.edit.discgp") /*"--NONE--"*/ }; SelectedDiscountGroup = discountGroup; DiscountGroups.Add(discountGroup); Using<IDiscountGroupRepository>(c).GetAll().OrderBy(n => n.Name).ToList().ForEach(n => DiscountGroups.Add(n)); ShippingAddresses.Clear(); DeletedAddresses.Clear(); } }
private ProductPricing[] ConstructPricings(IEnumerable<ProductImport> entities) { var newpricing = new List<ProductPricing>(); var exisitingPricing = ObjectFactory.GetInstance<IProductPricingRepository>().GetAll(true).ToList(); var pricingTiers = ObjectFactory.GetInstance<IProductPricingTierRepository>().GetAll(true).ToList(); foreach (var entity in entities) { if (!string.IsNullOrEmpty(entity.ProductCode)) { var product =ObjectFactory.GetInstance<CokeDataContext>().tblProduct.FirstOrDefault( p => p.ProductCode.ToLower() == entity.ProductCode.ToLower()); if (product != null) { var pricingExist = exisitingPricing.FirstOrDefault( p => p.ProductRef.ProductId == product.id && p.Tier.Code == "KES"); bool isNew = false; if (pricingExist == null) { var tire = pricingTiers .FirstOrDefault( p => p.Code.Equals("KES", StringComparison. CurrentCultureIgnoreCase)) ?? pricingTiers.FirstOrDefault( p => p.Code != null && p.Name == "DefaultPricingTire"); if (tire == null) { tire = new ProductPricingTier(Guid.NewGuid()) { Name = "DefaultPricingTire", Code = "DefaultPricingTire", Description = "DefaultPricingTire", }; try { ObjectFactory.GetInstance<IProductPricingTierRepository>().Save(tire); } catch { } } pricingExist = new ProductPricing(Guid.NewGuid()) { ProductRef = new ProductRef() {ProductId = product.id}, Tier = tire }; isNew = true; } if(isNew) { pricingExist.ProductPricingItems .Add(new ProductPricing.ProductPricingItem(Guid.NewGuid()) { EffectiveDate = DateTime.Now, ExFactoryRate = entity.ExFactoryPrice, SellingPrice = entity.SellingPrice }); pricingExist._Status = EntityStatus.Active; newpricing.Add(pricingExist); } else if (HasProductPricingChanged(pricingExist)) { pricingExist.ProductPricingItems .Add(new ProductPricing.ProductPricingItem(Guid.NewGuid()) { EffectiveDate = DateTime.Now, ExFactoryRate = entity.ExFactoryPrice, SellingPrice = entity.SellingPrice }); pricingExist._Status = EntityStatus.Active; newpricing.Add(pricingExist); } } else { if ( !_failedImpoprts.Any( p => p.Equals(entity.ProductCode, StringComparison.CurrentCultureIgnoreCase))) { _failedImpoprts.Add(entity.ProductCode); } } } else { _failedImpoprts.Add(entity.Description); } } return newpricing.ToArray(); }
public override decimal TotalExFactoryValue(ProductPricingTier tier) { return ProductDetails.Sum(n => n.Product.TotalExFactoryValue(tier) * n.QuantityPerConsolidatedProduct); }