Exemple #1
0
        public void TestIsAllianceShopFilialeByFilialeIdAndErrorMessage()
        {
            using (ShimsContext.Create())
            {
                string outMessage1;
                //模拟返回结果
                ShimFilialeSao.GetAllFiliale = () => new List <FilialeInfo> {
                    new FilialeInfo {
                        ID = new Guid("6E677868-AE98-4932-B4DB-0000020DC859"), Type = (int)FilialeType.EntityShop, IsActive = true
                    }
                };
                var expect1 = String.Empty;
                var result1 = FilialeManager.IsAllianceShopFiliale(new Guid("6E677868-AE98-4932-B4DB-0000020DC859"), out outMessage1);
                Assert.IsTrue(result1);
                Assert.AreEqual(expect1, outMessage1);

                string outMessage2;
                //模拟返回结果
                ShimFilialeSao.GetAllFiliale = () => new List <FilialeInfo> {
                    new FilialeInfo {
                        ID = new Guid("6E677868-AE98-4932-B4DB-0000020DC859"), Type = (int)FilialeType.EntityShop, IsActive = false
                    }
                };
                var expect2 = String.Empty;
                var result2 = FilialeManager.IsAllianceShopFiliale(new Guid("6E677868-AE98-4932-B4DB-0000020DC859"), out outMessage2);
                Assert.IsFalse(result2);
                Assert.AreEqual(expect2, outMessage2);

                string outMessage3;
                //模拟返回结果
                ShimFilialeSao.GetAllFiliale = () => new List <FilialeInfo> {
                    new FilialeInfo {
                        ID = new Guid("6E677868-AE98-4932-B4DB-0000020DC859"), Type = (int)FilialeType.SaleCompany, IsActive = true
                    }
                };
                var expect3 = String.Empty;
                var result3 = FilialeManager.IsAllianceShopFiliale(new Guid("6E677868-AE98-4932-B4DB-0000020DC859"), out outMessage3);
                Assert.IsFalse(result3);
                Assert.AreEqual(expect3, outMessage3);

                string outMessage4;
                var    expect4 = "公司信息未获取到";
                var    result4 = FilialeManager.IsAllianceShopFiliale(new Guid("00000000-0000-0000-0000-000000000000"), out outMessage4);
                Assert.IsFalse(result4);
                Assert.AreEqual(expect4, outMessage4);
            }
        }
Exemple #2
0
        public int AddNewApplyStock(ApplyStockInfo applyStockInfo, IList <ApplyStockDetailInfo> applyStockDetailInfoList, IDictionary <Guid, decimal> settledics, out string errorMsg)
        {
            var isalliance = FilialeManager.IsAllianceShopFiliale(applyStockInfo.FilialeId, out errorMsg);

            if (isalliance)//联盟店
            {
                if (applyStockInfo.CompanyWarehouseId == Guid.Empty)
                {
                    applyStockInfo.PurchaseType = (int)PurchaseType.FromPurchase;
                }

                var filialeInfo = FilialeManager.Get(applyStockInfo.CompanyId);
                applyStockInfo.CompanyName = filialeInfo != null && filialeInfo.ID != Guid.Empty ? filialeInfo.Name : "-";

                //新增加盟店采购申请添加时待确认
                if (applyStockInfo.StockState >= (int)ApplyStockState.Delivering)
                {
                    var goodsIds   = applyStockDetailInfoList.Select(ent => ent.CompGoodsID).Distinct().ToList();
                    var goodsInfos = _goodsInfoSao.GetGoodsListByGoodsIds(goodsIds);
                    if (goodsInfos == null || goodsInfos.Count != goodsIds.Count)
                    {
                        errorMsg = "GMS商品信息获取失败";
                        return(-1);
                    }
                    var hostingFilialeId = WMSSao.GetHostingFilialeIdByWarehouseIdGoodsTypes(applyStockInfo.CompanyWarehouseId, applyStockInfo.CompanyId, goodsInfos.Select(ent => ent.GoodsType).Distinct());
                    if (hostingFilialeId == Guid.Empty)
                    {
                        errorMsg = "获取仓库对应的物流公司失败";
                        return(-1);
                    }
                    var flag = IsMatchSendCondition(applyStockInfo, applyStockDetailInfoList, hostingFilialeId, goodsInfos.ToDictionary(k => k.GoodsId, v => v), settledics, out errorMsg);
                    //确认不通过修改采购申请状态为等待确认
                    if (!flag)
                    {
                        applyStockInfo.StockState = (int)ApplyStockState.Confirming;
                    }
                }
            }
            if (_applyStockDao.Insert(applyStockInfo) && _applyStockDao.InsertDetail(applyStockDetailInfoList) > 0)
            {
                errorMsg = "";
                return(applyStockInfo.StockState);
            }
            errorMsg = "添加申请明细时失败";
            return(-1);
        }
Exemple #3
0
        /// <summary>
        /// 新增门店采购单
        /// </summary>
        /// <param name="applyStockInfo"></param>
        /// <param name="applyStockDetailInfoList"></param>
        /// <param name="errorMsg"> </param>
        /// <returns>采购申请状态</returns>
        public int Add(ApplyStockInfo applyStockInfo, IList <ApplyStockDetailInfo> applyStockDetailInfoList, out string errorMsg)
        {
            int state = -1;

            try
            {
                var isalliance = FilialeManager.IsAllianceShopFiliale(applyStockInfo.FilialeId, out errorMsg);
                if (isalliance)//联盟店
                {
                    if (applyStockInfo.CompanyWarehouseId == Guid.Empty)
                    {
                        applyStockInfo.PurchaseType = (int)PurchaseType.FromPurchase;
                    }

                    var filialeInfo = FilialeManager.Get(applyStockInfo.CompanyId);
                    applyStockInfo.CompanyName = filialeInfo != null && filialeInfo.ID != Guid.Empty ? filialeInfo.Name : "-";

                    //新增加盟店采购申请添加时待确认
                    if (applyStockInfo.StockState >= (int)ApplyStockState.Delivering)
                    {
                        var goodsIds   = applyStockDetailInfoList.Select(ent => ent.CompGoodsID).Distinct().ToList();
                        var goodsInfos = _goodsInfoSao.GetGoodsListByGoodsIds(goodsIds);
                        if (goodsInfos == null || goodsInfos.Count != goodsIds.Count)
                        {
                            errorMsg = "GMS商品信息获取失败";
                            return(state);
                        }
                        var hostingFilialeId = WMSSao.GetHostingFilialeIdByWarehouseIdGoodsTypes(applyStockInfo.CompanyWarehouseId, applyStockInfo.CompanyId, goodsInfos.Select(ent => ent.GoodsType).Distinct());
                        if (hostingFilialeId == Guid.Empty)
                        {
                            errorMsg = "获取仓库对应的物流公司失败";
                            return(state);
                        }
                        var settleDics = _grossSettlementDal.GetLatestUnitPriceListByMultiGoods(hostingFilialeId, goodsIds);
                        var flag       = IsMatchSendCondition(applyStockInfo, applyStockDetailInfoList, hostingFilialeId, goodsInfos.ToDictionary(k => k.GoodsId, v => v), settleDics, out errorMsg);
                        //确认不通过修改采购申请状态为等待确认
                        if (!flag)
                        {
                            applyStockInfo.StockState = (int)ApplyStockState.Confirming;
                        }
                    }
                }
                using (var ts = new TransactionScope(TransactionScopeOption.Required))
                {
                    bool isSuccess = _applyStockDao.Insert(applyStockInfo);
                    if (isSuccess)
                    {
                        if (_applyStockDao.InsertDetail(applyStockDetailInfoList) > 0)
                        {
                            state = applyStockInfo.StockState;
                        }
                        else
                        {
                            isSuccess = false;
                            errorMsg  = "添加申请明细时失败";
                        }
                    }
                    else
                    {
                        errorMsg = "添加申请记录失败";
                    }
                    if (isSuccess)
                    {
                        ts.Complete();
                    }
                }
                return(state);
            }
            catch (Exception exp)
            {
                SAL.LogCenter.LogService.LogError(string.Format("新增采购申请报错: applyStockInfo={0}, applyStockDetailInfoList={1}", new Framework.Core.Serialize.JsonSerializer().Serialize(applyStockInfo), new Framework.Core.Serialize.JsonSerializer().Serialize(applyStockDetailInfoList)), "采购管理", exp);
                errorMsg = exp.Message;
                return(-1);
            }
        }