public JsonResult RemoveItem(int id) { var item = CustomerRefundDetail.Find(id); using (var scope = new TransactionScope()) { item.DeleteAndFlush(); } return(Json(new { id = id, result = true })); }
public JsonResult SetItemQuantity(int id, decimal value) { var entity = CustomerRefundDetail.Find(id); decimal sum = GetRefundableQuantity(entity.SalesOrderDetail.Id); entity.Quantity = (value >= 0 && value <= sum) ? value : sum; 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 CreateFromSalesOrder(string value) { int id = 0; SalesOrder entity = null; if (int.TryParse(value, out id)) { entity = SalesOrder.TryFind(id); } if (entity == null) { Response.StatusCode = 400; return(Content(Resources.SalesOrderNotFound)); } if (!entity.IsCompleted || entity.IsCancelled) { Response.StatusCode = 400; return(Content(Resources.SalesOrderIsNotRefundable)); } if (entity.Store != WebConfig.Store) { Response.StatusCode = 400; return(Content(Resources.InvalidStore)); } var item = new CustomerRefund(); // Store and Serial item.Store = entity.Store; try { item.Serial = (from x in CustomerRefund.Queryable where x.Store.Id == item.Store.Id select x.Serial).Max() + 1; } catch { item.Serial = 1; } item.SalesOrder = entity; item.SalesPerson = entity.SalesPerson; item.Customer = entity.Customer; item.Currency = entity.Currency; item.ExchangeRate = entity.ExchangeRate; item.CreationTime = DateTime.Now; item.Date = DateTime.Now; item.Creator = CurrentUser.Employee; item.Updater = item.Creator; item.ModificationTime = item.CreationTime; foreach (var x in entity.Details) { var qty = GetRefundableQuantity(x.Id); if (qty <= 0) { continue; } var detail = new CustomerRefundDetail { Refund = item, SalesOrderDetail = x, Product = x.Product, ProductCode = x.ProductCode, ProductName = x.ProductName, DiscountRate = x.DiscountRate, TaxRate = x.TaxRate, IsTaxIncluded = x.IsTaxIncluded, Quantity = 0, Price = x.Price, ExchangeRate = x.ExchangeRate, Currency = x.Currency }; item.Details.Add(detail); } if (item.Details.Count == 0) { Response.StatusCode = 400; return(Content(Resources.RefundableItemsNotFound)); } using (var scope = new TransactionScope()) { item.Create(); foreach (var detail in item.Details) { detail.Create(); } } return(Json(new { url = Url.Action("Edit", new { id = item.Id }) })); }
public ActionResult CreateFromSalesOrder(string value) { int id = 0; SalesOrder entity = null; if (int.TryParse (value, out id)) { entity = SalesOrder.TryFind (id); } if (entity == null) { Response.StatusCode = 400; return Content (Resources.SalesOrderNotFound); } if (!entity.IsCompleted || entity.IsCancelled) { Response.StatusCode = 400; return Content (Resources.SalesOrderIsNotRefundable); } if (entity.Store != WebConfig.Store) { Response.StatusCode = 400; return Content (Resources.InvalidStore); } var item = new CustomerRefund (); // Store and Serial item.Store = entity.Store; try { item.Serial = (from x in CustomerRefund.Queryable where x.Store.Id == item.Store.Id select x.Serial).Max () + 1; } catch { item.Serial = 1; } item.SalesOrder = entity; item.SalesPerson = entity.SalesPerson; item.Customer = entity.Customer; item.Currency = entity.Currency; item.ExchangeRate = entity.ExchangeRate; item.CreationTime = DateTime.Now; item.Creator = CurrentUser.Employee; item.Updater = item.Creator; item.ModificationTime = item.CreationTime; foreach (var x in entity.Details) { var qty = GetRefundableQuantity (x.Id); if (qty <= 0) continue; var detail = new CustomerRefundDetail { Refund = item, SalesOrderDetail = x, Product = x.Product, ProductCode = x.ProductCode, ProductName = x.ProductName, Discount = x.Discount, TaxRate = x.TaxRate, IsTaxIncluded = x.IsTaxIncluded, Quantity = qty, Price = x.Price, ExchangeRate = x.ExchangeRate, Currency = x.Currency }; item.Details.Add (detail); } if (item.Details.Count == 0) { Response.StatusCode = 400; return Content (Resources.RefundableItemsNotFound); } using (var scope = new TransactionScope ()) { item.Create (); foreach (var detail in item.Details) { detail.Create (); } } return Json (new { url = Url.Action ("Edit", new { id = item.Id }) }); }