protected void btnSave_Click(object sender, EventArgs e) { decimal value = 0; if (this.type == 0) //新增 { bool isEmpty = false; //判断产品编码是否存在空 bool isFalse = false; string hiddjsonContent = hdfJsonContent.Value; //产品列表 json string wfID = ddlwareHouses.Value.ToString(); string Ref = AutoAdjustedNumber(); // if (wfID == "") { base.ShowMessage("请添加仓库或未选择仓库!"); BindGrid(hiddjsonContent); return; } if (int.Parse(wfID) == -1) { base.ShowMessage("请添加仓库或未选择仓库!"); BindGrid(hiddjsonContent); return; } decimal totalMoney = 0; //调整单总价 decimal totalMoneywithTax = 0; //调整单税金总数 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 (productCode == "") { isEmpty = true; } if (productCount == 0) { isFalse = true; } decimal productMoney = ja_goods[i]["txtProductMoney"].ToString().Replace('\"', ' ').Trim() == "" ? value : decimal.Parse(ja_goods[i]["txtProductMoney"].ToString().Replace('\"', ' ').Trim()); //调整单单价 totalMoney = totalMoney + productMoney; decimal MoneyWithTax = ja_goods[i]["txtMoneyWithTax"].ToString().Replace('\"', ' ').Trim() == "" ? value : decimal.Parse(ja_goods[i]["txtMoneyWithTax"].ToString().Replace('\"', ' ').Trim()); //价税合计 totalMoneywithTax = totalMoneywithTax + MoneyWithTax; } } if (isEmpty) { base.ShowMessage("厂家编码不能为空!"); BindGrid(hiddjsonContent); return; } if (isFalse) { base.ShowMessage("商品数量不能为0!"); BindGrid(hiddjsonContent); return; } XMAdjustedInfo adjustedInfo = new XMAdjustedInfo(); adjustedInfo.PdInfoId = this.PdId; adjustedInfo.Ref = Ref; adjustedInfo.WarehouseId = int.Parse(ddlwareHouses.Value.ToString()); adjustedInfo.SaleMoney = totalMoney; adjustedInfo.MoneywithTax = totalMoneywithTax; adjustedInfo.ReceivingType = Convert.ToInt16(ddlPayment.SelectedValue); adjustedInfo.BizUserId = HozestERPContext.Current.User.CustomerID; //操作人 adjustedInfo.BizDt = txtStorageDate.Value == "" ? DateTime.Parse(DateTime.Now.ToShortDateString()) : Convert.ToDateTime(txtStorageDate.Value); adjustedInfo.BillMemo = txtNote.Text.Trim(); adjustedInfo.CreateDate = adjustedInfo.UpdateDate = DateTime.Now; adjustedInfo.CreateID = adjustedInfo.UpdateID = HozestERPContext.Current.User.CustomerID; adjustedInfo.IsEnable = false; adjustedInfo.FinancialStatus = false; base.XMAdjustedInfoService.InsertXMAdjustedInfo(adjustedInfo); int adjustedID = adjustedInfo.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(); //商品名称 string specifications = ja_goods[i]["lblSpecifications"].ToString().Replace('\"', ' ').Trim(); //商品规格 int productCount = ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim() == "" ? 0 : int.Parse(ja_goods[i]["txtProductCount"].ToString().Replace('\"', ' ').Trim()); //销售数量 string unit = ja_goods[i]["txtUnit"].ToString().Replace('\"', ' ').Trim(); //单位 decimal productPrice = ja_goods[i]["txtProductPrice"].ToString().Replace('\"', ' ').Trim() == "" ? value : decimal.Parse(ja_goods[i]["txtProductPrice"].ToString().Replace('\"', ' ').Trim()); //销售单价 decimal productMoney = ja_goods[i]["txtProductMoney"].ToString().Replace('\"', ' ').Trim() == "" ? value : decimal.Parse(ja_goods[i]["txtProductMoney"].ToString().Replace('\"', ' ').Trim()); //销售金额 decimal tax = ja_goods[i]["txtTax"].ToString().Replace('\"', ' ').Trim() == "" ? value : decimal.Parse(ja_goods[i]["txtTax"].ToString().Replace('\"', ' ').Trim()); //税率 decimal taxRate = ja_goods[i]["txtTaxRate"].ToString().Replace('\"', ' ').Trim() == "" ? value : decimal.Parse(ja_goods[i]["txtTaxRate"].ToString().Replace('\"', ' ').Trim()); //税率 decimal MoneyWithTax = ja_goods[i]["txtMoneyWithTax"].ToString().Replace('\"', ' ').Trim() == "" ? value : decimal.Parse(ja_goods[i]["txtMoneyWithTax"].ToString().Replace('\"', ' ').Trim()); //价税合计 XMAdjustedProductDetail details = new XMAdjustedProductDetail(); details.AdId = adjustedID; var product = base.XMProductService.getXMProductByManufacturersCode(productCode); if (product != null) { details.ProductId = product.Id; } details.PlatformMerchantCode = productCode; details.ProductCount = productCount; details.ProductMoney = productMoney; details.ProductPrice = productPrice; details.Tax = tax; details.TaxRate = taxRate; details.MoneyWithTax = MoneyWithTax; details.CreateDate = details.UpdateDate = DateTime.Now; details.CreateID = details.UpdateID = HozestERPContext.Current.User.CustomerID; details.IsEnable = false; base.XMAdjustedProductDetailService.InsertXMAdjustedProductDetail(details); } } base.ShowMessage("操作成功!"); BindGrid(adjustedInfo.Id); } else //修改 { bool isFalse = false; bool isEmpty = false; //判断产品编码是否存在空 decimal totalMoney = 0; //调整单总价 decimal totalMoneywithTax = 0; //调整单税金总数 string wfID = ddlwareHouses.Value.ToString(); string hiddjsonContent = hdfJsonContent.Value; //产品列表 json if (int.Parse(wfID) == -1) { base.ShowMessage("请添加仓库或未选择仓库!"); BindGrid(hiddjsonContent); return; } var adjusted = base.XMAdjustedInfoService.GetXMAdjustedInfoById(this.AdjustedID); if (adjusted != null) { adjusted.WarehouseId = int.Parse(ddlwareHouses.Value.ToString()); 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(); //厂家编码 if (productCode == "") { isEmpty = true; } 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; } decimal productMoney = ja_goods[i]["txtProductMoney"].ToString().Replace('\"', ' ').Trim() == "" ? value : decimal.Parse(ja_goods[i]["txtProductMoney"].ToString().Replace('\"', ' ').Trim()); //采购单价 totalMoney += productMoney; decimal MoneyWithTax = ja_goods[i]["txtMoneyWithTax"].ToString().Replace('\"', ' ') == "" ? value : decimal.Parse(ja_goods[i]["txtMoneyWithTax"].ToString().Replace('\"', ' ').Trim()); //价税合计 totalMoneywithTax = totalMoneywithTax + MoneyWithTax; } } if (isEmpty) { base.ShowMessage("厂家编码不能为空!"); BindGrid(hiddjsonContent); return; } if (isFalse) { base.ShowMessage("商品数量不能为0!"); BindGrid(hiddjsonContent); return; } adjusted.SaleMoney = totalMoney; adjusted.MoneywithTax = totalMoneywithTax; adjusted.ReceivingType = int.Parse(ddlPayment.SelectedValue); adjusted.BillMemo = txtNote.Text.Trim(); adjusted.UpdateID = HozestERPContext.Current.User.CustomerID; adjusted.UpdateDate = DateTime.Now; base.XMAdjustedInfoService.UpdateXMAdjustedInfo(adjusted); var adjustedDetails = base.XMAdjustedProductDetailService.GetXMAdjustedProductDetailListByAdjustedID(adjusted.Id); if (adjustedDetails != null && adjustedDetails.Count > 0) { 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()); //调整单数量 decimal productPrice = ja_goods[i]["txtProductPrice"].ToString().Replace('\"', ' ').Trim() == "" ? value : decimal.Parse(ja_goods[i]["txtProductPrice"].ToString().Replace('\"', ' ').Trim()); //调整单价 decimal productMoney = ja_goods[i]["txtProductMoney"].ToString().Replace('\"', ' ').Trim() == "" ? value : decimal.Parse(ja_goods[i]["txtProductMoney"].ToString().Replace('\"', ' ').Trim()); //调整金额 decimal tax = ja_goods[i]["txtTax"].ToString().Replace('\"', ' ').Trim() == "" ? value : decimal.Parse(ja_goods[i]["txtTax"].ToString().Replace('\"', ' ').Trim()); //税率 decimal taxRate = ja_goods[i]["txtTaxRate"].ToString().Replace('\"', ' ').Trim() == "" ? value : decimal.Parse(ja_goods[i]["txtTaxRate"].ToString().Replace('\"', ' ').Trim()); //税率 decimal MoneyWithTax = ja_goods[i]["txtMoneyWithTax"].ToString().Replace('\"', ' ').Trim() == "" ? value : decimal.Parse(ja_goods[i]["txtMoneyWithTax"].ToString().Replace('\"', ' ').Trim()); //价税合计 foreach (XMAdjustedProductDetail info in adjustedDetails) { if (productCode == info.PlatformMerchantCode) { isExsit = true; info.ProductCount = productCount; info.ProductPrice = productPrice; info.ProductMoney = productMoney; info.Tax = tax; info.TaxRate = taxRate; info.MoneyWithTax = MoneyWithTax; info.UpdateID = HozestERPContext.Current.User.CustomerID; info.UpdateDate = DateTime.Now; base.XMAdjustedProductDetailService.UpdateXMAdjustedProductDetail(info); } } if (isExsit == false) //不存在新增 { XMAdjustedProductDetail adjustDetail = new XMAdjustedProductDetail(); adjustDetail.AdId = adjusted.Id; var product = base.XMProductService.getXMProductByManufacturersCode(productCode); if (product != null) { adjustDetail.ProductId = product.Id; } adjustDetail.PlatformMerchantCode = productCode; adjustDetail.ProductCount = productCount; adjustDetail.ProductPrice = productPrice; adjustDetail.ProductMoney = productMoney; adjustDetail.Tax = tax; adjustDetail.TaxRate = taxRate; adjustDetail.MoneyWithTax = MoneyWithTax; adjustDetail.UpdateDate = adjustDetail.CreateDate = DateTime.Now; adjustDetail.CreateID = adjustDetail.UpdateID = HozestERPContext.Current.User.CustomerID; adjustDetail.IsEnable = false; base.XMAdjustedProductDetailService.InsertXMAdjustedProductDetail(adjustDetail); } } } } } base.ShowMessage("操作成功!"); BindGrid(adjusted.Id); } }
/// <summary> /// 库存帐查询 库存盘点 盘盈入库 /// </summary> private void UpdateInventoryLederStorageInfo(int wareHouseId, XMAdjustedProductDetail details) { var inventoryLeder = base.XMInventoryLedgerService.GetXMInventoryLedgerByParm(wareHouseId, details.PlatformMerchantCode); if (inventoryLeder != null) //更新数据 { //更新入库数量(加上) inventoryLeder.InCount = (inventoryLeder.InCount == null ? 0 : inventoryLeder.InCount) + details.ProductCount; inventoryLeder.InMoney = details.ProductPrice * inventoryLeder.InCount; inventoryLeder.InPrice = details.ProductPrice; inventoryLeder.UpdateDate = DateTime.Now; inventoryLeder.UpdateID = HozestERPContext.Current.User.CustomerID; base.XMInventoryLedgerService.UpdateXMInventoryLedger(inventoryLeder); } else //新增数据 { XMInventoryLedger inventoryLederInfo = new XMInventoryLedger(); inventoryLederInfo.WarehouseId = wareHouseId; inventoryLederInfo.ProductId = details.ProductId; inventoryLederInfo.PlatformMerchantCode = details.PlatformMerchantCode; inventoryLederInfo.AfloatCount = 0; inventoryLederInfo.AfloatPrice = details.ProductPrice; inventoryLederInfo.AfloatMoney = inventoryLederInfo.AfloatCount * inventoryLederInfo.AfloatPrice; inventoryLederInfo.InCount = details.ProductCount; inventoryLederInfo.InPrice = details.ProductPrice; inventoryLederInfo.InMoney = inventoryLederInfo.InCount * inventoryLederInfo.InPrice; inventoryLederInfo.OutCount = 0; inventoryLederInfo.OutPrice = details.ProductPrice; 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(wareHouseId, details.PlatformMerchantCode); decimal price = 0; decimal money = 0; XMInventoryLedgerDetail detail = new XMInventoryLedgerDetail(); detail.WarehouseId = wareHouseId; detail.ProductId = details.ProductId; detail.PlatformMerchantCode = details.PlatformMerchantCode; detail.InCount = details.ProductCount; //入库数量 detail.InPrice = details.ProductPrice; //入库单价 detail.InMoney = details.ProductMoney; detail.OutCount = 0; detail.OutPrice = price; detail.OutMoney = money; if (inventoryLederDetail != null && inventoryLederDetail.Count > 0) { //默认最后一条(余量) int BalanceCount = inventoryLederDetail[0].BalanceCount.Value; detail.BalanceCount = BalanceCount + detail.InCount; } else // { detail.BalanceCount = detail.InCount; } detail.BalancePrice = details.ProductPrice; detail.BalanceMoney = detail.BalancePrice * detail.BalanceCount; var adjustInfo = base.XMAdjustedInfoService.GetXMAdjustedInfoById(details.AdId); if (adjustInfo != null) { var pdInfo = base.XMPdInfoService.GetXMPdInfoById(adjustInfo.PdInfoId.Value); if (pdInfo != null) { detail.RefNumber = pdInfo.Ref; } } detail.BizDate = DateTime.Now; detail.BizUserId = HozestERPContext.Current.User.CustomerID; int refType = 1008; //业务类型 1 采购入库 1000 采购退货 1002 销售出库 1004 销售退货入库 1008 库存盘点-盘盈入库 1010 库存盘点-盘亏出库 detail.RefType = refType; base.XMInventoryLedgerDetailService.InsertXMInventoryLedgerDetail(detail); }