public ActionResult SetItemPrice(int id, string value) { var entity = SalesQuoteDetail.Find(id); bool success; decimal val; if (entity.SalesQuote.IsCompleted || entity.SalesQuote.IsCancelled) { Response.StatusCode = 400; return(Content(Resources.ItemAlreadyCompletedOrCancelled)); } success = decimal.TryParse(value.Trim(), System.Globalization.NumberStyles.Currency, null, out val); if (success && val >= 0) { entity.Price = val; using (var scope = new TransactionScope()) { entity.UpdateAndFlush(); } } return(Json(new { id = entity.Id, value = entity.FormattedValueFor(x => x.Price), total = entity.FormattedValueFor(x => x.Total), total2 = entity.FormattedValueFor(x => x.TotalEx) })); }
public ActionResult SetItemTaxRate(int id, string value) { var entity = SalesQuoteDetail.Find(id); bool success; decimal val; if (entity.SalesQuote.IsCompleted || entity.SalesQuote.IsCancelled) { Response.StatusCode = 400; return(Content(Resources.ItemAlreadyCompletedOrCancelled)); } success = decimal.TryParse(value.TrimEnd(new char [] { ' ', '%' }), out val); // TODO: VAT value range validation if (success) { entity.TaxRate = val; using (var scope = new TransactionScope()) { entity.Update(); } } return(Json(new { id = entity.Id, value = entity.FormattedValueFor(x => x.TaxRate), total = entity.FormattedValueFor(x => x.Total), total2 = entity.FormattedValueFor(x => x.TotalEx) })); }
public ActionResult SetItemProductName(int id, string value) { var entity = SalesQuoteDetail.Find(id); string val = (value ?? string.Empty).Trim(); if (entity.SalesQuote.IsCompleted || entity.SalesQuote.IsCancelled) { Response.StatusCode = 400; return(Content(Resources.ItemAlreadyCompletedOrCancelled)); } if (val.Length == 0) { entity.ProductName = entity.Product.Name; } else { entity.ProductName = val; } using (var scope = new TransactionScope()) { entity.UpdateAndFlush(); } return(Json(new { id = entity.Id, value = entity.ProductName })); }
public ActionResult SetItemQuantity(int id, decimal value) { var entity = SalesQuoteDetail.Find(id); if (entity.SalesQuote.IsCompleted || entity.SalesQuote.IsCancelled) { Response.StatusCode = 400; return(Content(Resources.ItemAlreadyCompletedOrCancelled)); } if (value < entity.Product.MinimumOrderQuantity) { Response.StatusCode = 400; return(Content(string.Format(Resources.MinimumQuantityRequired, entity.Product.MinimumOrderQuantity))); } entity.Quantity = value; using (var scope = new TransactionScope()) { entity.UpdateAndFlush(); } return(Json(new { id = entity.Id, value = entity.FormattedValueFor(x => x.Quantity), total = entity.FormattedValueFor(x => x.Total), total2 = entity.FormattedValueFor(x => x.TotalEx) })); }
public ActionResult RemoveItem(int id) { var entity = SalesQuoteDetail.Find(id); if (entity.SalesQuote.IsCompleted || entity.SalesQuote.IsCancelled) { Response.StatusCode = 400; return(Content(Resources.ItemAlreadyCompletedOrCancelled)); } using (var scope = new TransactionScope()) { entity.DeleteAndFlush(); } return(Json(new { id = id, result = true })); }
public ActionResult SetItemComment(int id, string value) { var entity = SalesQuoteDetail.Find(id); if (entity.SalesQuote.IsCompleted || entity.SalesQuote.IsCancelled) { Response.StatusCode = 400; return(Content(Resources.ItemAlreadyCompletedOrCancelled)); } entity.Comment = string.IsNullOrWhiteSpace(value) ? null : value.Trim(); using (var scope = new TransactionScope()) { entity.UpdateAndFlush(); } return(Json(new { id = id, value = entity.Comment })); }
public ActionResult Item(int id) { var entity = SalesQuoteDetail.Find(id); return(PartialView("_ItemEditorView", entity)); }
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 })); }
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, Discount = 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 }); }