chengsc
2024-10-20 f8957ba7f0ade842553bd37254cf31da639a1925
Wms/WMS.BLL/BllSoServer/ExportNoticeServer.cs
@@ -262,10 +262,22 @@
        }
        //回传出库单
        public bool FinishSo(int id, string url, int userId)
        public bool FinishSo(int id, string url, string userNo, string pwd, int userId)
        {
            try
            {
                var loginPwd = Md5Tools.CalcMd5(pwd);
                var date = Db.Queryable<SysUserInfor>().First(m => m.IsDel == "0" && m.UserName == userNo && m.PassWord == loginPwd);
                if (date == null) //账号密码是否正确
                {
                    throw new Exception("账号密码不正确或没有此账号");
                }
                if (date.Status != "0") //当前账号是否正常启用
                {
                    throw new Exception("当前账号非启用状态");
                }
                var notice = Db.Queryable<BllExportNotice>().First(m => m.Id == id && m.IsDel == "0");
                if (notice == null)
                {
@@ -280,7 +292,7 @@
                {
                    throw new Exception("未查询到单据明细信息");
                }
                if (userId == notice.UpdateUser)
                if (date.Id == notice.UpdateUser)
                {
                    throw new Exception("复核失败,复核人员和关闭订单人员不能相同!");
                }
@@ -315,10 +327,10 @@
                notice.Status = "6";
                notice.CheckTime = DateTime.Now;
                notice.CheckUser = userId;
                notice.CheckUser = date.Id;
                Db.Updateable(notice).ExecuteCommand();
                new OperationSOServer().AddLogOperationSo("出库作业", "出库单据", notice.SONo, "复核", $"复核了单据号为{notice.SONo}的单据信息", userId);
                new OperationSOServer().AddLogOperationSo("出库作业", "出库单据", notice.SONo, "复核", $"{date.RealName}复核了单据号为{notice.SONo}的单据信息", userId);
                return true;
            }
            catch (Exception e)
@@ -433,16 +445,16 @@
                        inspectStatus = "0";
                        break;
                    case "4"://不合格品出库
                        skuType = "(0,1,2,3)";
                        skuType = "(0,1,2,3,4)";
                        inspectStatus = "2";
                        break;
                    case "5"://中间品出库
                        skuType = "(4)";
                        inspectStatus = "0,1";
                        inspectStatus = "1";
                        break;
                    case "6"://代储出库
                        skuType = "(0,1,2,3)";
                        inspectStatus = "0,1";
                        skuType = "(0,1,2,3,4)";
                        inspectStatus = "0,1,2";
                        break;
                    case "8"://寄存出库
                        skuType = "(0,1,2,3)";
@@ -475,7 +487,7 @@
                    .AndIF(!string.IsNullOrWhiteSpace(inspectStatus), it => inspectStatus.Contains(it.InspectStatus))
                    .And(m => skuList.Contains(m.SkuNo))
                    .AndIF(type == "6", m => m.OwnerNo == ownerNo)//代储出库需要关联货主
                    .AndIF(type == "2", m=> string.IsNullOrWhiteSpace(m.OwnerNo))
                    .AndIF(type != "6", m=> string.IsNullOrWhiteSpace(m.OwnerNo))
                    .AndIF(!string.IsNullOrWhiteSpace(msg), it => (it.SkuNo.Contains(msg) || it.SkuName.Contains(msg) || it.LotNo.Contains(msg)))
                    .And(it => (it.Qty - it.LockQty - it.FrozenQty) > 0)
                    .And(it => (it.Status == "0" || it.Status == "1"))
@@ -3217,26 +3229,63 @@
                {
                    throw new Exception("获取失败,未找到指定出库单!");
                }
                if (detail.Status != "0" && detail.Status != "1" && detail.AllotQty >= detail.Qty)
                {
                    throw new Exception("获取失败,出库单状态不是等待执行或分配中!");
                }
                if (detail.AllotQty >= detail.Qty)
                {
                    throw new Exception("获取失败,出库单已分配完成!");
                }
                var notice = Db.Queryable<BllExportNotice>().First(a => a.SONo == detail.SONo);
                if (notice == null)
                {
                    throw new Exception("获取失败,未找到指定出库单!");
                }
                if (notice.Status == "3" && detail.AllotQty >= detail.Qty || notice.Status == "4" || notice.Status == "5")
                if (notice.Type != "1" && notice.Type != "2" && notice.Type != "3")
                {
                    throw new Exception("获取失败,出库单状态不允许!");
                    if (detail.Status != "0" && detail.Status != "1" && detail.AllotQty >= detail.Qty)
                    {
                        throw new Exception("获取失败,出库单状态不是等待执行或分配中!");
                    }
                    if (detail.AllotQty >= detail.Qty)
                    {
                        throw new Exception("获取失败,出库单已分配完成!");
                    }
                    if (notice.Status == "3" && detail.AllotQty >= detail.Qty || notice.Status == "4" || notice.Status == "5")
                    {
                        throw new Exception("获取失败,出库单状态不允许!");
                    }
                }
                string inspectStatus = string.Empty;
                switch (notice.Type)//0:原料 1:包材 2:成品 3:耗材 4:半成品
                {
                    case "0"://成品出库
                        inspectStatus = "1";
                        break;
                    case "1"://领料出库
                        inspectStatus = "1";
                        break;
                    case "2"://抽检出库
                        inspectStatus = "0,1,2";
                        break;
                    case "3"://物料取样出库
                        inspectStatus = "0";
                        break;
                    case "4"://不合格品出库
                        inspectStatus = "2";
                        break;
                    case "5"://中间品出库
                        inspectStatus = "1";
                        break;
                    case "6"://代储出库
                        inspectStatus = "0,1,2";
                        break;
                    case "8"://寄存出库
                        inspectStatus = "0,1";
                        break;
                    default: //其它出库
                        inspectStatus = "0,1";
                        break;
                }
                #endregion
                Expression<Func<DataStockDetail, bool>> item = Expressionable.Create<DataStockDetail>()
                    .AndIF(!string.IsNullOrWhiteSpace(inspectStatus), m => inspectStatus.Contains(m.InspectStatus))
                    .AndIF(!string.IsNullOrWhiteSpace(houseNo), m => m.WareHouseNo == houseNo)
                    .AndIF(!string.IsNullOrWhiteSpace(roadwayNo), m => m.RoadwayNo == roadwayNo)
                    .AndIF(!string.IsNullOrWhiteSpace(locateNo), m => m.LocatNo == locateNo)
@@ -3284,29 +3333,36 @@
                {
                    throw new Exception("操作失败,未找到指定出库单详情!");
                }
                if (detail.AllotQty >= detail.Qty || (detail.Status != "0" && detail.Status != "1"))
                {
                    throw new Exception("操作失败,出库单已分配完成!");
                }
                var notice = Db.Queryable<BllExportNotice>().First(a => a.IsDel == "0" && a.SONo == detail.SONo);
                if (notice == null)
                {
                    throw new Exception("操作失败,未找到指定出库单!");
                }
                if (notice.Status == "3" && detail.AllotQty >= detail.Qty || notice.Status == "4" || notice.Status == "5")
                if (notice.Type != "1" && notice.Type != "2" && notice.Type !="3")
                {
                    throw new Exception("操作失败,出库单已分配完成!");
                    if (detail.AllotQty >= detail.Qty || (detail.Status != "0" && detail.Status != "1"))
                    {
                        throw new Exception("操作失败,出库单已分配完成!");
                    }
                    if (notice.Status == "3" && detail.AllotQty >= detail.Qty || notice.Status == "4" || notice.Status == "5")
                    {
                        throw new Exception("操作失败,出库单已分配完成!");
                    }
                    //单据明细需要的出库数量
                    var needQty = detail.Qty - detail.AllotQty;
                    //分配的出库数量
                    var outQty = model.StockList.Select(s => s.Qty).ToList().Sum();
                    if (outQty != needQty)
                    {
                        throw new Exception("操作失败,出库数量与计划数量不一致!");
                    }
                }
                #endregion
                //单据明细需要的出库数量
                var needQty = detail.Qty - detail.AllotQty;
                //分配的出库数量
                var outQty = model.StockList.Select(s => s.Qty).ToList().Sum();
                if (outQty != needQty)
                {
                    throw new Exception("操作失败,出库数量与计划数量不一致!");
                }
                var stockIds = model.StockList.Select(a => a.StockId).ToList();
                //库存明细
                var stockList = Db.Queryable<DataStockDetail>().Where(a => stockIds.Contains(a.Id)).ToList();
@@ -3315,7 +3371,7 @@
                var allots = Db.Queryable<BllExportAllot>().Where(m => m.IsDel == "0" && m.SODetailNo == detail.Id && m.Status == "0").ToList();
                //库存总表
                //var stockz = Db.Queryable<DataStock>().First(d => d.IsDel == "0" && d.SkuNo == detail.SkuNo && d.LotNo == detail.LotNo);
                var stockz = Db.Queryable<DataStock>().First(d => d.IsDel == "0" && d.SkuNo == detail.SkuNo && d.LotNo == detail.LotNo);
                var allotList = new List<BllExportAllot>();
                decimal outQtys = 0;
@@ -3352,7 +3408,7 @@
                            IsBelt = stock.IsBelt,
                            Qty = st.Qty,
                            CompleteQty = 0,
                            Status = "0",
                            Status = notice.Status == "4"? "2":"0",
                            LogisticsId = notice.LogisticsId,
                            IsAdvance = "0",
                            OutMode = "",//出库口
@@ -3371,11 +3427,12 @@
                    //库存明细
                    stock.LockQty += st.Qty;
                    stock.Status = stock.LockQty == stock.Qty ? "2" : "1";
                    //库存总表
                    //stockz.LockQty += st.Qty;
                    //Db.Updateable(stockz).ExecuteCommand();
                    if (detail.AllotQty+ st.Qty > detail.Qty)
                    {
                        //库存总表
                        stockz.LockQty += (decimal)detail.AllotQty + st.Qty - detail.Qty;
                        Db.Updateable(stockz).ExecuteCommand();
                    }
                    Db.Updateable(stock).UpdateColumns(it => new { it.LockQty, it.Status }).ExecuteCommand();
                    outQtys += st.Qty;