示例#1
0
        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;

            listProduct = productManager.SelectIdAndStock(this.lue_ProductCategory.EditValue == null ? null : this.lue_ProductCategory.EditValue.ToString(), null, null);

            IList <Model.StockSeach> stockList = new List <Model.StockSeach>();

            string workHousePendingArea = 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 待转区库存:合计前单位转入 - 合计转出/入库 ,从2019.1.1开始计算
                DateTime startDate = new DateTime(2019, 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     = "";

                if (phList != null && phList.Count > 0)
                {
                    foreach (var ph in phList)
                    {
                        pronoteHeaderIds += "'" + ph.PronoteHeaderID + "',";
                        invoiceXOIds     += "'" + ph.InvoiceXOId + "',";
                    }
                    pronoteHeaderIds = pronoteHeaderIds.TrimEnd(',');
                    invoiceXOIds     = invoiceXOIds.TrimEnd(',');

                    //计算所有转入 仓库待转区 部门的数量
                    Model.ProduceInDepotDetail pidYanpianIn = produceInDepotDetailManager.SelectByNextWorkhouse(item.ProductId, dateEnd.AddSeconds(-1), workHousePendingArea, pronoteHeaderIds);
                    double pendingAreaTransferIn            = Convert.ToDouble(pidYanpianIn.ProduceTransferQuantity);

                    //计算 仓库待转区 部门的转出/入库 数量
                    Model.ProduceInDepotDetail pidYanpianOut = produceInDepotDetailManager.SelectByThisWorkhouse(item.ProductId, dateEnd.AddSeconds(-1), workHousePendingArea, pronoteHeaderIds);
                    double pendingAreaTransferOut            = Convert.ToDouble(pidYanpianOut.ProduceTransferQuantity);
                    double pendingAreaInDepot = Convert.ToDouble(pidYanpianOut.ProduceQuantity);


                    double pendingAreaStock = pendingAreaTransferIn - pendingAreaTransferOut - pendingAreaInDepot;
                    pendingAreaStock = pendingAreaStock < 0 ? 0 : pendingAreaStock;

                    item.PendingAreaStock = pendingAreaStock;
                }

                #endregion
            }

            this.bindingSourceProduct.DataSource = listProduct;
        }
示例#2
0
        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;
        }