public ActionResult EditDetailCurrency(int id, string value) { var detail = PurchaseOrderDetail.Find(id); CurrencyCode val; bool success; success = Enum.TryParse <CurrencyCode> (value.Trim(), out val); if (success) { decimal rate = CashHelpers.GetTodayExchangeRate(val); if (rate == 0) { Response.StatusCode = 400; return(Content(Resources.Message_InvalidExchangeRate)); } detail.Currency = val; detail.ExchangeRate = CashHelpers.GetTodayExchangeRate(val); using (var scope = new TransactionScope()) { detail.Update(); } } return(Json(new { id = id, value = detail.Currency.ToString(), rate = detail.ExchangeRate, total = detail.Total.ToString("c") })); }
public ActionResult SetItemPrice(int id, string value) { var entity = SalesOrderDetail.Find(id); bool success; decimal val; if (entity.SalesOrder.IsCompleted || entity.SalesOrder.IsCancelled) { Response.StatusCode = 400; return(Content(Resources.ItemAlreadyCompletedOrCancelled)); } success = decimal.TryParse(value.Trim(), System.Globalization.NumberStyles.Currency, null, out val); if (success && entity.Price >= 0) { var price_in_list = ProductPrice.Queryable.Where(x => x.List == entity.SalesOrder.Customer.PriceList && x.Product == entity.Product).SingleOrDefault(); if (price_in_list != null) { var current_price = price_in_list.Value; if (price_in_list.Product.Currency != entity.Currency) { current_price = current_price * CashHelpers.GetTodayExchangeRate(price_in_list.Product.Currency, entity.Currency); } if (current_price > val) { Response.StatusCode = 400; return(Content(Resources.Validation_WrongDiscount)); } } entity.Price = val; using (var scope = new TransactionScope()) { entity.UpdateAndFlush(); } } return(Json(new { id = entity.Id, discount_percentage = entity.FormattedValueFor(x => x.DiscountRate), discount_price = string.Format("{0:C}", entity.Price * entity.DiscountRate), value = entity.FormattedValueFor(x => x.Price), total = entity.FormattedValueFor(x => x.Total), total2 = entity.FormattedValueFor(x => x.TotalEx) })); }
public ActionResult SetCurrency(int id, string value) { var entity = SalesQuote.Find(id); CurrencyCode val; bool success; if (entity.IsCompleted || entity.IsCancelled) { Response.StatusCode = 400; return(Content(Resources.ItemAlreadyCompletedOrCancelled)); } success = Enum.TryParse <CurrencyCode> (value.Trim(), out val); if (success) { decimal rate = CashHelpers.GetTodayExchangeRate(val); if (rate == 0m) { Response.StatusCode = 400; return(Content(Resources.Message_InvalidExchangeRate)); } entity.Currency = val; entity.ExchangeRate = rate; entity.Updater = CurrentUser.Employee; entity.ModificationTime = DateTime.Now; using (var scope = new TransactionScope()) { foreach (var item in entity.Details) { item.Currency = val; item.ExchangeRate = rate; item.Update(); } entity.UpdateAndFlush(); } } return(Json(new { id = entity.Id, value = entity.FormattedValueFor(x => x.Currency), rate = entity.FormattedValueFor(x => x.ExchangeRate), itemsChanged = success })); }
public ActionResult AddItem(int order, int product) { var entity = SalesQuote.TryFind(order); var p = Product.TryFind(product); int pl = entity.Customer.PriceList.Id; var cost = (from x in ProductPrice.Queryable where x.Product.Id == product && x.List.Id == 0 select x).SingleOrDefault(); var price = (from x in ProductPrice.Queryable where x.Product.Id == product && x.List.Id == pl select x).SingleOrDefault(); var discount = (from x in CustomerDiscount.Queryable where x.Product.Id == product && x.Customer.Id == entity.Customer.Id select x.Discount).SingleOrDefault(); if (entity.IsCompleted || entity.IsCancelled) { Response.StatusCode = 400; return(Content(Resources.ItemAlreadyCompletedOrCancelled)); } if (cost == null) { cost = new ProductPrice { Value = decimal.Zero }; } if (price == null) { price = new ProductPrice { Value = decimal.MaxValue }; } var item = new SalesQuoteDetail { SalesQuote = entity, Product = p, ProductCode = p.Code, ProductName = p.Name, TaxRate = p.TaxRate, IsTaxIncluded = p.IsTaxIncluded, Quantity = p.MinimumOrderQuantity, Price = price.Value, DiscountRate = discount, Currency = entity.Currency, ExchangeRate = entity.ExchangeRate }; if (p.Currency != entity.Currency) { item.Price = price.Value * CashHelpers.GetTodayExchangeRate(p.Currency, entity.Currency); } using (var scope = new TransactionScope()) { item.CreateAndFlush(); } return(Json(new { id = item.Id })); }