public override string GetTitle() { if (!string.IsNullOrEmpty(Request.QueryString["Id"])) { int id = Convert.ToInt32(Request.QueryString["Id"]); PriceCalculation pc = ControllerManager.PriceCalculation.GetById(id); string title = Resource.Business.GetString("PricePoliticTitle"); if (pc != null) { if (pc.Provider != null) { title = title + " - " + pc.Provider.Name; } if (pc.CategoryBase != null) { title = title + " - " + pc.CategoryBase.Name; } return(title); } return(Resource.Business.GetString("PricePoliticTitle")); } return(Resource.Business.GetString("PricePoliticTitle")); }
protected void Page_Load(object sender, EventArgs e) { var catalogContext = ObjectFactory.Instance.Resolve <ICatalogContext>(); var imageService = ObjectFactory.Instance.Resolve <IImageService>(); if (CurrentProduct == null) { Visible = false; return; } string url = CatalogLibrary.GetNiceUrlForProduct(CurrentProduct, catalogContext.CurrentCategory); PriceCalculation price = CatalogLibrary.CalculatePrice(CurrentProduct); if (!string.IsNullOrWhiteSpace(CurrentProduct.ThumbnailImageMediaId)) { productImage.ImageUrl = imageService.GetImage(CurrentProduct.ThumbnailImageMediaId).Url; hlImage.Visible = true; } hlProduct.Text = CurrentProduct.DisplayName(); hlProduct.NavigateUrl = url; hlViewMore.NavigateUrl = url; hlImage.NavigateUrl = url; litPrice.Text = price?.YourPrice?.Amount.ToString() ?? "-"; if (price?.YourTax != null) { litTax.Text = price.YourTax.ToString(); } }
private void LoadFields() { if (PoliticId != 0) { PriceCalculation pc = ControllerManager.PriceCalculation.GetById(PoliticId); if (pc != null) { PriceCalculation pc2 = ControllerManager.PriceCalculation.Get(pc.Provider, pc.CategoryBase, 2); txtFormula1.Text = pc.Formula; if (pc2 != null) { txtFormula2.Text = pc2.Formula; } if (pc.CategoryBase != null) { ddlCategoryLinked.Values = pc.CategoryBase.ID; } if (pc.Provider != null) { ddlProvider.SelectedValue = ddlProvider.Items.FindByValue(pc.Provider.ID.ToString()).Value; } } else { Utils.ShowMessage(Page, "La política de precios seleccionada no existe.", Utils.MessageType.Error); } } }
protected override void OnAfterSaveEntity(PriceCalculation calculation) { var targetCalculationLookup = Lookups.SingleOrDefault(priceCalculationLookup => priceCalculationLookup.Id == calculation.Id); if (targetCalculationLookup != null) { targetCalculationLookup.Refresh(calculation); return; } var author = calculation.PriceCalculationItems.FirstOrDefault()?.SalesUnits.FirstOrDefault()?.Project.Manager; var canWath = author?.Id == GlobalAppProperties.User.Id && calculation.TaskCloseMoment.HasValue; var canCalc = calculation.TaskOpenMoment.HasValue && (GlobalAppProperties.User.RoleCurrent == Role.Admin || GlobalAppProperties.User.RoleCurrent == Role.Pricer); if (canWath || canCalc) { if (Lookups is ObservableCollection <PriceCalculationLookup> collection) { if (!Lookups.Select(lookup => lookup.Entity).ContainsById(calculation)) { collection.Insert(0, new PriceCalculationLookup(calculation)); } } return; } }
public void TestMethodGetSaleRate() { _priceCalculation = new PriceCalculation(1, 0.01020304m, 0.01020404m, 0); Assert.AreEqual(0.0000980100048612962411202936m, _priceCalculation.GetSaleRate()); _priceCalculation = new PriceCalculation(1, 0.01020304m, 0.01060404m, 0); Assert.AreEqual(0.0393020119493797926892377174m, _priceCalculation.GetSaleRate()); }
public PriceCalculation GetPriceCalculation() { List <PriceItem> priceItems = priceItemsService.GetAll(); PriceCalculationsHelper priceCalculationsHelper = new PriceCalculationsHelper(); PriceCalculation priceCalculation = priceCalculationsHelper.GetPriceCalculation(priceItems); return(priceCalculation); }
public PriceItem(PriceCalculation priceCalculation, PriceCalculationItem priceCalculationItem) { if (priceCalculation.TaskCloseMoment != null) { FinishDate = priceCalculation.TaskCloseMoment.Value; } PriceCalculationItem = priceCalculationItem; }
//Calculate public PriceCalculation GetPriceCalculation(List <PriceItem> priceItems) { PriceCalculation priceCalculation = new PriceCalculation(); priceCalculation.PriceMin = GetMinPrice(priceItems); priceCalculation.PriceMax = GetMaxPrice(priceItems); priceCalculation.PriceAverage = GetAvgPrice(priceItems); priceCalculation.MostExpensiveSixtyMinutesPeriod = GetMostExpensiveSixtyMinutesPeriod(priceItems); return(priceCalculation); }
public ActionResult CalculatePriceForVariant(ProductPriceCalculatePriceForVariantViewModel variantPriceCalculationDetails) { Product variant = _productRepository.Select(x => x.VariantSku == variantPriceCalculationDetails.ProductVariantSku && x.Sku == variantPriceCalculationDetails.ProductSku).FirstOrDefault(); var catalog = _catalogLibraryInternal.GetCatalog(variantPriceCalculationDetails.CatalogId); PriceCalculation priceCalculation = new PriceCalculation(variant, catalog); var yourPrice = priceCalculation.YourPrice.Amount.ToString(); var yourTax = priceCalculation.YourTax.ToString(); return(Json(new { YourPrice = yourPrice, Tax = yourTax })); }
public ActionResult CalculatePrice(ProductCardRenderingViewModel priceCalculationDetails) { var product = _productRepository.Select(x => x.Sku == priceCalculationDetails.ProductSku && x.ParentProduct == null).FirstOrDefault(); var catalog = _catalogLibraryInternal.GetCatalog(priceCalculationDetails.CatalogId); PriceCalculation priceCalculation = new PriceCalculation(product, catalog); var yourPrice = priceCalculation.YourPrice.Amount.ToString(); var yourTax = priceCalculation.YourTax.ToString(); var discount = priceCalculation.Discount.Amount.ToString(); return(Json(new { YourPrice = yourPrice, Tax = yourTax, Discount = discount })); }
public void PriceCalculatorTest(int[] quantities, double Subtotoal, double Totaldisocunt, double TotalPrice) { for (int i = 0; i <= 3; i++) { TestData[i].Quantiity = quantities[i]; } PriceCalculation totoalAmount = calculateAmount.CalculateTotalPrice(TestData); Assert.NotNull(totoalAmount); Assert.AreEqual(Subtotoal, totoalAmount.Subtotoal); Assert.AreEqual(Totaldisocunt, totoalAmount.TotalDiscount); Assert.AreEqual(TotalPrice, totoalAmount.Subtotoal - totoalAmount.TotalDiscount); }
private static bool CalculatePrice(Order order) { bool result = true; var priceCalculation = new PriceCalculation(); var price = priceCalculation.CalculatePrice(order.ArticleId, order.Quantity); if (price == -1m) { result = false; } return(result); }
public void TestPriceCalculationChargedDiscountsNoReservations() { DateTime reservationDateStart = new DateTime(2012, 01, 23, 15, 00, 00); DateTime reservationDateEnd = new DateTime(2012, 01, 23, 18, 00, 00); Arrangement arrangement = new HourlyArrangement(100, HourlyArrangementType.Airport, reservationDateStart, reservationDateEnd); Limousine limoTest = new Limousine("FIAT 500", 100, new List <Arrangement>() { }); List <Discount> vip = new List <Discount>() { new Discount(2, 0.05f), new Discount(7, 0.075f), new Discount(15, 0.1f) }; Category categorieTestVIP = new Category(vip, CategorieType.vip); Client clientTest = new Client("Tom", "684432685", "Jef De Belderlaan 6", categorieTestVIP); PriceCalculation priceTest = new PriceCalculation(arrangement, limoTest, clientTest, reservationDateStart, reservationDateEnd); priceTest.ChargedDiscounts.ShouldBe(0); }
public void TestMethod3() { int expected = 280; List <ProductToBuy> listProduct = new List <ProductToBuy>(); PriceCalculation priceCalculation = new PriceCalculation(); ProductToBuy productToBuy = new ProductToBuy(); JSONParser parser = new JSONParser(); dynamic promotionEngineModel = parser.ParseJSON(); priceCalculation.UnitPrice = promotionEngineModel.UnitPrice; priceCalculation.ActivePromotions = promotionEngineModel.ActivePromotions; productToBuy.ProuductName = "A"; productToBuy.ProductQuantity = 3; listProduct.Add(productToBuy); productToBuy = new ProductToBuy(); productToBuy.ProuductName = "B"; productToBuy.ProductQuantity = 5; listProduct.Add(productToBuy); productToBuy = new ProductToBuy(); productToBuy.ProuductName = "C"; productToBuy.ProductQuantity = 1; listProduct.Add(productToBuy); productToBuy = new ProductToBuy(); productToBuy.ProuductName = "D"; productToBuy.ProductQuantity = 1; listProduct.Add(productToBuy); int actual = priceCalculation.GetTotalPrice(listProduct); Assert.AreEqual(expected, actual, "Test Method 3 failed"); }
public void RentHeavyProductForFiveDays() { var price = PriceCalculation.EquipmentPrice(Types.Heavy, 5); Assert.AreEqual(400, price); }
public void TestCleanup() { _priceCalculation = null; }
public void TestMethodGetSaleRateTotalAmount() { _priceCalculation = new PriceCalculation(1, 0.01021004m, 0.01022304m, 0); Assert.AreEqual(0.010725647020m, _priceCalculation.GetSaleRateTotalAmount(5.05m)); }
public void RentRegularProductForNineDays() { var price = PriceCalculation.EquipmentPrice(Types.Regular, 9); Assert.AreEqual(500, price); }
private bool IsCalculationOfManager(PriceCalculation calculation) { return(calculation.PriceCalculationItems.First().SalesUnits.First().Project.Manager.IsAppCurrentUser()); }
public ActionResult FlightBooking(FlightBookingViewModel model, string[] Name, string[] Gender, string[] Nationality, string[] DOB, string btnProceed, string btnSubmit) { string seats = Request.Form["SeatsSelected"]; string[] seat = seats.Split(new char[] { ',' }); if (!String.IsNullOrEmpty(btnProceed)) { string bookedSeats = String.Join(",", (from b in db.Booking_Detail join s in db.Seat_Detail on b.BookingID equals s.BookingID where b.FlightID == model.flightID select s.SeatID).ToArray()); ViewBag.BookedSeats = bookedSeats; ViewBag.SelectedSeats = seats; var flightDetail = (from f in db.Flight_Detail where f.FlightID == model.flightID select f).FirstOrDefault(); var priceList = (from p in db.Pricings where p.FlightID == model.flightID select p).ToList(); var firstClassPriceList = (from pl in priceList where pl.ClassCategory == "First" select pl).OrderBy(x => x.Price).ToList(); var businessClassPriceList = (from pl in priceList where pl.ClassCategory == "Business" select pl).OrderBy(x => x.Price).ToList(); var economyClassPriceList = (from pl in priceList where pl.ClassCategory == "Economy" select pl).OrderBy(x => x.Price).ToList(); model.numberOfSelectedSeats = seat.Length; model.bookedSeats = seat; model.flightDetail = flightDetail; model.firstClassPriceList = firstClassPriceList; model.businessClassPriceList = businessClassPriceList; model.economyClassPriceList = economyClassPriceList; ViewBag.Disable = "disable"; } if (!String.IsNullOrEmpty(btnSubmit)) { Guid sessionUserID = new Guid(User.Identity.Name.Split('|')[1].ToString()); PriceCalculation priceCalculation = new PriceCalculation(); Booking_Detail bookingDetail = new Booking_Detail() { BookingID = Guid.NewGuid(), FlightID = model.flightID, BookedByCustomerID = sessionUserID, Amount = priceCalculation.GetTotalPrice(DOB, seat, model.flightID), BookingDateTime = DateTime.Now }; db.Booking_Detail.Add(bookingDetail); db.SaveChanges(); for (int i = 0; i < seat.Length; i++) { Seat_Detail seatDetail = new Seat_Detail() { TicketID = Guid.NewGuid(), BookingID = bookingDetail.BookingID, SeatID = Convert.ToInt16(seat[i]) }; db.Seat_Detail.Add(seatDetail); db.SaveChanges(); Passenger passenger = new Passenger() { PassengerID = Guid.NewGuid(), Name = Name[i], Gender = Gender[i], DOB = Convert.ToDateTime(DOB[i]), Nationality = Nationality[i], TicketID = seatDetail.TicketID }; db.Passengers.Add(passenger); db.SaveChanges(); } return(RedirectToAction("Home", "Customer")); } return(View(model)); }
private void GenSalesUnits() { var random = new Random(); var products = new List <Product> { ProductBreakersDrivePprk, ProductVeb110, ProductZng110, ProductZip1 }; var facilityOwners = new List <Company> { CompanyFsk, CompanyMrsk }; var contracts = new List <Contract> { ContractFsk, ContractMrsk, ContractPmk }; var managers = new List <User> { UserIvanov, UserKosolapov, UserGazizov, UserBrehov, UserKolesnik, UserRybin }; var paymentConditionSets = new List <PaymentConditionSet> { PaymentConditionSet50Na50, PaymentConditionSet30Na70 }; for (int projectNum = 0; projectNum < 20; projectNum++) { var manager = managers[random.Next(0, managers.Count)]; var project = new Project { Name = $"Реконструкция ПС №{projectNum}", ProjectType = ProjectTypeReconstruction, Manager = manager }; Projects.Add(project); for (int pr = 0; pr < random.Next(1, 5); pr++) { var product = products[random.Next(0, products.Count)]; var facilityOwner = facilityOwners[random.Next(0, facilityOwners.Count)]; var facility = new Facility { Name = $"Подстанция №{projectNum}", Type = FacilityTypeSubStation, OwnerCompany = facilityOwner, Address = new Address { Locality = LocalityMoscow, Description = "123" } }; int year = random.Next(DateTime.Today.Year - 1, DateTime.Today.Year + 2); int month = random.Next(1, 13); int day = random.Next(1, DateTime.DaysInMonth(year, month) + 1); var deliveryDateExpected = new DateTime(year, month, day); var cost = random.Next(1000, 5000001); var paymentConditionSet = paymentConditionSets[random.Next(0, paymentConditionSets.Count)]; DateTime? signalToStartProduction = null; DateTime? signalToStartProductionDone = null; Order order = null; Company producer = null; string sn = null; Specification specification = null; PriceCalculation priceCalculation = null; PaymentDocument paymentDocument = null; if (deliveryDateExpected < DateTime.Today.AddDays(100)) { if (random.Next(100) < 60) { producer = CompanyUetm; signalToStartProduction = deliveryDateExpected.AddDays(-120); signalToStartProductionDone = deliveryDateExpected.AddDays(-118); order = new Order { DateOpen = signalToStartProductionDone.Value, Number = $"{projectNum}-{pr}" }; specification = new Specification { Number = $"{projectNum+10}", Vat = 20, Contract = contracts[random.Next(0, contracts.Count)], Date = signalToStartProduction.Value }; sn = $"sn-{pr}-{projectNum}"; paymentDocument = new PaymentDocument { Number = $"pd-{pr}-{projectNum}", Vat = 20 }; } else if (random.Next(100) < 60) { producer = random.Next(100) < 70 ? CompanyZeto : CompanyApparat; } priceCalculation = new PriceCalculation { Initiator = UserKosolapov }; priceCalculation.History.Add(new PriceCalculationHistoryItem() { Moment = deliveryDateExpected.AddDays(-140), Type = PriceCalculationHistoryItemType.Start }); priceCalculation.History.Add(new PriceCalculationHistoryItem() { Moment = deliveryDateExpected.AddDays(-130), Type = PriceCalculationHistoryItemType.Finish }); } var salesUnits = new List <SalesUnit>(); for (int salesUnitNum = 0; salesUnitNum < random.Next(1, 100); salesUnitNum++) { var salesUnit = new SalesUnit { Project = project, Product = product, Cost = cost, DeliveryDateExpected = deliveryDateExpected, Facility = facility, PaymentConditionSet = paymentConditionSet, SignalToStartProduction = signalToStartProduction, SignalToStartProductionDone = signalToStartProductionDone, Order = order, OrderPosition = order == null ? null : $"{salesUnitNum + 1}", Producer = producer, PickingDate = signalToStartProductionDone?.Date.AddDays(110), EndProductionDate = signalToStartProductionDone?.Date.AddDays(120), RealizationDate = signalToStartProductionDone?.Date.AddDays(121), ShipmentDate = signalToStartProductionDone?.Date.AddDays(121), DeliveryDate = signalToStartProductionDone?.Date.AddDays(123), StartProductionDate = signalToStartProduction?.Date, EndProductionPlanDate = signalToStartProductionDone?.Date.AddDays(100), SerialNumber = sn == null ? null : $"{sn}-{salesUnitNum}", Specification = specification }; SalesUnits.Add(salesUnit); salesUnits.Add(salesUnit); } if (paymentDocument != null) { PaymentDocuments.Add(paymentDocument); var date = signalToStartProduction.Value.AddDays(7); var sum = cost * random.Next(0, 75) / 100; foreach (var salesUnit in salesUnits) { salesUnit.PaymentsActual.Add(new PaymentActual { Date = date, Sum = sum }); } var payments = salesUnits.SelectMany(x => x.PaymentsActual); paymentDocument.Payments.AddRange(payments); } if (priceCalculation != null) { var salesUnit = salesUnits.First(); var priceCalculationItem = new PriceCalculationItem { RealizationDate = deliveryDateExpected.AddDays(-2), PaymentConditionSet = salesUnit.PaymentConditionSet, OrderInTakeDate = deliveryDateExpected.AddDays(-130) }; priceCalculationItem.SalesUnits.AddRange(salesUnits); priceCalculationItem.StructureCosts.Add(new StructureCost { AmountNumerator = 1, Comment = $"structureCostName-{projectNum}", Number = $"structureCostNumber-{projectNum}", UnitPrice = salesUnit.Cost * random.Next(4, 7) / 10 }); priceCalculation.PriceCalculationItems.Add(priceCalculationItem); PriceCalculations.Add(priceCalculation); } } } }
public void RentSpezializedProductForTwoDays() { var price = PriceCalculation.EquipmentPrice(Types.Specialized, 2); Assert.AreEqual(120, price); }
protected void btnSave_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } Provider provider = null; if (ddlProvider.SelectedIndex != 0) { provider = ControllerManager.Provider.GetById(Convert.ToInt32(ddlProvider.SelectedValue)); } CategoryBase category = null; if (ddlCategoryLinked.Index != 0) { category = ControllerManager.CategoryBase.GetById(Convert.ToInt32(ddlCategoryLinked.Values)); } string errors; bool mainvalid = false; bool secvalid = true; bool error = false; PriceCalculation pc = null; if ((!string.IsNullOrEmpty(txtFormula1.Text) || !string.IsNullOrEmpty(txtFormula2.Text)) && (txtFormula1.Text != txtFormula2.Text)) { if (!string.IsNullOrEmpty(txtFormula1.Text)) { try { ControllerManager.PriceCalculation.CheckFormula(txtFormula1.Text, out errors, out mainvalid); } catch (Exception ex) { Utils.ShowMessage(this.Page, "Error en la formula principal.", Utils.MessageType.Error); } if (mainvalid && !string.IsNullOrEmpty(txtFormula2.Text)) { try { ControllerManager.PriceCalculation.CheckFormula(txtFormula2.Text, out errors, out secvalid); } catch (Exception) { Utils.ShowMessage(this.Page, "Error en la formula secundaria.", Utils.MessageType.Error); } } if (mainvalid && secvalid) { int pcid = 0; pc = ControllerManager.PriceCalculation.FindOrCreate(PoliticId, provider, category, txtFormula1.Text, 1); if (pc.ID == -1) { Utils.ShowMessage(this.Page, "Ya existe fórmula principal para esa política.", Utils.MessageType.Error); error = true; } else { pcid = pc.ID; } if (!string.IsNullOrEmpty(txtFormula2.Text)) { pc = ControllerManager.PriceCalculation.FindOrCreate(0, provider, category, txtFormula2.Text, 2); if (pc.ID == -1) { Utils.ShowMessage(this.Page, "Ya existe fórmula secundaria para esa política.", Utils.MessageType.Error); error = true; } } ControllerManager.PriceCalculation.Run(pc.Provider, pc.CategoryBase); if (!error) { Response.Redirect("/admin/pricespolitics/view/?Id=" + pcid); } } else { Utils.ShowMessage(this.Page, "Revise las formulas.", Utils.MessageType.Error); } } } else { Utils.ShowMessage(this.Page, "No ingrese 2 formulas iguales.", Utils.MessageType.Error); } }
public BookingDB(IConfiguration configuration) { priceCalculation = new PriceCalculation(); dataAccessLayer = DataAccessLayer.DataAccessLayerFactory.GetDataAccessLayer(configuration); showDb = new ShowDB(configuration); }
private void ProcessRecords() { Utils.GetLogger().Debug("Processing Records"); foreach (PriceBase priceBase in priceBases) { // Ignore if ((priceBase.PricePurchase == 0 && priceBase.PriceSuggest == 0) || priceBase.Status != PriceBaseStatus.NotVerified) { continue; } List <PriceCalculation> lstPriceCalculationCopy = new List <PriceCalculation>(priceCalculations); // Remove formulas with TP if (priceBase.PricePurchase == 0) { lstPriceCalculationCopy = priceCalculations.FindAll(delegate(PriceCalculation record) { if (!record.Formula.Contains("TP")) { return(true); } return(false); }); } // Remove formulas with GRP else if (priceBase.PriceSuggest == 0) { lstPriceCalculationCopy = priceCalculations.FindAll(delegate(PriceCalculation record) { if (!record.Formula.Contains("GRP")) { return(true); } return(false); }); } // Find default formula PriceCalculation defaultPriceCalculation = lstPriceCalculationCopy.Find(delegate(PriceCalculation record) { if (record.Priority == PriceCalculationPriority.Default) { return(true); } return(false); }); int providerId = priceBase.Provider.ID; List <IDIDView> productCategories = lstProductByCategories.FindAll(delegate(IDIDView record) { if (record.Id1 == priceBase.Product.ID) { return(true); } return(false); } ); if (lstPriceCalculationCopy.Count > 0) { lstPriceCalculationCopy = lstPriceCalculationCopy.FindAll(delegate(PriceCalculation record) { if (record.Provider != null && record.Provider.ID == providerId && record.CategoryBase != null && productCategories.Count > 0) { if (productCategories.Exists(delegate(IDIDView record2) { if (record2.Id2 == record.CategoryBase.ID) { return(true); } return(false); })) { return(true); } } if (record.Provider != null && record.Provider.ID == providerId && record.CategoryBase == null) { return(true); } if (record.Provider == null && record.CategoryBase != null && productCategories.Count > 0) { if (productCategories.Exists(delegate(IDIDView record2) { if (record2.Id2 == record.CategoryBase.ID) { return(true); } return(false); })) { return(true); } } return(false); }); } // If there is a better formula than Default, set it. PriceCalculation selectedPriceCalculation = lstPriceCalculationCopy.Count > 0 ? lstPriceCalculationCopy[0] : defaultPriceCalculation; // If no formula found, return; if (selectedPriceCalculation == null) { continue; } Utils.GetLogger().Debug(string.Format("Selected formula {0} for PriceBase [{1}/{2}]", selectedPriceCalculation.Formula, priceBase.Product.ID, priceBase.Provider.ID)); // Find current rate for PriceSuggest CurrencyRateView currentRate = currencyRateViews.Find(delegate(CurrencyRateView record) { if (record.FromCurrency.ID == priceBase.PriceSuggestCurrency.ID && record.ToCurrency.ID == priceBase.PriceListCurrency.ID) { return(true); } return(false); }); object[] loCodeParms = new object[2]; loCodeParms[0] = priceBase.PriceSuggest * currentRate.Rate; // Find current rate for PricePurchase currentRate = currencyRateViews.Find(delegate(CurrencyRateView record) { if (record.FromCurrency.ID == priceBase.PricePurchaseCurrency.ID && record.ToCurrency.ID == priceBase.PriceListCurrency.ID) { return(true); } return(false); }); loCodeParms[1] = priceBase.PricePurchase * currentRate.Rate; Utils.GetLogger().Debug(string.Format("Executing formula {0} for PriceBase [{1}/{2}]", selectedPriceCalculation.Formula, priceBase.Product.ID, priceBase.Provider.ID)); // Calculate with the specified formula decimal finalPriceList = Convert.ToDecimal(loObject.GetType().InvokeMember("Formula" + selectedPriceCalculation.ID.ToString(), BindingFlags.InvokeMethod, null, loObject, loCodeParms)); // Ignore if same price if (finalPriceList == priceBase.PriceList) { continue; } //// Create the Price Base history record if needed. //if (createHistory) // ControllerManager.PriceBaseHistory.SaveAudit(priceBase, HistoryStatus.ModificationPolitics, userId); // Assign new price priceBase.PriceList = finalPriceList; priceBase.TimeStamp.ModifiedOn = DateTime.Now; if (userId.HasValue) { priceBase.TimeStamp.ModifiedBy = userId; } Utils.GetLogger().Debug(string.Format("Setting price of {0} for PriceBase [{1}/{2}]", finalPriceList, priceBase.Product.ID, priceBase.Provider.ID)); } priceBases.Clear(); Utils.GetLogger().Debug("Finish executing data for Price Calculator"); }
public void TestMethodGetGrossProfit() { _priceCalculation = new PriceCalculation(5m, 0.01020304m, 0.01020404m, 0); Assert.AreEqual(0.00000500m, _priceCalculation.GetGrossProfit()); }
public IHttpActionResult GetProductInformation([FromBody] GetProductInformationRequest request) { ProductCatalog catalog = CatalogLibrary.GetCatalog(request.CatalogId); Product product = CatalogLibrary.GetProduct(request.Sku); Category category = CatalogLibrary.GetCategory(request.CategoryId.Value); string niceUrl = CatalogLibrary.GetNiceUrlForProduct(product, category, catalog); PriceCalculation priceCalculation = CatalogLibrary.CalculatePrice(product); Currency currency = priceCalculation.YourPrice.Amount.Currency; ProductInformation productInformation = new ProductInformation() { NiceUrl = niceUrl, PriceCalculation = new PriceCalculationViewModel() { Discount = new PriceViewModel() { Amount = new MoneyViewModel() { Value = priceCalculation.Discount.Amount.Value, DisplayValue = new Money(priceCalculation.Discount.Amount.Value, currency).ToString() }, AmountExclTax = new MoneyViewModel() { Value = priceCalculation.Discount.AmountExclTax.Value, DisplayValue = new Money(priceCalculation.Discount.AmountExclTax.Value, currency).ToString() }, AmountInclTax = new MoneyViewModel() { Value = priceCalculation.Discount.AmountInclTax.Value, DisplayValue = new Money(priceCalculation.Discount.AmountInclTax.Value, currency).ToString() } }, IsDiscounted = priceCalculation.IsDiscounted, YourPrice = new PriceViewModel() { Amount = new MoneyViewModel() { Value = priceCalculation.YourPrice.Amount.Value, DisplayValue = new Money(priceCalculation.YourPrice.Amount.Value, currency).ToString() }, AmountInclTax = new MoneyViewModel() { Value = priceCalculation.YourPrice.AmountInclTax.Value, DisplayValue = new Money(priceCalculation.YourPrice.AmountInclTax.Value, currency).ToString() }, AmountExclTax = new MoneyViewModel() { Value = priceCalculation.YourPrice.AmountExclTax.Value, DisplayValue = new Money(priceCalculation.YourPrice.AmountExclTax.Value, currency).ToString() } }, ListPrice = new PriceViewModel() { Amount = new MoneyViewModel() { Value = priceCalculation.ListPrice.Amount.Value, DisplayValue = new Money(priceCalculation.ListPrice.Amount.Value, currency).ToString() }, AmountExclTax = new MoneyViewModel() { Value = priceCalculation.ListPrice.AmountExclTax.Value, DisplayValue = new Money(priceCalculation.ListPrice.AmountExclTax.Value, currency).ToString() }, AmountInclTax = new MoneyViewModel() { Value = priceCalculation.ListPrice.AmountInclTax.Value, DisplayValue = new Money(priceCalculation.ListPrice.AmountInclTax.Value, currency).ToString() } } } }; productInformation.Sku = product.Sku; return(Json(productInformation)); }
public void TestMethodGetNetProfit() { _priceCalculation = new PriceCalculation(5m, 0.01020304m, 0.01020404m, 0.002m); Assert.AreEqual(-0.00199500m, _priceCalculation.GetNetProfit()); }
public void TestMethodGetPriceDifferenceNegative() { _priceCalculation = new PriceCalculation(1, 0.01020404m, 0.01020304m, 0); Assert.AreEqual(-0.00000100m, _priceCalculation.GetPriceDifference()); }
public OrderValidationStatus ValidateOrder(string accName, string custName, List <ProductEntity> products) { logger.Message = "Starting Validation On Order"; dispatcher.interceptors.ForEach(f => f.Intercept(logger)); var orderValidationStatus = new OrderValidationStatus() { IsValid = false }; if (accName.Equals(null) || custName.Equals(null) || products.Equals(null)) { return(orderValidationStatus); } var accountName = accName.Trim(); var customerName = custName.Trim(); logger.Message = "Validate Account"; dispatcher.interceptors.ForEach(f => f.Intercept(logger)); invoker.Message = "ValidateAccountEntity()"; dispatcher.interceptorsInv.ForEach(f => f.Intercept(invoker)); var account = ValidateAccountEntity(accountName); if (account == null) { return(orderValidationStatus); } logger.Message = "Validate Customer"; dispatcher.interceptors.ForEach(f => f.Intercept(logger)); var customer = ValidateCustomerEntity(customerName); if (customer == null) { return(orderValidationStatus); } logger.Message = "Validate Products"; dispatcher.interceptors.ForEach(f => f.Intercept(logger)); if (ValidateProducts(products)) { PriceCalculation pricing = new PriceCalculation(products, customer); logger.Message = "Calculating Total Price For Products"; dispatcher.interceptors.ForEach(f => f.Intercept(logger)); var totalCost = pricing.CalculateTotalCostOfProducts(); logger.Message = ("Calculating Discounts"); dispatcher.interceptors.ForEach(f => f.Intercept(logger)); totalCost = pricing.CalculateDiscounts(totalCost); orderValidationStatus.IsValid = true; orderValidationStatus.OrderEntity = new OrderEntity() { CustomerEntity = customer, AccountEntity = account, OrderDate = DateTime.Now, OrderId = ObjectId.GenerateNewId().ToString(), OrderType = FinalOrderType.Completed, Products = products, TotalCost = totalCost, Interceptions = logger.LogList, Invokations = invoker.InvokedList }; SalesValidation salesValidation = new SalesValidation(new RepositoryFactory <SalesEntity>(), ConnString); var salesEntity = salesValidation.GetAllSales(); if (orderValidationStatus.OrderEntity.CustomerEntity.SchemesCards.DrugScheme) { salesEntity.SalesEntity.DrugSchemeSales++; } else if (orderValidationStatus.OrderEntity.CustomerEntity.SchemesCards.MedicalCard) { salesEntity.SalesEntity.MedicalCardSales++; } else { salesEntity.SalesEntity.RegularSales++; } salesValidation.UpdateSales(salesEntity.SalesEntity); return(orderValidationStatus); } return(orderValidationStatus); }