public ActionResult SetItemProductName(int id, string value) { var entity = SalesOrderDetail.Find(id); string val = (value ?? string.Empty).Trim(); if (entity.SalesOrder.IsCompleted || entity.SalesOrder.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 SetItemDiscountPercentage(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.TrimEnd(new char[] { ' ', '%' }), out val); val /= 100m; if (success && val <= 1.0m && val >= 0.0m) { entity.DiscountRate = val; using (var scope = new TransactionScope()) { entity.UpdateAndFlush(); } } return(Json(new { id = entity.Id, value = entity.FormattedValueFor(x => x.DiscountRate), discountPrice = string.Format("{0:C}", entity.Price * entity.DiscountRate), total = entity.FormattedValueFor(x => x.Total), total2 = entity.FormattedValueFor(x => x.TotalEx) })); }
public ActionResult SetItemQuantity(int id, decimal value) { var entity = SalesOrderDetail.Find(id); if (entity.SalesOrder.IsCompleted || entity.SalesOrder.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 SetItemTaxRate(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.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) })); }
decimal GetRefundableQuantity(int id) { var item = SalesOrderDetail.Find(id); string sql = @"SELECT SUM(d.quantity) quantity FROM customer_refund_detail d INNER JOIN customer_refund m ON d.customer_refund = m.customer_refund_id WHERE m.completed <> 0 AND m.cancelled = 0 AND d.sales_order_detail = :detail "; IList <decimal> quantities = (IList <decimal>) ActiveRecordMediator <CustomerRefundDetail> .Execute( delegate(ISession session, object instance) { try { return(session.CreateSQLQuery(sql) .SetParameter("detail", id) .SetMaxResults(1) .List <decimal> ()); } catch (Exception) { return(null); } }, null); if (quantities != null && quantities.Count > 0) { return(item.Quantity - quantities [0]); } return(item.Quantity); }
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 RemoveItem(int id) { var entity = SalesOrderDetail.Find(id); if (entity.SalesOrder.IsCompleted || entity.SalesOrder.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 = SalesOrderDetail.Find(id); if (entity.SalesOrder.IsCompleted || entity.SalesOrder.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 = SalesOrderDetail.Find(id); return(PartialView("_ItemEditorView", entity)); }