public JsonResult DiscardLotSerialNumbers(int id) { var rqmt = LotSerialRequirement.Find(id); var qry = from x in LotSerialTracking.Queryable where x.Source == rqmt.Source && x.Reference == rqmt.Reference && x.Warehouse.Id == rqmt.Warehouse.Id && x.Product == rqmt.Product select x; using (var scope = new TransactionScope()) { var entity = new LotSerialTracking { Source = rqmt.Source, Reference = rqmt.Reference, Date = DateTime.Now, Warehouse = rqmt.Warehouse, Product = rqmt.Product, Quantity = rqmt.Quantity }; foreach (var item in qry) { item.Delete(); } entity.Create(); rqmt.DeleteAndFlush(); } return(Json(new { id = id, result = true }, JsonRequestBehavior.AllowGet)); }
public ActionResult ConfirmLotSerialNumbers(int id) { var entity = LotSerialRequirement.Find(id); var qry = from x in LotSerialTracking.Queryable where x.Source == entity.Source && x.Reference == entity.Reference && x.Warehouse.Id == entity.Warehouse.Id && x.Product.Id == entity.Product.Id select x; decimal sum = qry.Count() > 0 ? qry.Sum(x => x.Quantity) : 0; if (entity.Quantity != sum) { Response.StatusCode = 400; return(Content(Resources.ValidationFailed)); } using (var scope = new TransactionScope()) { if (entity.Source == TransactionType.InventoryTransfer) { var transfer = InventoryTransfer.Find(entity.Reference); foreach (var serial in qry) { var item = new LotSerialTracking { Source = serial.Source, Reference = serial.Reference, Date = serial.Date, Warehouse = transfer.To, Product = serial.Product, Quantity = -serial.Quantity, LotNumber = serial.LotNumber, ExpirationDate = serial.ExpirationDate, SerialNumber = serial.SerialNumber }; item.Create(); } } entity.DeleteAndFlush(); } return(Json(new { id = id, result = true })); }
public JsonResult GetLotSerialNumberCount(int id) { var item = LotSerialRequirement.Find(id); var qry = from x in LotSerialTracking.Queryable where x.Source == item.Source && x.Reference == item.Reference && x.Warehouse.Id == item.Warehouse.Id && x.Product.Id == item.Product.Id select x.Quantity; decimal sum = qry.Count() > 0 ? qry.Sum() : 0; return(Json(new { id = item.Id, count = sum, total = item.Quantity }, JsonRequestBehavior.AllowGet)); }
public JsonResult AddLotSerialNumber(int id, decimal qty, string lot, DateTime?expiration, string serial) { var rqmt = LotSerialRequirement.Find(id); var item = GetLastLotSerial(rqmt.Product.Id, lot, serial); if (item == null) { item = new LotSerialTracking { LotNumber = lot, ExpirationDate = expiration, SerialNumber = string.IsNullOrWhiteSpace(serial) ? null : serial }; } else { item = new LotSerialTracking { LotNumber = item.LotNumber, ExpirationDate = item.ExpirationDate, SerialNumber = string.IsNullOrWhiteSpace(serial) ? null : item.SerialNumber }; } item.Source = rqmt.Source; item.Reference = rqmt.Reference; item.Date = DateTime.Now; item.Warehouse = rqmt.Warehouse; item.Product = rqmt.Product; item.Quantity = (rqmt.Quantity > 0 ? qty : -qty); using (var scope = new TransactionScope()) { item.CreateAndFlush(); } return(Json(new { id = item.Id, result = true })); }