public JsonResult Add(StockOutRecord model) { //FIXED 出仓处理逻辑 if (ModelState.IsValid) { string errorMessage = AddStockOutForUpdateStockItem(model); if (!string.IsNullOrEmpty(errorMessage)) { ModelState.AddModelError(string.Empty, errorMessage); } } var allErrors = this.GetModelStateErrors(ModelState); return(Json(allErrors)); }
public string AddStockOutForUpdateStockItem(ExtendedIdentityDbContext db, StockOutRecord model, string userName) { try { StockItem stockItem = db.StockItems.Find(model.StockItemId); if (stockItem != null) { StockOutRecord record = this.GetStockOutRecord( db, stockItem, model); record.OperatorSysUserName = userName; stockItem.StockOutRecords.Add(record); var outWeight = stockItem.StockOutRecords.Sum( m => m.StockWeight.GetValueOrDefault()); if (outWeight <= 0) { stockItem.StockStatus = StockStatus.InStock; } else if (stockItem.StockWeight.GetValueOrDefault() > outWeight) { stockItem.StockStatus = StockStatus.InStockSelling; } else { stockItem.StockStatus = StockStatus.IsSold; stockItem.IsAllSold = true; } return(AppBusinessManager.Instance.AddOrUpdateStockItem( db, stockItem, userName)); } return("找不到对应的库存,可能已经出仓。"); } catch (Exception e) { string errorMsg = string.Format("库存出仓失败。发生异常:{0}", e.Message); LogHelper.Error(errorMsg, e); if ((e is AggregateException) && (e as AggregateException).InnerException != null) { var tmp = (e as AggregateException).InnerException; errorMsg += tmp.Message; LogHelper.Error(errorMsg, tmp); } return(errorMsg); } }
private StockOutRecord GetStockOutRecord(ExtendedIdentityDbContext db, StockItem stockItem, StockOutRecord model) { StockOutRecord record = db.StockOutRecords.Create(); record.StockItemId = model.StockItemId; record.StockWeight = model.StockWeight; record.StockOutDate = DateTime.Now; record.SaleContractId = model.SaleContractId; record.RemainderStockWeight = model.RemainderStockWeight; record.RemainderQuantity = model.RemainderQuantity; record.Quantity = model.Quantity; record.InventoriesFeeSubTotal = model.InventoriesFeeSubTotal; record.Comments = model.Comments; return(record); }
private string AddStockOutForUpdateStockItem(StockOutRecord model) { return(AppBusinessManager.Instance.AddStockOutForUpdateStockItem( m_db, model, HttpContext.User.Identity.Name)); }