Exemple #1
0
        /// <summary>根据主商品ID查询其当前仓库子商品的库存信息
        /// </summary>
        /// <param name="goodsId"></param>
        /// <param name="warehouseId"></param>
        /// <param name="hostingFilialeId"></param>
        /// <returns></returns>
        public IList <GoodsStockPileInfo> GetChildGoodsStockPileList(Guid goodsId, Guid warehouseId, Guid hostingFilialeId)
        {
            if (goodsId == Guid.Empty)
            {
                return(new List <GoodsStockPileInfo>());
            }
            var goodsInfo = _goodsCenterSao.GetGoodsBaseInfoById(goodsId);

            if (goodsInfo == null)
            {
                return(new List <GoodsStockPileInfo>());
            }
            var goodsStockPileList = new List <GoodsStockPileInfo>();

            //根据主商品获取所有子商品信息
            var childGoodsList = _goodsCenterSao.GetRealGoodsListByGoodsId(new List <Guid> {
                goodsId
            }).ToList();

            if (childGoodsList.Count > 0)
            {
                var goodsIds = childGoodsList.Select(w => w.RealGoodsId).ToList();
                var dicRealGoodsIdAndStockQuantity = WMSSao.GoodsCanUsableStockForDicRealGoodsIdAndStockQuantity(warehouseId, null, goodsIds, hostingFilialeId);
                if (dicRealGoodsIdAndStockQuantity != null && dicRealGoodsIdAndStockQuantity.Count > 0)
                {
                    var goodsIdList = new List <Guid> {
                        goodsId
                    };
                    //根据仓库Id获取供应商Id
                    var dicGoodsIdAndCompanyId = _purchaseSet.GetCompanyIdByWarehouseId(warehouseId, hostingFilialeId);
                    var companyIdList          = dicGoodsIdAndCompanyId.Where(p => goodsIdList.Contains(p.Key)).Select(p => p.Value).ToList();
                    //获取商品的最后一次进货价信息
                    var goodsPurchaseLastPriceInfoList = _storageRecordDao.GetGoodsPurchaseLastPriceInfoByWarehouseId(warehouseId);
                    goodsPurchaseLastPriceInfoList = goodsPurchaseLastPriceInfoList.Where(p => goodsIdList.Contains(p.GoodsId) && companyIdList.Contains(p.ThirdCompanyId)).ToList();

                    //返回库存>0的子商品
                    foreach (var childGoodsInfo in childGoodsList)
                    {
                        //可出库数
                        var goodsStockKeyValuePair = dicRealGoodsIdAndStockQuantity.FirstOrDefault(w => w.Key == childGoodsInfo.RealGoodsId);
                        //根据商品id获取供应商
                        var companyId = dicGoodsIdAndCompanyId.ContainsKey(childGoodsInfo.GoodsId) ? dicGoodsIdAndCompanyId[childGoodsInfo.GoodsId] : Guid.Empty;

                        decimal unitPrice = 0;
                        GoodsPurchaseLastPriceInfo goodsPurchaseLastPriceInfo = null;
                        if (goodsPurchaseLastPriceInfoList.Count > 0)
                        {
                            goodsPurchaseLastPriceInfo = goodsPurchaseLastPriceInfoList.FirstOrDefault(p => p.GoodsId.Equals(childGoodsInfo.GoodsId) && p.ThirdCompanyId.Equals(companyId));
                            unitPrice = goodsPurchaseLastPriceInfo != null ? goodsPurchaseLastPriceInfo.UnitPrice : 0;
                        }
                        var goodsStockPileInfo = new GoodsStockPileInfo
                        {
                            GoodsId                  = childGoodsInfo.RealGoodsId,
                            GoodsName                = goodsInfo.GoodsName,
                            GoodsCode                = goodsInfo.GoodsCode,
                            Specification            = childGoodsInfo.Specification,
                            UnitPrice                = unitPrice,
                            NonceWarehouseGoodsStock = goodsStockKeyValuePair.Value,
                            RecentInDate             = goodsPurchaseLastPriceInfo != null ? goodsPurchaseLastPriceInfo.LastPriceDate : DateTime.MinValue
                        };
                        goodsStockPileList.Add(goodsStockPileInfo);
                    }
                }
            }
            return(goodsStockPileList);
            //IList<GoodsStockQuantityInfo> stockQuantityList = _stockCenterManager.GetChildGoodsQuantity(goodsId);
            //var result = from item in stockQuantityList.Where(ent => ent.FilialeId == warehouseInfo.FilialeId && ent.WarehouseId == warehouseId)
            //             select new GoodsStockPileInfo
            //             {
            //                 GoodsId = item.RealGoodsId,
            //                 GoodsName = item.GoodsName,
            //                 GoodsCode = item.GoodsCode,
            //                 Specification = item.Specification,
            //                 UnitPrice = item.RecentInPrice,
            //                 NonceWarehouseGoodsStock = item.CurrentQuantity,
            //                 WaitConsignmentedGoodsStock = item.OutboundQuantity,
            //                 RecentInDate = item.RecentCDate
            //             };
            //return result.ToList();
        }
Exemple #2
0
        /// <summary>绑定数据源
        /// </summary>
        protected void GridGoodsStock_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            IList <StockTurnOverInfo> stockTurnOverList = new List <StockTurnOverInfo>();

            if (!WarehouseId.Equals(Guid.Empty))
            {
                //选择了责任人,则获取当前责任人负责的商品ID集合
                var goodsIds = new List <Guid>();
                if (PersonnelId != Guid.Empty || CompanyId != Guid.Empty)
                {
                    goodsIds = _purchaseSet.GetGoodsIdByPersonnelId(PersonnelId, CompanyId).ToList();
                }
                //根据条件获取商品信息
                List <GoodsPerformance> goodsList = _goodsCenterSao.GetGoodsPerformanceList(GoodsClassId, goodsIds,
                                                                                            GoodsNameOrCode, CB_IsPerformance.Checked);
                var tempGoodsIds = new List <Guid>();
                //var isNeedStock = true;
                switch (State)
                {
                case 0:     //全部
                    tempGoodsIds = goodsList.Select(ent => ent.GoodsId).ToList();
                    break;

                case 1:     //下架缺货有库存
                            //备注:  PurchaseState 0下架, 1上架
                    tempGoodsIds.AddRange(from item in goodsList
                                          where item.IsScarcity || item.PurchaseState == 0
                                          select item.GoodsId);
                    //isNeedStock = true;
                    break;

                case 2:     //无销售商品
                    tempGoodsIds.AddRange(from item in goodsList
                                          where !_salesDic.ContainsKey(item.GoodsId)
                                          select item.GoodsId);
                    var newGoodsList =
                        tempGoodsIds.Select(goodsId => goodsList.FirstOrDefault(ent => ent.GoodsId == goodsId)).ToList();
                    goodsList.Clear();
                    goodsList.AddRange(newGoodsList);
                    break;
                }

                //获取商品库存信息
                var goodsStockList = WMSSao.StockSearchByGoodsIds(tempGoodsIds, WarehouseId, FilialeId) ?? new Dictionary <Guid, int>();
                //获取所有的商品采购设置
                var allGoodsPurchaseSet = _purchaseSet.GetAllPurchaseSet(WarehouseId);

                var companyIdList = allGoodsPurchaseSet.Select(p => p.CompanyId).Distinct().ToList();
                //获取商品的最后一次进货价信息
                var goodsPurchaseLastPriceInfoList = _storageRecordDao.GetGoodsPurchaseLastPriceInfoByWarehouseId(WarehouseId);
                goodsPurchaseLastPriceInfoList = goodsPurchaseLastPriceInfoList.Where(p => tempGoodsIds.Contains(p.GoodsId) && companyIdList.Contains(p.ThirdCompanyId)).ToList();

                foreach (var goodsInfo in goodsList)
                {
                    // ReSharper disable once UseObjectOrCollectionInitializer
                    var info = new StockTurnOverInfo();
                    info.GoodsID   = goodsInfo.GoodsId;
                    info.GoodsName = goodsInfo.GoodsName;
                    info.GoodsCode = goodsInfo.GoodsCode;
                    info.IsStatisticalPerformance    = goodsInfo.IsStatisticalPerformance;
                    info.IsStatisticalPerformanceStr = goodsInfo.IsStatisticalPerformance ? "√" : string.Empty;
                    info.IsScarcity    = goodsInfo.IsScarcity;
                    info.IsScarcityStr = goodsInfo.IsScarcity ? "√" : string.Empty;
                    info.State         = goodsInfo.PurchaseState == 0;
                    info.IsStateStr    = goodsInfo.PurchaseState == 0 ? "√" : string.Empty;
                    //库存信息获取
                    var stockQuantity = goodsStockList.ContainsKey(goodsInfo.GoodsId)
                        ? goodsStockList[goodsInfo.GoodsId]
                        : 0;
                    if (stockQuantity <= 0)
                    {
                        continue;
                    }
                    info.StockNums = stockQuantity;
                    if (!_salesDic.ContainsKey(goodsInfo.GoodsId))
                    {
                        info.StockNumSort = stockQuantity;
                    }

                    //责任人供应商信息获取
                    var tempGoodsPurchaseSetInfo = allGoodsPurchaseSet.FirstOrDefault(ent => ent.GoodsId == goodsInfo.GoodsId);

                    //根据商品id获取供应商
                    var companyId = tempGoodsPurchaseSetInfo != null ? tempGoodsPurchaseSetInfo.CompanyId : Guid.Empty;

                    decimal unitPrice = 0;
                    GoodsPurchaseLastPriceInfo goodsPurchaseLastPriceInfo = null;
                    if (goodsPurchaseLastPriceInfoList.Count > 0)
                    {
                        goodsPurchaseLastPriceInfo = goodsPurchaseLastPriceInfoList.FirstOrDefault(p => p.GoodsId.Equals(goodsInfo.GoodsId) && p.ThirdCompanyId.Equals(companyId));
                        unitPrice = goodsPurchaseLastPriceInfo != null ? goodsPurchaseLastPriceInfo.UnitPrice : 0;
                    }
                    info.RecentInPrice = unitPrice;
                    info.RecentCDate   = (goodsPurchaseLastPriceInfo != null ? goodsPurchaseLastPriceInfo.LastPriceDate : DateTime.MinValue).ToString("yyyy-MM-dd");

                    if (tempGoodsPurchaseSetInfo != null)
                    {
                        info.PersonResponsible = tempGoodsPurchaseSetInfo.PersonResponsible;
                        var firstOrDefault = PersonnelList.FirstOrDefault(ent => ent.PersonnelId == tempGoodsPurchaseSetInfo.PersonResponsible);
                        if (firstOrDefault != null)
                        {
                            info.PersonResponsibleName = firstOrDefault.RealName;
                        }
                        info.CompanyId   = tempGoodsPurchaseSetInfo.CompanyId;
                        info.CompanyName = tempGoodsPurchaseSetInfo.CompanyName;
                    }
                    //销售数量
                    if (_salesDic.ContainsKey(goodsInfo.GoodsId))
                    {
                        info.SaleNums     = _salesDic[goodsInfo.GoodsId];
                        info.SaleNumSort  = 1;
                        info.StockNumSort = 0;
                    }

                    #region [计算商品库存周转情况(天数)]
                    if (info.State && info.StockNums == 0)
                    {
                        info.TurnOverDays = 0;
                        info.TurnOverStr  = "下架";
                    }
                    else if (info.State && info.StockNums != 0)
                    {
                        info.TurnOverDays = 0;
                        info.TurnOverStr  = "下架有库存";
                    }
                    else if (info.IsScarcity && info.StockNums == 0)
                    {
                        info.TurnOverDays = 0;
                        info.TurnOverStr  = "缺货";
                    }
                    else if (info.IsScarcity && info.StockNums != 0)
                    {
                        info.TurnOverDays = 0;
                        info.TurnOverStr  = "缺货有库存";
                    }
                    else if (info.StockNums == 0)
                    {
                        info.TurnOverDays = 0;
                        info.TurnOverStr  = "0天";
                    }
                    else if (info.SaleNums > 0)
                    {
                        var tempTurnOverDays = info.StockNums * 30 / info.SaleNums;
                        info.TurnOverDays = tempTurnOverDays;
                        info.TurnOverStr  = tempTurnOverDays + "天";
                    }
                    else
                    {
                        info.TurnOverDays = 0;
                        info.TurnOverStr  = "无销售";
                    }
                    #endregion

                    #region [计算商品报备周转天数]

                    if (_weightedAverageSaleDic.ContainsKey(info.GoodsID))
                    {
                        var weightedAverageSale = _weightedAverageSaleDic[info.GoodsID];
                        if (_weightedAverageSaleDic[info.GoodsID] != 0)
                        {
                            info.TurnOverByFiling = info.StockNums * 30 / weightedAverageSale + "天";
                        }
                    }

                    #endregion

                    stockTurnOverList.Add(info);
                }
            }
            var pageIndex = GridGoodsStock.CurrentPageIndex;
            var pageSize  = GridGoodsStock.PageSize;
            stockTurnOverList               = stockTurnOverList.OrderBy(ent => ent.SaleNumSort).ThenByDescending(ent => ent.StockNumSort).ThenByDescending(ent => ent.TurnOverDays).ToList();
            GridGoodsStock.DataSource       = stockTurnOverList.Skip(pageIndex * pageSize).Take(pageSize).ToList();
            GridGoodsStock.VirtualItemCount = stockTurnOverList.Count;
        }
        /// <summary>绑定数据源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridGoodsStock_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            GridGoodsStock.MasterTableView.Columns[2].Display = IsPostBack;
            IList <GoodsStockSearchInfo> goodsStockSearchList = new List <GoodsStockSearchInfo>();
            var pageIndex  = GridGoodsStock.CurrentPageIndex + 1;
            int pageSize   = GridGoodsStock.PageSize;
            int totalCount = 0;

            if (IsPostBack)
            {
                if (WarehouseId == Guid.Empty)
                {
                    RAM.Alert("您没有授权的仓库!");
                }
                else
                {
                    var goodsIdList = new List <Guid>();
                    if (CompanyId != Guid.Empty)
                    {
                        var purchaseings = _purchaseSet.GetPurchaseSetListByWarehouseIdAndCompanyId(WarehouseId, CompanyId);
                        if (purchaseings.Count == 0)
                        {
                            RAM.Alert("系统提示:当前选择供应商没有设置相关商品,无法为您查询库存信息!");
                            return;
                        }
                        goodsIdList = purchaseings.Select(act => act.GoodsId).ToList();
                    }
                    var goodsInfoList = _goodsCenterSao.GetGoodsStockGridList(GoodsClassId, SearchText, goodsIdList, pageIndex, pageSize, out totalCount).ToList();
                    if (goodsInfoList.Count > 0)
                    {
                        var goodsIds       = goodsInfoList.Select(ent => ent.GoodsId).ToList();
                        var childGoodsList = _goodsCenterSao.GetRealGoodsListByGoodsId(goodsIds).ToList();
                        var list           = WMSSao.StockSearchList(childGoodsList.Select(ent => ent.RealGoodsId), WarehouseId, HostingFilialeId);
                        FilialeDic =
                            (from item in list.GroupBy(ent => ent.FilialeId) let filiale = item.First() select filiale)
                            .ToDictionary(k => k.FilialeId, v => v.FilialeName);
                        Dictionary <Guid, List <Guid> >            dics        = new Dictionary <Guid, List <Guid> >();
                        Dictionary <Guid, Dictionary <Guid, int> > goodsStocks = new Dictionary <Guid, Dictionary <Guid, int> >();
                        //根据仓库Id获取供应商Id
                        var dicGoodsIdAndCompanyId = _purchaseSet.GetAllPurchaseSet(WarehouseId);
                        //获取商品的最后一次进货价信息
                        var goodsPurchaseLastPriceInfoList = _storageRecordDao.GetGoodsPurchaseLastPriceInfoByWarehouseId(WarehouseId);
                        goodsPurchaseLastPriceInfoList = goodsPurchaseLastPriceInfoList.Where(p => goodsIds.Contains(p.GoodsId)).ToList();

                        foreach (var info in goodsInfoList)
                        {
                            var realGoodsIds = childGoodsList.Where(ent => ent.GoodsId == info.GoodsId).Select(ent => ent.RealGoodsId);
                            dics.Add(info.GoodsId, realGoodsIds.ToList());
                            goodsStocks.Add(info.GoodsId, new Dictionary <Guid, int>());
                            if (childGoodsList.Count > 0)
                            {
                                var goodsStockSearchInfo = new GoodsStockSearchInfo();
                                //根据商品id获取供应商
                                var companyIds = dicGoodsIdAndCompanyId.Where(ent => ent.GoodsId == info.GoodsId).Select(ent => ent.CompanyId);

                                decimal unitPrice = 0;
                                GoodsPurchaseLastPriceInfo goodsPurchaseLastPriceInfo = null;
                                if (goodsPurchaseLastPriceInfoList.Count > 0)
                                {
                                    goodsPurchaseLastPriceInfo = goodsPurchaseLastPriceInfoList.FirstOrDefault(p => p.GoodsId.Equals(info.GoodsId) && companyIds.Contains(p.ThirdCompanyId));
                                    unitPrice = goodsPurchaseLastPriceInfo != null ? goodsPurchaseLastPriceInfo.UnitPrice : 0;
                                }
                                goodsStockSearchInfo.RecentCDate   = goodsPurchaseLastPriceInfo != null ? goodsPurchaseLastPriceInfo.LastPriceDate : DateTime.MinValue;
                                goodsStockSearchInfo.RecentInPrice = unitPrice;

                                if (list != null && list.Count > 0)
                                {
                                    int quantity = 0;
                                    foreach (var item in list)
                                    {
                                        var filiaeQuantity = item.StockQuantity.Where(ent => realGoodsIds.Contains(ent.Key)).Sum(ent => ent.Value);
                                        quantity += filiaeQuantity;
                                        goodsStocks[info.GoodsId].Add(item.FilialeId, filiaeQuantity);
                                    }
                                    goodsStockSearchInfo.GoodsId         = info.GoodsId;
                                    goodsStockSearchInfo.GoodsName       = info.GoodsName;
                                    goodsStockSearchInfo.GoodsCode       = info.GoodsCode;
                                    goodsStockSearchInfo.IsScarcity      = info.IsStockScarcity;
                                    goodsStockSearchInfo.IsOnShelf       = info.IsOnShelf;
                                    goodsStockSearchInfo.CurrentQuantity = quantity;
                                    goodsStockSearchInfo.CurrentSumPrice = quantity * unitPrice;
                                }
                                else
                                {
                                    goodsStockSearchInfo.GoodsId    = info.GoodsId;
                                    goodsStockSearchInfo.GoodsName  = info.GoodsName;
                                    goodsStockSearchInfo.GoodsCode  = info.GoodsCode;
                                    goodsStockSearchInfo.IsScarcity = info.IsStockScarcity;
                                    goodsStockSearchInfo.IsOnShelf  = info.IsOnShelf;
                                }
                                goodsStockSearchList.Add(goodsStockSearchInfo);
                            }
                        }
                        StockSearchDic = goodsStocks;
                    }
                }
            }
            #region FooterText 统计显示
            var recentCDate = GridGoodsStock.MasterTableView.Columns.FindByUniqueName("RecentCDate");
            var isOnShelf   = GridGoodsStock.MasterTableView.Columns.FindByUniqueName("IsOnShelf");
            if (goodsStockSearchList.Count > 0)
            {
                var currentSumPrice = goodsStockSearchList.Sum(ent => ent.CurrentSumPrice);
                recentCDate.FooterText = "库存金额总计:";
                isOnShelf.FooterText   = WebControl.NumberSeparator(currentSumPrice.ToString("N"));
            }
            else
            {
                recentCDate.FooterText = "库存金额总计:-";
            }
            #endregion

            GridGoodsStock.DataSource       = goodsStockSearchList.OrderByDescending(w => w.CurrentQuantity).ToList();
            GridGoodsStock.VirtualItemCount = totalCount;
        }