public void DoProduct(Guid productId, Guid customerId, Guid slId, int stepCode, double qty, double unQty, double freezeQty) { var spBll = new StockProduct(); var spInfo = spBll.GetModel(productId, customerId); if (spInfo == null) { throw new ArgumentException(MC.M_StockProductInvalidError); } var pslaList = JsonConvert.DeserializeObject <List <ProductStockLocationAttrInfo> >(spInfo.StockLocations); var currTime = DateTime.Now; if (stepCode == (int)EnumData.EnumStep.发货) { #region 发货 var pslItem = pslaList.FirstOrDefault(m => m.StockLocationId.Equals(slId)); if (pslItem == null) { throw new ArgumentException(MC.GetString(MC.Params_Data_NotExist, "库位ID为“" + slId + "”")); } pslItem.FreezeQty += freezeQty; pslItem.Qty -= freezeQty; if (pslItem.Qty == 0 && pslItem.FreezeQty == 0) { pslaList.Remove(pslItem); } spInfo.Qty -= freezeQty; spInfo.FreezeQty += freezeQty; #endregion } else if (stepCode == (int)EnumData.EnumStep.架) { #region 架 var pslItem = pslaList.FirstOrDefault(m => m.StockLocationId.Equals(slId)); if (pslItem == null) { var slBll = new StockLocation(); var slInfo = slBll.GetModel(slId); if (slInfo == null) { throw new ArgumentException(MC.GetString(MC.Params_Data_NotExist, "库位ID为“" + slId + "”")); } pslaList.Add(new ProductStockLocationAttrInfo(slId, slInfo.Code, slInfo.Named, qty, 0, currTime)); } else { pslItem.Qty += qty; if (pslItem.Qty == 0 && pslItem.FreezeQty == 0) { pslaList.Remove(pslItem); } } spInfo.Qty += qty; spInfo.UnQty -= qty; if (spInfo.UnQty < 0) { throw new ArgumentException(MC.GetString(MC.Request_InvalidQty, qty.ToString())); } #endregion } spInfo.StockLocations = JsonConvert.SerializeObject(pslaList); spBll.Update(spInfo); }
public IEnumerable <StockProductInfo> GetSelectProductListByStepName(int pageIndex, int pageSize, string stepName, object productId, object customerId, double qty) { var sqlWhere = new StringBuilder(100); if (EnumData.EnumStep.发货.ToString() == stepName) { sqlWhere.Append("and sp.Qty > 0 "); } else if (EnumData.EnumStep.拣货.ToString() == stepName) { sqlWhere.AppendFormat("and sp.FreezeQty > 0 and ProductId = '{0}' and CustomerId = '{1}' ", productId, customerId); } var spList = new List <StockProductInfo>(); var list = dal.GetListByJoin(pageIndex, pageSize, sqlWhere.ToString(), null); if (list != null && list.Count > 0) { var slBll = new StockLocation(); var slTemp = slBll.GetModelForTemp(); var slList = slBll.GetList(); foreach (var item in list) { var pslaList = JsonConvert.DeserializeObject <List <ProductStockLocationAttrInfo> >(item.StockLocations); if (EnumData.EnumStep.发货.ToString() == stepName || EnumData.EnumStep.拣货.ToString() == stepName) { pslaList.RemoveAll(m => m.StockLocationId.Equals(slTemp.Id)); } foreach (var pslaItem in pslaList) { if (EnumData.EnumStep.发货.ToString() == stepName) { if (pslaItem.Qty <= 0) { continue; } } else if (EnumData.EnumStep.拣货.ToString() == stepName) { if (pslaItem.FreezeQty <= 0) { continue; } } var slInfo = slList.FirstOrDefault(m => m.Id.Equals(pslaItem.StockLocationId)); if (slInfo == null) { throw new ArgumentException(string.Format("{0}对应的库位数据不存在或已被删除", pslaItem.StockLocationId)); } var spInfo = new StockProductInfo(item.ProductId, item.CustomerId, item.Qty, item.UnQty, item.FreezeQty, item.StepCode, item.LastStepName, item.Status, item.StockLocations, "", item.LastUpdatedDate); spInfo.StockLocations = ""; spInfo.StockLocationId = slInfo.Id; spInfo.StockLocationCode = slInfo.Code; spInfo.StockLocationName = slInfo.Named; spInfo.LastUpdatedDate = pslaItem.LastUpdatedDate; spInfo.Qty = 0; spInfo.ProductCode = item.ProductCode; spInfo.ProductName = item.ProductName; spInfo.CustomerCode = item.CustomerCode; spInfo.CustomerName = item.CustomerName; if (EnumData.EnumStep.拣货.ToString() == stepName) { spInfo.MaxQty = pslaItem.FreezeQty; } else { spInfo.MaxQty = pslaItem.Qty; } spList.Add(spInfo); } } var q = spList.OrderBy(m => m.LastUpdatedDate); var totalQty = 0d; foreach (var item in q) { if (totalQty >= qty) { break; } item.IsBest = true; totalQty += item.MaxQty; } } return(spList); }
public void DoProduct(Guid productId, Guid customerId, Guid slId, bool isIncrease, double qty, double unQty, double freezeQty, int stepCode, string status) { var spInfo = dal.GetModel(productId, customerId); var sStepCode = Common.GetStepCode(spInfo == null ? null : spInfo.StepCode, stepCode.ToString(), false); var sLastStepName = Enum.GetName(typeof(EnumData.EnumStep), stepCode); var currQty = 0d; var currFreezeQty = 0d; if (!isIncrease) { #region 对库存货物“减”处理 if (spInfo != null) { if (unQty > 0) { currQty += unQty; spInfo.UnQty -= unQty; if (spInfo.UnQty < 0) { throw new ArgumentException(MC.M_QtyInvalidError); } } var pslaList = JsonConvert.DeserializeObject <List <ProductStockLocationAttrInfo> >(spInfo.StockLocations); var pslaInfo = pslaList.FirstOrDefault(m => m.StockLocationId.Equals(slId)); if (pslaInfo != null) { pslaInfo.Qty -= currQty; pslaInfo.FreezeQty -= currFreezeQty; } spInfo.StockLocations = JsonConvert.SerializeObject(pslaList); if (spInfo.StepCode == ((int)EnumData.EnumStep.收货).ToString() && spInfo.Qty == 0 && spInfo.UnQty == 0 && spInfo.FreezeQty == 0) { dal.Delete(productId, customerId); } else { dal.Update(spInfo); } } #endregion } else { #region 对库存货物“增”处理 if (spInfo != null) { #region 已存在相应数据,则执行修改操作 if (unQty > 0) { spInfo.UnQty += unQty; currQty += unQty; } var pslaList = JsonConvert.DeserializeObject <List <ProductStockLocationAttrInfo> >(spInfo.StockLocations); var pslaInfo = pslaList.FirstOrDefault(m => m.StockLocationId.Equals(slId)); if (pslaInfo != null) { pslaInfo.Qty += unQty; } else { var slBll = new StockLocation(); var slInfo = slBll.GetModel(slId); if (slInfo == null) { throw new ArgumentException(MC.GetString(MC.Params_Data_NotExist, slId.ToString())); } pslaList.Add(new ProductStockLocationAttrInfo(slId, slInfo.Code, slInfo.Named, currQty, currFreezeQty, DateTime.Now)); } spInfo.StockLocations = JsonConvert.SerializeObject(pslaList); dal.Update(spInfo); #endregion } else { #region 否则执行新增操作 if (unQty > 0) { currQty += unQty; } var slBll = new StockLocation(); var slInfo = slBll.GetModel(slId); if (slInfo == null) { throw new ArgumentException(MC.GetString(MC.Params_Data_NotExist, slId.ToString())); } var pslaList = new List <ProductStockLocationAttrInfo>(); pslaList.Add(new ProductStockLocationAttrInfo(slId, slInfo.Code, slInfo.Named, currQty, currFreezeQty, DateTime.Now)); spInfo = new StockProductInfo(productId, customerId, qty, unQty, freezeQty, sStepCode, sLastStepName, status, JsonConvert.SerializeObject(pslaList), "", DateTime.Now); dal.Insert(spInfo); #endregion } #endregion } }
public IList <PandianProductInfo> GetPandianProductList(Guid pandianId, Guid userId, DateTime stockStartDate, DateTime stockEndDate, string customer, string zones, string stockLocations) { var list = new List <PandianProductInfo>(); var slBll = new StockLocation(); var slTempInfo = slBll.GetModelForTemp(); var zBll = new Zone(); var hasStartDate = (stockStartDate != DateTime.Parse("1754-01-01") && stockStartDate != DateTime.MinValue); var hasEndDate = (stockEndDate != DateTime.Parse("1754-01-01") && stockEndDate != DateTime.MinValue); string[] customers = null; if (!string.IsNullOrWhiteSpace(customer)) { customers = customer.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } if ((customers != null && customers.Length > 0) && (!hasStartDate && !hasEndDate && string.IsNullOrWhiteSpace(zones) && string.IsNullOrWhiteSpace(stockLocations))) { #region 获取只客户为条件的库存货品 StringBuilder sqlWhere = null; SqlParameter parm = null; if (customers.Length == 1) { sqlWhere = new StringBuilder(@"and sp.CustomerId = @CustomerId "); parm = new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier); parm.Value = Guid.Parse(customers[0]); } else { sqlWhere = new StringBuilder(1200); var sqlIn = new StringBuilder(1000); foreach (var item in customers) { sqlIn.AppendFormat("'{0}',", item); } sqlWhere.AppendFormat("and sp.CustomerId in ({0})", sqlIn.ToString().Trim(',')); } var spList = dal.GetListByJoin(sqlWhere.ToString(), parm); if (spList != null && spList.Count > 0) { var zList = zBll.GetList(); var slList = slBll.GetList(); foreach (var item in spList) { var qty = 0d; var sZones = new List <string>(); var pslList = JsonConvert.DeserializeObject <List <ProductStockLocationAttrInfo> >(item.StockLocations); if (pslList != null && pslList.Count > 0) { pslList.RemoveAll(m => m.StockLocationId.Equals(slTempInfo.Id)); if (pslList.Count > 0) { qty = pslList.Sum(m => (m.Qty + m.FreezeQty)); var minSlList = new List <MinStockLocationInfo>(); foreach (var pslInfo in pslList) { var slInfo = slList.FirstOrDefault(m => m.Id.Equals(pslInfo.StockLocationId)); if (slInfo != null) { var zInfo = zList.FirstOrDefault(m => m.Id.Equals(slInfo.ZoneId)); if (zInfo != null) { if (!sZones.Contains(zInfo.ZoneCode)) { sZones.Add(zInfo.ZoneCode); } } minSlList.Add(new MinStockLocationInfo(slInfo.Id, slInfo.Code, slInfo.Named, (pslInfo.Qty + pslInfo.FreezeQty))); } } qty = minSlList.Sum(m => m.Qty); list.Add(new PandianProductInfo(pandianId, userId, item.ProductId, item.CustomerId, string.Join(",", sZones), JsonConvert.SerializeObject(minSlList), qty, "", "", 0, 0, EnumData.EnumOrderStatus.新建.ToString(), "", DateTime.Now)); } } } } #endregion } else { #region 获取可能包含入库时间、库区、库位为条件的库存货品 var spList = dal.GetList(); if (spList != null && spList.Count > 0) { string[] slItems = null; if (!string.IsNullOrWhiteSpace(stockLocations)) { slItems = stockLocations.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } IList <StockLocationInfo> zslList = null; if (!string.IsNullOrWhiteSpace(zones) && (slItems == null || slItems.Length == 0)) { zslList = slBll.GetListInZoneIds(zones); } var zList = zBll.GetList(); var slList = slBll.GetList(); foreach (var item in spList) { var pslList = JsonConvert.DeserializeObject <List <ProductStockLocationAttrInfo> >(item.StockLocations); if (pslList == null || pslList.Count == 0) { continue; } pslList.RemoveAll(m => m.StockLocationId.Equals(slTempInfo.Id)); if (pslList.Count == 0) { continue; } if (customers != null && customers.Length > 0 && pslList.Count > 0) { if (!customers.Contains(item.CustomerId.ToString())) { continue; } } if (hasStartDate) { pslList.RemoveAll(m => m.LastUpdatedDate < stockStartDate); } if (hasEndDate && pslList.Count > 0) { pslList.RemoveAll(m => m.LastUpdatedDate > stockStartDate); } if (slItems != null && slItems.Length > 0 && pslList.Count > 0) { pslList.RemoveAll(m => !slItems.Contains(m.StockLocationId.ToString())); } if (!string.IsNullOrWhiteSpace(zones) && (slItems != null && slItems.Length == 0) && pslList.Count > 0) { pslList.RemoveAll(m => !slList.Any(mm => mm.Id.Equals(m.StockLocationId))); } if (pslList.Count == 0) { continue; } var sZones = new List <string>(); var minSlList = new List <MinStockLocationInfo>(); foreach (var pslInfo in pslList) { var slInfo = slList.FirstOrDefault(m => m.Id.Equals(pslInfo.StockLocationId)); if (slInfo != null) { var zInfo = zList.FirstOrDefault(m => m.Id.Equals(slInfo.ZoneId)); if (zInfo != null) { if (!sZones.Contains(zInfo.ZoneCode)) { sZones.Add(zInfo.ZoneCode); } } minSlList.Add(new MinStockLocationInfo(slInfo.Id, slInfo.Code, slInfo.Named, (pslInfo.Qty + pslInfo.FreezeQty))); } } var qty = minSlList.Sum(m => m.Qty); list.Add(new PandianProductInfo(pandianId, userId, item.ProductId, item.CustomerId, string.Join(",", sZones), JsonConvert.SerializeObject(minSlList), qty, "", "", 0, 0, EnumData.EnumOrderStatus.新建.ToString(), "", DateTime.Now)); } } #endregion } return(list); }
public void DoOrderPickProduct(string itemAppend) { var items = itemAppend.Split(new char[] { '$' }, StringSplitOptions.RemoveEmptyEntries); var orderPickId = Guid.Parse(items[0]); var orderId = Guid.Parse(items[1]); var productId = Guid.Parse(items[2]); var customerId = Guid.Parse(items[3]); var oBll = new OrderPicked(); var oInfo = oBll.GetModel(orderPickId); if (oInfo == null) { throw new ArgumentException(MC.GetString(MC.Params_Data_NotExist, "拣货单ID“" + orderPickId + "”")); } var osBll = new OrderSend(); var orderInfo = osBll.GetModel(orderId); if (orderInfo == null) { throw new ArgumentException(MC.GetString(MC.Params_Data_NotExist, orderId.ToString())); } var ospBll = new OrderSendProduct(); var ospInfo = ospBll.GetModel(orderId, productId, customerId); if (ospInfo == null) { throw new ArgumentException(MC.M_RuleInvalidError); } var pBll = new Product(); var productInfo = pBll.GetModel(productId); var minVolume = productInfo.OutPackVolume == 0 ? 1 : productInfo.OutPackVolume; var slItems = items[4].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); var dicSl = new Dictionary <Guid, float>(); var totalQty = 0f; var currTime = DateTime.Now; foreach (var item in slItems) { var subItems = item.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var qty = float.Parse(subItems[1]); dicSl.Add(Guid.Parse(subItems[0]), qty); totalQty += qty; } var slBll = new StockLocation(); var slpBll = new StockLocationProduct(); var oppBll = new OrderPickProduct(); int effect = 0; var oppInfo = oppBll.GetModel(orderPickId, orderId, productId, customerId); oppInfo.Qty += totalQty; oppInfo.StockLocations = slBll.GetStockLocationTextInIds(string.Join(",", dicSl.Select(m => m.Key))); oppInfo.LastUpdatedDate = currTime; effect = oppBll.Update(oppInfo); new StockProduct().DoProduct(productId, customerId, (int)EnumData.EnumStep.拣货, false, dicSl); oBll.SetTotalProduct(orderPickId.ToString()); ospInfo.PickQty += totalQty; ospBll.Update(ospInfo); osBll.SetStatus(orderId.ToString()); }
public void DoShelfMissionProduct(string itemAppend) { var items = itemAppend.Split(new char[] { '$' }, StringSplitOptions.RemoveEmptyEntries); var shelfMissionId = Guid.Parse(items[0]); var orderId = Guid.Parse(items[1]); var productId = Guid.Parse(items[2]); var smBll = new ShelfMission(); var smInfo = smBll.GetModel(shelfMissionId); if (smInfo == null) { throw new ArgumentException(MC.GetString(MC.Params_Data_NotExist, shelfMissionId.ToString())); } var oBll = new OrderReceipt(); var orderInfo = oBll.GetModel(orderId); if (orderInfo == null) { throw new ArgumentException(MC.GetString(MC.Params_Data_NotExist, orderId.ToString())); } var pBll = new Product(); var productInfo = pBll.GetModel(productId); var minVolume = productInfo.OutPackVolume == 0 ? 1 : productInfo.OutPackVolume; var slItems = items[3].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); var slBll = new StockLocation(); var pslaList = new List <ProductStockLocationAttrInfo>(); var dicSl = new Dictionary <Guid, float>(); var totalQty = 0f; var currTime = DateTime.Now; foreach (var item in slItems) { var subItems = item.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var slId = Guid.Parse(subItems[0]); var qty = float.Parse(subItems[1]); var slInfo = slBll.GetModel(slId); if (slInfo == null) { throw new ArgumentException(MC.GetString(MC.Params_Data_NotExist, "库位ID为" + slId + "")); } pslaList.Add(new ProductStockLocationAttrInfo(slId, slInfo.Code, slInfo.Named, qty, 0, currTime)); dicSl.Add(slId, qty); totalQty += qty; } var smpBll = new ShelfMissionProduct(); var smpInfo = smpBll.GetModel(shelfMissionId, orderId, productId); if (smpInfo == null) { throw new ArgumentException(MC.Data_NotExist); } smpInfo.Qty += totalQty; smpInfo.StockLocations = JsonConvert.SerializeObject(pslaList); smpInfo.LastUpdatedDate = currTime; smpBll.Update(smpInfo); smBll.SetTotalProduct(shelfMissionId.ToString()); #region 库存库位货品 var spBll = new StockProduct(); spBll.DoProduct(productId, orderInfo.CustomerId, (int)EnumData.EnumStep.架, dicSl); #endregion }
public void DoProduct(Guid slId, Guid productId, bool isIncrease, double qty, double freezeQty) { var slpInfo = dal.GetModel(slId); if (!isIncrease) { #region 对库位货物“减”处理 if (slpInfo != null) { var slpaList = JsonConvert.DeserializeObject <List <StockLocationProductAttrInfo> >(slpInfo.ProductAttr); var slpaInfo = slpaList.FirstOrDefault(m => m.ProductId.Equals(productId)); if (slpaInfo != null) { if (qty > 0) { slpaInfo.Qty -= qty; if (slpaInfo.Qty < 0) { throw new ArgumentException(MC.GetString(MC.Request_InvalidQty, qty.ToString())); } } if (freezeQty > 0) { slpaInfo.FreezeQty -= freezeQty; if (slpaInfo.FreezeQty < 0) { throw new ArgumentException(MC.GetString(MC.Request_InvalidQty, freezeQty.ToString())); } } if (slpaInfo.Qty <= 0 && slpaInfo.FreezeQty <= 0) { slpaList.Remove(slpaInfo); } slpInfo.ProductAttr = JsonConvert.SerializeObject(slpaList); dal.Update(slpInfo); } } #endregion } else { #region 对库位货物“增”处理 if (slpInfo != null) { #region 已存在相应数据,则执行修改操作 var slpaList = JsonConvert.DeserializeObject <List <StockLocationProductAttrInfo> >(slpInfo.ProductAttr); var slpaInfo = slpaList.FirstOrDefault(m => m.ProductId.Equals(productId)); if (slpaInfo != null) { if (qty > 0) { slpaInfo.Qty += qty; } if (freezeQty > 0) { slpaInfo.FreezeQty += freezeQty; } } else { slpaList.Add(new StockLocationProductAttrInfo(productId, qty, freezeQty, DateTime.Now)); } slpInfo.ProductAttr = JsonConvert.SerializeObject(slpaList); dal.Update(slpInfo); #endregion } else { #region 否则执行新增操作 var slpaList = new List <StockLocationProductAttrInfo>(); slpaList.Add(new StockLocationProductAttrInfo(productId, qty > 0 ? qty : 0, freezeQty > 0 ? freezeQty : 0, DateTime.Now)); var slBll = new StockLocation(); var slInfo = slBll.GetModel(slId); var maxVolume = slInfo.Volume; if (qty > 0) { maxVolume -= qty; } slpInfo = new StockLocationProductInfo(slId, JsonConvert.SerializeObject(slpaList), maxVolume); dal.Insert(slpInfo); #endregion } #endregion } }