/// <summary> /// 更新出库记录 /// </summary> /// <param name="wareHousesId"></param> /// <param name="info"></param> private void UpdateDeliveryInventoryLederInfo(int wareHousesId, XMAllocateProductDetails info) { var inventoryLeder = base.XMInventoryLedgerService.GetXMInventoryLedgerByParm(wareHousesId, info.PlatformMerchantCode); var productDetails = base.XMProductDetailsService.GetXMProductDetailsListByProductId(info.ProductId.Value); if (inventoryLeder != null) //更新数据 { //更新出库数量(加上) inventoryLeder.OutCount = (inventoryLeder.OutCount == null ? 0 : inventoryLeder.OutCount) + info.ProductCount; if (productDetails != null && productDetails.Count > 0) { inventoryLeder.OutPrice = productDetails[0].Costprice; } inventoryLeder.OutMoney = inventoryLeder.OutPrice * inventoryLeder.OutCount; inventoryLeder.UpdateDate = DateTime.Now; inventoryLeder.UpdateID = HozestERPContext.Current.User.CustomerID; base.XMInventoryLedgerService.UpdateXMInventoryLedger(inventoryLeder); } else { XMInventoryLedger inventoryLederInfo = new XMInventoryLedger(); inventoryLederInfo.OutCount = info.ProductCount; inventoryLederInfo.WarehouseId = wareHousesId; inventoryLederInfo.ProductId = info.ProductId.Value; inventoryLederInfo.PlatformMerchantCode = info.PlatformMerchantCode; if (productDetails != null && productDetails.Count > 0) { inventoryLederInfo.OutPrice = productDetails[0].Costprice; } inventoryLederInfo.OutMoney = inventoryLederInfo.OutCount * inventoryLederInfo.OutPrice; inventoryLederInfo.CreateDate = DateTime.Now; inventoryLederInfo.CreateID = HozestERPContext.Current.User.CustomerID; base.XMInventoryLedgerService.InsertXMInventoryLedger(inventoryLederInfo); } //新增库存总账明细(出库) var inventoryLederDetail = base.XMInventoryLedgerDetailService.GetXMInventoryLedgerDetailListByParm(wareHousesId, info.PlatformMerchantCode); decimal price = 0; decimal money = 0; XMInventoryLedgerDetail details = new XMInventoryLedgerDetail(); details.WarehouseId = wareHousesId; details.ProductId = info.ProductId; details.PlatformMerchantCode = info.PlatformMerchantCode; details.OutCount = info.ProductCount; //出库数量 if (productDetails != null && productDetails.Count > 0) { details.OutPrice = productDetails[0].Costprice; //出库单价 } details.OutMoney = details.OutPrice * info.ProductCount; details.InCount = 0; details.InPrice = price; details.InMoney = money; if (inventoryLederDetail != null && inventoryLederDetail.Count > 0) { //默认最后一条(余量) int BalanceCount = inventoryLederDetail[0].BalanceCount.Value; details.BalanceCount = BalanceCount - info.ProductCount; } else // { details.BalanceCount = info.ProductCount; } details.BalancePrice = price; details.BalanceMoney = details.BalancePrice * details.BalanceCount; var dbInfo = base.XMAllocateInfoService.GetXMAllocateInfoById(info.AllocateId); if (dbInfo != null) { details.RefNumber = dbInfo.Ref; //业务单号 } details.BizDate = DateTime.Now; details.BizUserId = HozestERPContext.Current.User.CustomerID; int refType = 1011; //业务类型 1 采购入库 1000 采购退货 1002 销售出库 1004 销售退货入库 1008 库存盘点-盘盈入库 1010 库存盘点-盘亏出库 1011 调拨出库 details.RefType = refType; base.XMInventoryLedgerDetailService.InsertXMInventoryLedgerDetail(details); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { decimal value = 0; if (this.type == 0) //新增 { string errMessage = ""; bool isFalse = false; bool isEmpty = false; bool isInventLess = false; //库存是否充足 string dbCode = AutodbNumber(); string wfIDFrom = WareHoursesout.Value.ToString(); //调出仓库 string wfIDTo = WareHoursesin.Value.ToString(); //调入仓库 string hiddjsonContent = hdfJsonContent.Value; //产品列表 json if (wfIDFrom == null && wfIDFrom == "") { base.ShowMessage("请添加调出仓库或未选择调出仓库!"); BindGrid(hiddjsonContent); return; } if (wfIDTo == null && wfIDTo == "") { base.ShowMessage("请添加调入仓库或未选择调入仓库!"); BindGrid(hiddjsonContent); return; } if (hiddjsonContent != "") { JArray ja_goods = (JArray)JsonConvert.DeserializeObject(hiddjsonContent); for (int i = 0; i < ja_goods.Count; i++) { string productCode = ja_goods[i]["txtProductCode"].ToString().Replace('\"', ' ').Trim(); //厂家编码 bool t = IsNumeric(ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim() == "" ? "0" : ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim()); if (!t) { base.ShowMessage("调拨数量格式不正确!"); BindGrid(hiddjsonContent); return; } int productCount = ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim() == "" ? 0 : int.Parse(ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim()); //盘点后库存数量 if (productCount == 0) { isFalse = true; } if (productCode == "") { isEmpty = true; } var inventInfo = base.XMInventoryInfoService.GetXMInventoryInfoByParm(productCode, int.Parse(wfIDFrom)); if ((inventInfo != null && inventInfo.StockNumber < productCount) || inventInfo == null) { isInventLess = true; //库存不足 errMessage += "厂家编码为:" + productCode + "的商品库存不足! "; } } } if (isEmpty) { base.ShowMessage("厂家编码不能为空!"); BindGrid(hiddjsonContent); return; } if (isFalse) { base.ShowMessage("调拨数量不能为0!"); BindGrid(hiddjsonContent); return; } if (isInventLess) { base.ShowMessage(errMessage); BindGrid(hiddjsonContent); return; } XMAllocateInfo allcateInfo = new XMAllocateInfo(); allcateInfo.Ref = dbCode; allcateInfo.From_WarehouseId = int.Parse(WareHoursesout.Value.ToString()); allcateInfo.To_WarehouseId = int.Parse(WareHoursesin.Value.ToString()); allcateInfo.BizUserId = HozestERPContext.Current.User.CustomerID; allcateInfo.BizDt = txtDeliveryDate.Value == "" ? DateTime.Now : Convert.ToDateTime(txtDeliveryDate.Value); allcateInfo.BillMemo = txtNote.Text.Trim(); allcateInfo.BillStatus = 0; allcateInfo.CreateDate = allcateInfo.UpdateDate = DateTime.Now; allcateInfo.CreateID = allcateInfo.UpdateID = HozestERPContext.Current.User.CustomerID; allcateInfo.IsEnable = false; base.XMAllocateInfoService.InsertXMAllocateInfo(allcateInfo); int dbId = allcateInfo.Id; if (hiddjsonContent != "") { JArray ja_goods = (JArray)JsonConvert.DeserializeObject(hiddjsonContent); for (int i = 0; i < ja_goods.Count; i++) { string productCode = ja_goods[i]["txtProductCode"].ToString().Replace('\"', ' ').Trim(); //厂家编码 string productName = ja_goods[i]["txtProductName"].ToString().Replace('\"', ' ').Trim(); //商品名称 int productCount = ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim() == "" ? 0 : int.Parse(ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim()); //调拨数量 XMAllocateProductDetails details = new XMAllocateProductDetails(); details.AllocateId = dbId; var product = base.XMProductService.getXMProductByManufacturersCode(productCode); //根据厂家编码查询产品 if (product != null) { details.ProductId = product.Id; } details.PlatformMerchantCode = productCode; details.ProductCount = productCount; details.CreateDate = details.UpdateDate = DateTime.Now; details.CrerateId = details.UpdateID = HozestERPContext.Current.User.CustomerID; details.IsEnable = false; base.XMAllocateProductDetailsService.InsertXMAllocateProductDetails(details); } } base.ShowMessage("操作成功!"); BindGrid(allcateInfo.Id); } else //编辑 { string errMessage = ""; bool isInventLess = false; //判断库存是否不足 bool isEmpty = false; bool isFalse = false; string hiddjsonContent = hdfJsonContent.Value; //产品列表 json string wfIDFrom = WareHoursesout.Value.ToString(); //调出仓库 string wfIDTo = WareHoursesin.Value.ToString(); //调入仓库 if (wfIDFrom == null && wfIDFrom == "") { base.ShowMessage("请添加调出仓库或未选择调出仓库!"); BindGrid(hiddjsonContent); return; } if (wfIDTo == null && wfIDTo == "") { base.ShowMessage("请添加调入仓库或未选择调入仓库!"); BindGrid(hiddjsonContent); return; } var dbInfo = base.XMAllocateInfoService.GetXMAllocateInfoById(this.scid); if (dbInfo != null) { if (hiddjsonContent != "") { JArray ja_goods = (JArray)JsonConvert.DeserializeObject(hiddjsonContent); for (int i = 0; i < ja_goods.Count; i++) { bool t = IsNumeric(ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim() == "" ? "0" : ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim()); if (!t) { base.ShowMessage("调拨数量格式不正确!"); X.Msg.Alert("Server Time", DateTime.Now.ToLongTimeString()).Show(); BindGrid(hiddjsonContent); return; } int productCount = ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim() == "" ? 0 : int.Parse(ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim()); //盘点后库存数量 if (productCount == 0) { isFalse = true; } string productCode = ja_goods[i]["txtProductCode"].ToString().Replace('\"', ' ').Trim(); //厂家编码 if (productCode == "") { isEmpty = true; } var inventInfo = base.XMInventoryInfoService.GetXMInventoryInfoByParm(productCode, int.Parse(wfIDFrom)); if ((inventInfo != null && inventInfo.StockNumber < productCount) || inventInfo == null) { isInventLess = true; //库存不足 errMessage += "厂家编码为:" + productCode + "的商品库存不足! "; } } } if (isEmpty) { base.ShowMessage("厂家编码不能为空!"); BindGrid(hiddjsonContent); return; } if (isFalse) { base.ShowMessage("调拨数量不能为0!"); BindGrid(hiddjsonContent); return; } if (isInventLess) { base.ShowMessage(errMessage); BindGrid(hiddjsonContent); return; } var dbInfoProductDetails = base.XMAllocateProductDetailsService.GetXMAllocateProductDetailsListByAllcateId(dbInfo.Id); dbInfo.BizDt = Convert.ToDateTime(txtDeliveryDate.Value); dbInfo.From_WarehouseId = int.Parse(WareHoursesout.Value.ToString()); dbInfo.To_WarehouseId = int.Parse(WareHoursesin.Value.ToString()); dbInfo.BillMemo = txtNote.Text.Trim(); dbInfo.UpdateDate = DateTime.Now; dbInfo.UpdateID = HozestERPContext.Current.User.CustomerID; base.XMAllocateInfoService.UpdateXMAllocateInfo(dbInfo); if (hiddjsonContent != "") { JArray ja_goods = (JArray)JsonConvert.DeserializeObject(hiddjsonContent); for (int i = 0; i < ja_goods.Count; i++) { bool isExsit = false; //判断厂家编码是否存在 string productCode = ja_goods[i]["txtProductCode"].ToString().Replace('\"', ' ').Trim(); //厂家编码 int productCount = ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim() == "" ? 0 : int.Parse(ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim()); //调拨单数量 foreach (XMAllocateProductDetails info in dbInfoProductDetails) { if (productCode == info.PlatformMerchantCode) { isExsit = true; info.ProductCount = productCount; info.UpdateID = HozestERPContext.Current.User.CustomerID; info.UpdateDate = DateTime.Now; base.XMAllocateProductDetailsService.UpdateXMAllocateProductDetails(info); } } if (ja_goods.Count >= dbInfoProductDetails.Count && isExsit == false) //不存在新增 { XMAllocateProductDetails details = new XMAllocateProductDetails(); details.AllocateId = dbInfo.Id; var product = base.XMProductService.getXMProductByManufacturersCode(productCode); if (product != null) { details.ProductId = product.Id; } details.PlatformMerchantCode = productCode; details.ProductCount = productCount; details.UpdateDate = details.CreateDate = DateTime.Now; details.CrerateId = details.UpdateID = HozestERPContext.Current.User.CustomerID; details.IsEnable = false; base.XMAllocateProductDetailsService.InsertXMAllocateProductDetails(details); } } if (dbInfoProductDetails != null && dbInfoProductDetails.Count > 0) { foreach (XMAllocateProductDetails info in dbInfoProductDetails) { bool isDelete = true; if (hiddjsonContent != "") { JArray ja_goods2 = (JArray)JsonConvert.DeserializeObject(hiddjsonContent); for (int i = 0; i < ja_goods.Count; i++) { string productCode2 = ja_goods[i]["txtProductCode"].ToString().Replace('\"', ' ').Trim(); //厂家编码 if (productCode2 == info.PlatformMerchantCode) { isDelete = false; break; } } } if (isDelete) { info.IsEnable = true; info.UpdateID = HozestERPContext.Current.User.CustomerID; info.UpdateDate = DateTime.Now; base.XMAllocateProductDetailsService.UpdateXMAllocateProductDetails(info); } } } } } base.ShowMessage("操作成功!"); BindGrid(dbInfo.Id); } }