private void btn_Search_Click(object sender, EventArgs e) { resultList.Clear(); DateTime dateEnd = global::Helper.DateTimeParse.EndDate; IList <Model.Product> listProduct = productManager.SelectIdAndStock(this.lue_ProductCategory.EditValue == null ? null : this.lue_ProductCategory.EditValue.ToString(), null, null); string workHouseYanpian = workHouseManager.SelectWorkHouseIdByName("验片"); string workHouseZuzhuang = workHouseManager.SelectWorkHouseIdByName("组装现场仓"); string workHouseChengpinZuzhuang = workHouseManager.SelectWorkHouseIdByName("成品组装"); string handBookId = this.cob_HandBookId.Text; foreach (Model.Product item in listProduct) { item.HandbookId = handBookId; item.StocksQuantity = item.StocksQuantity.HasValue ? item.StocksQuantity : 0; Dictionary <string, double> parentProductDic = new Dictionary <string, double>(); GetParentProductInfo("'" + item.ProductId + "'", parentProductDic); #region 现场数量 //查询商品对应的未结案加工单 2018年7月3日22:17:36 改:只查询2018.1.1 之后的订单 DateTime startDate = new DateTime(2018, 1, 1); IList <Model.PronoteHeader> phList = null; if (string.IsNullOrEmpty(handBookId)) //2018年12月7日20:52:30 : 加手册 { phList = pronoteHeaderManager.SelectByProductId(startDate, dateEnd.AddSeconds(-1), item.ProductId); } else { phList = pronoteHeaderManager.SelectByProductId(startDate, dateEnd.AddSeconds(-1), item.ProductId, handBookId); } if (phList == null || phList.Count == 0) { continue; } foreach (var phGroup in phList.GroupBy(P => P.CustomerInvoiceXOId)) { string pronoteHeaderIds = ""; string invoiceXOIds = ""; foreach (var ph in phGroup) { pronoteHeaderIds += "'" + ph.PronoteHeaderID + "',"; invoiceXOIds += "'" + ph.InvoiceXOId + "',"; } pronoteHeaderIds = pronoteHeaderIds.TrimEnd(','); invoiceXOIds = invoiceXOIds.TrimEnd(','); if (string.IsNullOrEmpty(pronoteHeaderIds)) { continue; } #region 验片:合计前单位转入 - 合计生产数量(包含合计合格数量,合计不良品) //计算所有转入 验片 部门的数量 Model.ProduceInDepotDetail pidYanpianIn = produceInDepotDetailManager.SelectByNextWorkhouse(item.ProductId, dateEnd.AddSeconds(-1), workHouseYanpian, pronoteHeaderIds); double yanpianTransferIn = Convert.ToDouble(pidYanpianIn.ProduceTransferQuantity); //计算 验片 部门的生产数量 Model.ProduceInDepotDetail pidYanpianOut = produceInDepotDetailManager.SelectByThisWorkhouse(item.ProductId, dateEnd.AddSeconds(-1), workHouseYanpian, pronoteHeaderIds); double yanpianProcedures = Convert.ToDouble(pidYanpianOut.ProceduresSum); double yanpianBuliang = Convert.ToDouble(pidYanpianOut.ProceduresSum - pidYanpianOut.CheckOutSum); double yanpianXianchang = yanpianTransferIn - yanpianProcedures; yanpianXianchang = yanpianXianchang < 0 ? 0 : yanpianXianchang; item.XianchangYanpian = yanpianXianchang; #endregion #region 组装现场:合计前单位转入+ 合计领料单领出 - 合计出库数量(合计转生产到其他部门,成品入库数量换算后扣减数量) //2018年2月22日13:18:54: 组装现场:合计前单位转入+ 合计领料单领出 - 合计出库数量(合计转生产到其他部门,成品入库数量换算后扣减数量)- 生产退料(从组装现场退的) //领到 组装现场 部门的数量 double materialQty = 0; if (!string.IsNullOrEmpty(invoiceXOIds)) { materialQty = produceMaterialdetailsManager.SelectMaterialQty(item.ProductId, dateEnd.AddSeconds(-1), workHouseZuzhuang, invoiceXOIds); } //计算所有转入 组装现场 部门的数量 //Model.ProduceInDepotDetail pidZuzhuangIn = produceInDepotDetailManager.SelectByNextWorkhouse(item.ProductId, dateEnd.AddSeconds(-1), workHouseZuzhuang, pronoteHeaderIds); //计算即时现场库存时不用区分订单,不需要加工单号,查询所有即可,这里要区分订单,所以要加上加工单号 //double zuzhuangTransferIn = Convert.ToDouble(pidZuzhuangIn.ProduceTransferQuantity); IList <Model.ProduceInDepotDetail> pidZuzhuangIn = produceInDepotDetailManager.SelectTransZuZhuangXianChang(item.ProductId, dateEnd.AddSeconds(-1), workHouseZuzhuang, pronoteHeaderIds); double zuzhuangTransferIn = pidZuzhuangIn.Sum(P => P.ProduceTransferQuantity).Value; string xoIDs = ""; foreach (string xoid in pidZuzhuangIn.Select(D => D.InvoiceXOId).Distinct()) { xoIDs += "'" + xoid + "',"; } xoIDs = xoIDs.TrimEnd(','); //计算 组装现场 部门转入其他部门的数量 Model.ProduceInDepotDetail pidZuzhuangOut = produceInDepotDetailManager.SelectByThisWorkhouse(item.ProductId, dateEnd.AddSeconds(-1), workHouseZuzhuang, pronoteHeaderIds); double zuzhuangTransferOut = Convert.ToDouble(pidZuzhuangOut.ProduceTransferQuantity); //计算 从组装现场退回的 生产退料 double exitQty = produceMaterialExitDetailManager.SelectSumQtyFromZuzhuang(item.ProductId, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang, xoIDs); #region 查询商品对应的所有母件 入库 扣减 double deductionQty = 0; if (!string.IsNullOrEmpty(xoIDs)) { string proIds = ""; foreach (var str in parentProductDic.Keys) { proIds += "'" + str + "',"; } proIds = proIds.TrimEnd(','); if (!string.IsNullOrEmpty(proIds)) { //IList<Model.ProduceInDepotDetail> pids = produceInDepotDetailManager.SelectIndepotQty(proIds, dateEnd.AddSeconds(-1), workHouseChengpinZuzhuang, invoiceXOIds); IList <Model.ProduceInDepotDetail> pids = produceInDepotDetailManager.SelectIndepotQty(proIds, dateEnd.AddSeconds(-1), workHouseChengpinZuzhuang, xoIDs); //对应转到组装现场的生产入库单的客户订单,如果订单不在范围内,母件入库不扣减 foreach (var pid in pids) { deductionQty += Convert.ToDouble(pid.ProduceQuantity) * parentProductDic[pid.ProductId]; } //2018年8月1日22:51:32 对应的母件领到组装现场的数量 List <Model.ProduceMaterialdetails> pmds = produceMaterialdetailsManager.SelectMaterialsByProductIds(proIds, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang, xoIDs).ToList(); foreach (var pmd in pmds) { //如果母件有领料,对应抵消入库扣减 if (pids.Any(P => P.ProductId == pmd.ProductId)) { deductionQty -= pmd.Materialprocessum.HasValue ? pmd.Materialprocessum.Value * parentProductDic[pmd.ProductId] : 0; } else { Dictionary <string, double> fatherDic = new Dictionary <string, double>(); GetParentProductInfo("'" + pmd.ProductId + "'", fatherDic); if (pids.Any(P => fatherDic.Keys.Contains(P.ProductId))) { //deductionQty -= pmd.Materialprocessum.HasValue ? pmd.Materialprocessum.Value * parentProductDic[pmd.ProductId] * fatherDic[pids.First(P => fatherDic.Keys.Contains(P.ProductId)).ProductId] : 0; deductionQty -= pmd.Materialprocessum.HasValue ? pmd.Materialprocessum.Value * parentProductDic[pmd.ProductId] : 0; //这里是商品对应的半成品母件领料扣减,不是对应的成品母件(上面if才是对应的成品母件),所以系数乘以半成品母件的就够了. } } } deductionQty = deductionQty < 0 ? 0 : deductionQty; //2018年8月16日11:26:19 对应的母件退料,组装现场数量扣减 List <Model.ProduceMaterialExitDetail> pmeds = produceMaterialExitDetailManager.SelectSumQtyFromZuzhuangByPros(proIds, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang, xoIDs).ToList(); foreach (var pmed in pmeds) { exitQty += pmed.ProduceQuantity.Value * parentProductDic[pmed.ProductId]; } } } #endregion //double zuzhuangXianchang = zuzhuangTransferIn + materialQty - zuzhuangTransferOut - deductionQty; double zuzhuangXianchang = zuzhuangTransferIn + materialQty - zuzhuangTransferOut - deductionQty - exitQty; zuzhuangXianchang = zuzhuangXianchang < 0 ? 0 : zuzhuangXianchang; item.XianchangZuzhuang = zuzhuangXianchang; #endregion resultList.Add(new Book.Model.Product() { Id = item.Id, ProductVersion = item.ProductVersion, ProductName = item.ProductName, CustomerInvoiceXOId = phGroup.Key, XianchangYanpian = item.XianchangYanpian, XianchangZuzhuang = item.XianchangZuzhuang, HandbookId = item.HandbookId, CnName = item.CnName }); } #endregion } this.bindingSourceProduct.DataSource = resultList; this.gridControl1.RefreshDataSource(); }
private decimal CountSiteQuantity(string productId, DateTime dateEnd) { // 2018年7月3日22:17:36 改:只查询2018.1.1 之后的订单 DateTime startDate = new DateTime(2018, 1, 1); IList <Model.PronoteHeader> phList = pronoteHeaderManager.SelectByProductId(startDate, dateEnd.AddSeconds(-1), productId); //if (phList == null || phList.Count == 0) // return 0; string pronoteHeaderIds = ""; string invoiceXOIds = ""; string allInvoiceXOIds = ""; #region 验片:合计前单位转入 - 合计生产数量(包含合计合格数量,合计不良品) double yanpianTransferIn = 0; double yanpianProcedures = 0; double yanpianBuliang = 0; double yanpianXianchang = 0; if (phList != null && phList.Count > 0) { foreach (var ph in phList) { pronoteHeaderIds += "'" + ph.PronoteHeaderID + "',"; invoiceXOIds += "'" + ph.InvoiceXOId + "',"; } pronoteHeaderIds = pronoteHeaderIds.TrimEnd(','); allInvoiceXOIds = invoiceXOIds = invoiceXOIds.TrimEnd(','); //计算所有转入 验片 部门的数量 Model.ProduceInDepotDetail pidYanpianIn = produceInDepotDetailManager.SelectByNextWorkhouse(productId, dateEnd.AddSeconds(-1), workHouseYanpian, pronoteHeaderIds); yanpianTransferIn = Convert.ToDouble(pidYanpianIn.ProduceTransferQuantity); //计算 验片 部门的生产数量 Model.ProduceInDepotDetail pidYanpianOut = produceInDepotDetailManager.SelectByThisWorkhouse(productId, dateEnd.AddSeconds(-1), workHouseYanpian, pronoteHeaderIds); yanpianProcedures = Convert.ToDouble(pidYanpianOut.ProceduresSum); yanpianBuliang = Convert.ToDouble(pidYanpianOut.ProceduresSum - pidYanpianOut.CheckOutSum); yanpianXianchang = yanpianTransferIn - yanpianProcedures; yanpianXianchang = yanpianXianchang < 0 ? 0 : yanpianXianchang; } #endregion #region 组装现场:合计前单位转入+ 合计领料单领出 - 合计出库数量(合计转生产到其他部门,成品入库数量换算后扣减数量)- 生产退料(从组装现场退的) double zuzhuangTransferIn = 0; double zuzhuangTransferOut = 0; double exitQty = 0; double deductionQty = 0; //领到 组装现场 部门的数量 double materialQty = 0; //materialQty = produceMaterialdetailsManager.SelectMaterialQty(productId, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang); //2018年7月9日23:07:51 领料单所包含的未结案订单号码拉出来,用于查询母件入库扣减 System.Data.DataTable dt = produceMaterialdetailsManager.SelectMaterialQty(productId, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang, invoiceXOIds); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { materialQty += Convert.ToDouble(dr["Materialprocessum"].ToString()); if (!invoiceXOIds.Contains(dr["InvoiceId"].ToString())) { allInvoiceXOIds = "'" + dr["InvoiceId"].ToString() + "'," + allInvoiceXOIds; } } allInvoiceXOIds = allInvoiceXOIds.TrimEnd(','); } #region 查询商品对应的所有母件 入库 扣减 //if (!string.IsNullOrEmpty(xoIDs)) //if (!string.IsNullOrEmpty(invoiceXOIds)) if (!string.IsNullOrEmpty(allInvoiceXOIds)) { Dictionary <string, double> parentProductDic = new Dictionary <string, double>(); GetParentProductInfo("'" + productId + "'", parentProductDic); string proIds = ""; foreach (var str in parentProductDic.Keys) { proIds += "'" + str + "',"; } proIds = proIds.TrimEnd(','); if (!string.IsNullOrEmpty(proIds)) { //IList<Model.ProduceInDepotDetail> pids = produceInDepotDetailManager.SelectIndepotQty(proIds, dateEnd.AddSeconds(-1), workHouseChengpinZuzhuang, xoIDs); //对应转到组装现场的生产入库单的客户订单,如果订单不在范围内,母件入库不扣减 //IList<Model.ProduceInDepotDetail> pids = produceInDepotDetailManager.SelectIndepotQty(proIds, dateEnd.AddSeconds(-1), workHouseChengpinZuzhuang, invoiceXOIds); //2018年7月9日23:21:00 加上领料单对应的订单 IList <Model.ProduceInDepotDetail> pids = produceInDepotDetailManager.SelectIndepotQty(proIds, dateEnd.AddSeconds(-1), workHouseChengpinZuzhuang, allInvoiceXOIds); foreach (var pid in pids) { deductionQty += Convert.ToDouble(pid.ProduceQuantity) * parentProductDic[pid.ProductId]; } //2018年8月1日22:51:32 对应的母件领到组装现场的数量 List <Model.ProduceMaterialdetails> pmds = produceMaterialdetailsManager.SelectMaterialsByProductIds(proIds, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang, allInvoiceXOIds).ToList(); foreach (var pmd in pmds) { //如果母件有领料,对应抵消入库扣减 if (pids.Any(P => P.ProductId == pmd.ProductId)) { deductionQty -= pmd.Materialprocessum.HasValue ? pmd.Materialprocessum.Value * parentProductDic[pmd.ProductId] : 0; } else { Dictionary <string, double> fatherDic = new Dictionary <string, double>(); GetParentProductInfo("'" + pmd.ProductId + "'", fatherDic); if (pids.Any(P => fatherDic.Keys.Contains(P.ProductId))) { deductionQty -= pmd.Materialprocessum.HasValue ? pmd.Materialprocessum.Value * parentProductDic[pmd.ProductId] * fatherDic[pids.First(P => fatherDic.Keys.Contains(P.ProductId)).ProductId] : 0; } } } deductionQty = deductionQty < 0 ? 0 : deductionQty; //2018年8月16日11:26:19 对应的母件退料,组装现场数量扣减 List <Model.ProduceMaterialExitDetail> pmeds = produceMaterialExitDetailManager.SelectSumQtyFromZuzhuangByPros(proIds, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang, allInvoiceXOIds).ToList(); foreach (var pmed in pmeds) { exitQty += pmed.ProduceQuantity.Value * parentProductDic[pmed.ProductId]; } } } #endregion //计算 从组装现场退回的 生产退料 exitQty += produceMaterialExitDetailManager.SelectSumQtyFromZuzhuang(productId, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang, allInvoiceXOIds); #region 计算所有转入 组装现场 部门的数量 if (phList != null && phList.Count > 0) { IList <Model.ProduceInDepotDetail> pidZuzhuangIn = produceInDepotDetailManager.SelectTransZuZhuangXianChang(productId, dateEnd.AddSeconds(-1), workHouseZuzhuang, pronoteHeaderIds); zuzhuangTransferIn = pidZuzhuangIn.Sum(P => P.ProduceTransferQuantity).Value; //计算 组装现场 部门转入其他部门的数量 Model.ProduceInDepotDetail pidZuzhuangOut = produceInDepotDetailManager.SelectByThisWorkhouse(productId, dateEnd.AddSeconds(-1), workHouseZuzhuang, pronoteHeaderIds); zuzhuangTransferOut = Convert.ToDouble(pidZuzhuangOut.ProduceTransferQuantity); } #endregion //double zuzhuangXianchang = zuzhuangTransferIn + materialQty - zuzhuangTransferOut - deductionQty; double zuzhuangXianchang = zuzhuangTransferIn + materialQty - zuzhuangTransferOut - deductionQty - exitQty; zuzhuangXianchang = zuzhuangXianchang < 0 ? 0 : zuzhuangXianchang; #endregion return((decimal)zuzhuangXianchang + (decimal)yanpianXianchang); }
private void btn_Search_Click(object sender, EventArgs e) { if (this.date_End.EditValue == null) { MessageBox.Show("请先选择查询日期", "提示", MessageBoxButtons.OK); return; } if (this.lue_ProductCategory.EditValue == null) { MessageBox.Show("请先选择商品类别", "提示", MessageBoxButtons.OK); return; } DateTime dateEnd = this.date_End.DateTime.Date.AddDays(1); string handBookId = this.cob_HandBookId.Text; string depotId = this.lookUpEditDepotStar.EditValue == null ? "" : this.lookUpEditDepotStar.EditValue.ToString(); listProduct = productManager.SelectIdAndStock(this.lue_ProductCategory.EditValue == null ? null : this.lue_ProductCategory.EditValue.ToString(), this.lue_ProductCategoryEnd.EditValue == null ? null : this.lue_ProductCategoryEnd.EditValue.ToString(), depotId); IList <Model.StockSeach> stockList = new List <Model.StockSeach>(); string workHouseYanpian = workHouseManager.SelectWorkHouseIdByName("验片"); string workHouseZuzhuang = workHouseManager.SelectWorkHouseIdByName("组装现场仓"); string workHouseChengpinZuzhuang = workHouseManager.SelectWorkHouseIdByName("成品组装"); foreach (Model.Product item in listProduct) { item.HandbookId = handBookId; item.StocksQuantity = item.StocksQuantity.HasValue ? item.StocksQuantity : 0; item.InitialQty = stockManager.SelectStockQuantity0(item.ProductId); #region 仓库数量 stockList = this.stockManager.SelectJiShi(item.ProductId, dateEnd, DateTime.Now); double panQty = 0; double outQty = 0; double inQty = 0; //如果有 盘点单,盘点算入(ex:由100→200,则算作入库(200-100=100)) if (stockList != null && stockList.Count > 0) { //0 出,1 入,3 盘点 2 调拨,库存不变 panQty = Convert.ToDouble(stockList.Where(I => I.InvoiceTypeIndex == 3).Sum(S => S.InvoiceQuantity - S.StockCheckBookQuantity)); outQty = Convert.ToDouble(stockList.Where(I => I.InvoiceTypeIndex == 0).Sum(S => S.InvoiceQuantity)); //出库数量 inQty = Convert.ToDouble(stockList.Where(I => I.InvoiceTypeIndex == 1 && !string.IsNullOrEmpty(I.PositionName)).Sum(S => S.InvoiceQuantity)); //入库数量 item.StocksQuantity = item.StocksQuantity + outQty - inQty - panQty; } #endregion #region 现场数量 这边改动,其他两个地方也要对应修改(1,Book.UI.Query.SceneStock 2,Book.UI.Settings.StockLimitations.AssemblySiteDifferenceForm) #region 验片:合计前单位转入 - 合计生产数量(包含合计合格数量,合计不良品) //查询商品对应的未结案加工单 2018年7月3日22:17:36 改:只查询2018.1.1 之后的订单 DateTime startDate = new DateTime(2018, 1, 1); IList <Model.PronoteHeader> phList = null; if (string.IsNullOrEmpty(handBookId)) //2018年12月7日20:52:30 : 加手册 { phList = pronoteHeaderManager.SelectByProductId(startDate, dateEnd.AddSeconds(-1), item.ProductId); } else { phList = pronoteHeaderManager.SelectByProductId(startDate, dateEnd.AddSeconds(-1), item.ProductId, handBookId); } //if (phList == null || phList.Count == 0) // continue; string pronoteHeaderIds = ""; string invoiceXOIds = ""; string allInvoiceXOIds = ""; if (phList != null && phList.Count > 0) { foreach (var ph in phList) { pronoteHeaderIds += "'" + ph.PronoteHeaderID + "',"; invoiceXOIds += "'" + ph.InvoiceXOId + "',"; } pronoteHeaderIds = pronoteHeaderIds.TrimEnd(','); allInvoiceXOIds = invoiceXOIds = invoiceXOIds.TrimEnd(','); //计算所有转入 验片 部门的数量 Model.ProduceInDepotDetail pidYanpianIn = produceInDepotDetailManager.SelectByNextWorkhouse(item.ProductId, dateEnd.AddSeconds(-1), workHouseYanpian, pronoteHeaderIds); double yanpianTransferIn = Convert.ToDouble(pidYanpianIn.ProduceTransferQuantity); //计算 验片 部门的生产数量 Model.ProduceInDepotDetail pidYanpianOut = produceInDepotDetailManager.SelectByThisWorkhouse(item.ProductId, dateEnd.AddSeconds(-1), workHouseYanpian, pronoteHeaderIds); double yanpianProcedures = Convert.ToDouble(pidYanpianOut.ProceduresSum); double yanpianBuliang = Convert.ToDouble(pidYanpianOut.ProceduresSum - pidYanpianOut.CheckOutSum); double yanpianXianchang = yanpianTransferIn - yanpianProcedures; yanpianXianchang = yanpianXianchang < 0 ? 0 : yanpianXianchang; item.XianchangYanpian = yanpianXianchang; } #endregion #region 组装现场:合计前单位转入+ 合计领料单领出 - 合计出库数量(合计转生产到其他部门,成品入库数量换算后扣减数量) 2018年5月22日21:48:44,这边修改的时候对应到“组装现场盘点差异”也要修改 //2018年2月22日13:18:54: 组装现场:合计前单位转入+ 合计领料单领出 - 合计出库数量(合计转生产到其他部门,成品入库数量换算后扣减数量)- 生产退料(从组装现场退的) double zuzhuangTransferIn = 0; double zuzhuangTransferOut = 0; double exitQty = 0; double deductionQty = 0; //领到 组装现场 部门的数量 double materialQty = 0; //if (!string.IsNullOrEmpty(invoiceXOIds)) // materialQty = produceMaterialdetailsManager.SelectMaterialQty(item.ProductId, dateEnd.AddSeconds(-1), workHouseZuzhuang, invoiceXOIds); //2018年5月17日00:34:42 只要是未结案的订单领到组装现场的都计入 2018年7月3日22:17:36 改:只查询2017.10.1 之后的订单 //materialQty = produceMaterialdetailsManager.SelectMaterialQty(item.ProductId, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang); //2018年7月9日23:07:51 领料单所包含的未结案订单号码拉出来,用于查询母件入库扣减 System.Data.DataTable dt = null; //2018年12月7日21:19:44 :增加手册 if (string.IsNullOrEmpty(handBookId)) { dt = produceMaterialdetailsManager.SelectMaterialQty(item.ProductId, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang, invoiceXOIds); } else { dt = produceMaterialdetailsManager.SelectMaterialQty(item.ProductId, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang, invoiceXOIds, handBookId); } if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { materialQty += Convert.ToDouble(dr["Materialprocessum"].ToString()); if (!invoiceXOIds.Contains(dr["InvoiceId"].ToString())) { allInvoiceXOIds = "'" + dr["InvoiceId"].ToString() + "'," + allInvoiceXOIds; } } allInvoiceXOIds = allInvoiceXOIds.TrimEnd(','); } #region 查询商品对应的所有母件 入库 扣减 //if (!string.IsNullOrEmpty(xoIDs)) //if (!string.IsNullOrEmpty(invoiceXOIds)) if (!string.IsNullOrEmpty(allInvoiceXOIds)) { Dictionary <string, double> parentProductDic = new Dictionary <string, double>(); GetParentProductInfo("'" + item.ProductId + "'", parentProductDic); string proIds = ""; foreach (var str in parentProductDic.Keys) { proIds += "'" + str + "',"; } proIds = proIds.TrimEnd(','); if (!string.IsNullOrEmpty(proIds)) { //IList<Model.ProduceInDepotDetail> pids = produceInDepotDetailManager.SelectIndepotQty(proIds, dateEnd.AddSeconds(-1), workHouseChengpinZuzhuang, xoIDs); //对应转到组装现场的生产入库单的客户订单,如果订单不在范围内,母件入库不扣减 //IList<Model.ProduceInDepotDetail> pids = produceInDepotDetailManager.SelectIndepotQty(proIds, dateEnd.AddSeconds(-1), workHouseChengpinZuzhuang, invoiceXOIds); //2018年7月9日23:21:00 加上领料单对应的订单 IList <Model.ProduceInDepotDetail> pids = produceInDepotDetailManager.SelectIndepotQty(proIds, dateEnd.AddSeconds(-1), workHouseChengpinZuzhuang, allInvoiceXOIds); foreach (var pid in pids) { deductionQty += Convert.ToDouble(pid.ProduceQuantity) * parentProductDic[pid.ProductId]; } //2018年8月1日22:51:32 对应的母件领到组装现场的数量 List <Model.ProduceMaterialdetails> pmds = produceMaterialdetailsManager.SelectMaterialsByProductIds(proIds, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang, allInvoiceXOIds).ToList(); foreach (var pmd in pmds) { //如果母件有领料,对应抵消入库扣减 if (pids.Any(P => P.ProductId == pmd.ProductId)) { deductionQty -= pmd.Materialprocessum.HasValue ? pmd.Materialprocessum.Value * parentProductDic[pmd.ProductId] : 0; } else { Dictionary <string, double> fatherDic = new Dictionary <string, double>(); GetParentProductInfo("'" + pmd.ProductId + "'", fatherDic); if (pids.Any(P => fatherDic.Keys.Contains(P.ProductId))) { //deductionQty -= pmd.Materialprocessum.HasValue ? pmd.Materialprocessum.Value * parentProductDic[pmd.ProductId] * fatherDic[pids.First(P => fatherDic.Keys.Contains(P.ProductId)).ProductId] : 0; deductionQty -= pmd.Materialprocessum.HasValue ? pmd.Materialprocessum.Value * parentProductDic[pmd.ProductId] : 0; //这里是商品对应的半成品母件领料扣减,不是对应的成品母件(上面if才是对应的成品母件),所以系数乘以半成品母件的就够了. } } } deductionQty = deductionQty < 0 ? 0 : deductionQty; //2018年8月16日11:26:19 对应的母件退料,组装现场数量扣减 List <Model.ProduceMaterialExitDetail> pmeds = produceMaterialExitDetailManager.SelectSumQtyFromZuzhuangByPros(proIds, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang, allInvoiceXOIds).ToList(); foreach (var pmed in pmeds) { exitQty += pmed.ProduceQuantity.Value * parentProductDic[pmed.ProductId]; } } } #endregion //计算 从组装现场退回的 生产退料 exitQty += produceMaterialExitDetailManager.SelectSumQtyFromZuzhuang(item.ProductId, startDate, dateEnd.AddSeconds(-1), workHouseZuzhuang, allInvoiceXOIds); #region 计算所有转入 组装现场 部门的数量 if (phList != null && phList.Count > 0) { //Model.ProduceInDepotDetail pidZuzhuangIn = produceInDepotDetailManager.SelectByNextWorkhouse(item.ProductId, dateEnd.AddSeconds(-1), workHouseZuzhuang, null); //转入组装现场时没有加工单 //double zuzhuangTransferIn = Convert.ToDouble(pidZuzhuangIn.ProduceTransferQuantity); IList <Model.ProduceInDepotDetail> pidZuzhuangIn = produceInDepotDetailManager.SelectTransZuZhuangXianChang(item.ProductId, dateEnd.AddSeconds(-1), workHouseZuzhuang, pronoteHeaderIds); zuzhuangTransferIn = pidZuzhuangIn.Sum(P => P.ProduceTransferQuantity).Value; //计算 组装现场 部门转入其他部门的数量 Model.ProduceInDepotDetail pidZuzhuangOut = produceInDepotDetailManager.SelectByThisWorkhouse(item.ProductId, dateEnd.AddSeconds(-1), workHouseZuzhuang, pronoteHeaderIds); zuzhuangTransferOut = Convert.ToDouble(pidZuzhuangOut.ProduceTransferQuantity); } #endregion //double zuzhuangXianchang = zuzhuangTransferIn + materialQty - zuzhuangTransferOut - deductionQty; double zuzhuangXianchang = zuzhuangTransferIn + materialQty - zuzhuangTransferOut - deductionQty - exitQty; zuzhuangXianchang = zuzhuangXianchang < 0 ? 0 : zuzhuangXianchang; item.XianchangZuzhuang = zuzhuangXianchang; #endregion #endregion } if (!checkEdit1.Checked) //不显示0库存商品 { listProduct = listProduct.Where(p => p.XianchangZuzhuang != 0).ToList(); } this.bindingSourceProduct.DataSource = listProduct; }