Administrator
2024-03-06 65ecd34acf0a3d33e6c1e10c93e351716d749e2f
Wms/WMS.BLL/BllAsnServer/ArrivalNoticeServer.cs
@@ -103,7 +103,7 @@
                    rowCount = count;
                }
                sqlString += "SELECT DISTINCT tb1.*,tb2.Status as AsnStatus,tb3.RealName as CreateUserName, ";
                sqlString += "SELECT DISTINCT tb1.*,tb2.Type as AsnType,tb2.Status as AsnStatus,tb3.RealName as CreateUserName, ";
                sqlString += "tb4.RealName as UpdateUserName,isnull(tb6.UnitName,tb5.UnitNo) as UnitName,tb7.PackagName ";
                sqlString += "FROM BllArrivalNoticeDetail AS tb1 ";
                sqlString += "LEFT JOIN BllArrivalNotice AS tb2 ON tb1.ASNNo = tb2.ASNNo ";
@@ -124,34 +124,63 @@
                throw ex;
            }
        }
        //获取入库单明细剩余打印数量
        public string GetAsnDetailQtyList(int id)
        {
            try
            {
                var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == id);
                if (detail == null)
                {
                    throw new Exception("未查询到入库单明细");
                }
                var labelQty = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.ASNDetailNo == id).Sum(m => m.Qty);
                var qty = detail.Qty - labelQty;
                return qty.ToString();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        //获取物料信息(添加入库单明细使用)
        public List<MaterialsDto> GetMaterialsList(GetMaterialsVm model)
        {
            try
            {
                string skuType = string.Empty;
                switch(model.Type)//0:原料 1:包材 2:成品 3:耗材 4:半成品
                switch (model.Type)//0:原料 1:包材 2:成品 3:耗材 4:半成品
                {
                    case "0"://成品入库
                        skuType = "(2)";
                        break;
                    case "3"://退货入库
                        skuType = "(2)";
                        break;
                    case "5"://其它入库
                        skuType = "(0,1,3)";
                        break;
                    case "6"://代储入库
                        skuType = "(2)";
                        break;
                    case "1"://采购入库
                        skuType = "(0,1,3)";
                        break;
                    case "2"://中间品入库
                        skuType = "(4)";
                        break;
                    case "3"://退货入库
                        skuType = "(2)";
                        break;
                    case "4"://车间余料退回入库
                        skuType = "(0,1,3)";
                        break;
                    case "5"://其它入库
                        skuType = "(2)";
                    case "2"://中间品入库
                        skuType = "(4)";
                        break;
                    case "6"://代储入库
                        skuType = "(2)";
                    case "7"://寄存入库
                        skuType = "(3)";
                        break;
                    default: //其它
                        skuType = "(0,1,2,3,4)";
                        break;
                }
@@ -208,6 +237,9 @@
            string strMessage = "";
            string sqlString = string.Empty;
            string sqlDetailStr = string.Empty;
            //0:成品入库 1:采购入库 2:中间品入库 3:退货入库 4:车间余料入库 5:其它入库 6:代储入库 7:寄存入库
            var TypeLot = "1, 2, 5, 6, 7";
            try
            {
                if (model.Origin == "录入")
@@ -223,6 +255,15 @@
                    if (string.IsNullOrEmpty(model.Type))
                    {
                        throw new Exception("单据类型不可为空!");
                    }
                }
                //判断是否为采购入库单据或车间余料退回入库
                // 0:成品入库 1:采购入库 2:中间品入库 3:退货入库 4:车间余料退回入库 5:其它入库 6:代储入库 7:寄存入库
                if (model.Type == "1" || model.Type == "4")
                {
                    if (!string.IsNullOrWhiteSpace(model.LotNo))
                    {
                        throw new Exception("采购入库或余料退回不可输入批次,不可编辑!");
                    }
                }
@@ -251,8 +292,12 @@
                    }
                    if (string.IsNullOrEmpty(detailModel.LotNo))
                    {
                        strMessage = "-1:批次号不可为空;";
                        continue;
                        //判断是否为不限制批次单据
                        if (!TypeLot.Contains(model.Type))
                        {
                            strMessage = "-1:批次号不可为空;";
                            continue;
                        }
                    }
                    // 判断是否已存在当前明细
                    string sqlCount = $"SELECT COUNT(ID) FROM BllArrivalNoticeDetail where ASNNo = '{model.ASNNo}' ";
@@ -314,6 +359,18 @@
            string sqlDetailStr = string.Empty;
            try
            {
                //判断是否为采购入库单据或车间余料退回入库
                // 0:成品入库 1:采购入库 2:中间品入库 3:退货入库 4:车间余料退回入库 5:其它入库 6:代储入库 7:寄存入库
                int isType = 0;
                if (model.Type == "1" || model.Type == "4")
                {
                    isType = 1;
                    if (!string.IsNullOrWhiteSpace(model.LotNo))
                    {
                        strMessage = "-1:采购入库或余料退回不可输入批次,不可编辑;";
                        return strMessage;
                    }
                }
                if (model.Origin != "录入")
                {
                    strMessage = "-1:上游系统下发的单据,不可编辑;";
@@ -330,7 +387,7 @@
                sqlString = "UPDATE BllArrivalNotice SET ";
                sqlString += $"CustomerNo = '{model.CustomerNo}',CustomerName = '{model.CustomerName}',";
                sqlString += $"LotNo = '{model.LotNo}',LotText = '{model.LotText}',";
                sqlString += $"LotNo = '{model.LotNo}',LotText = '{model.LotText}',";
                sqlString += $"UpdateTime = GETDATE(),UpdateUser = '{model.CreateUser}' ";
                sqlString += $"WHERE ASNNo = '{model.ASNNo}'";
@@ -368,7 +425,7 @@
                        strMessage = "-1:数量必须大于0;";
                        continue;
                    }
                    if (string.IsNullOrEmpty(detailModel.LotNo))
                    if (string.IsNullOrEmpty(detailModel.LotNo) && isType != 1)
                    {
                        strMessage = "-1:批次号不可为空;";
                        continue;
@@ -473,6 +530,7 @@
                }
                // 删除总单
                sqlString = $"UPDATE BllArrivalNotice SET IsDel = '1',";
                sqlString += $"UpdateTime = GETDATE(),UpdateUser = '{model.CreateUser}' ";
@@ -482,10 +540,30 @@
                sqlString += $"UPDATE BllArrivalNoticeDetail SET IsDel = '1',";
                sqlString += $"UpdateTime = GETDATE(),UpdateUser = '{model.CreateUser}' ";
                sqlString += $"WHERE ASNNo = '{model.ASNNo}';";
                //判断是否为采购入库单据或车间余料退回入库
                // 0:成品入库 1:采购入库 2:中间品入库 3:退货入库 4:车间余料退回入库 5:其它入库 6:代储入库 7:寄存入库
                int notdel = 0;
                if (model.Type == "1" || model.Type == "4")
                {
                    //获取单据生成对应标签
                    var list = Db.Queryable<BllBoxInfo>().Where(a => a.IsDel == "0" && a.Status == "0" && a.BindNo == null);
                    //验证对应箱支信息是否存在
                    if (list == null)
                    {
                        return "-1:已有箱码已绑定托盘或已入库,不可删除!";
                    }
                    // 删除对应箱支信息
                    sqlString += $"UPDATE BllBoxInfo SET IsDel = '1',";
                    sqlString += $"UpdateTime = GETDATE(),UpdateUser = '{model.CreateUser}' ";
                    sqlString += $"WHERE ASNNo = '{model.ASNNo}';";
                    notdel = 1;
                }
                Db.Ado.BeginTran();
                int rowCount = Db.Ado.ExecuteCommand(sqlString);
                if (rowCount < 2)
                if (rowCount < 2 + notdel)
                {
                    Db.RollbackTran();
                    return "-1:删除失败!";
@@ -496,6 +574,7 @@
            }
            catch (Exception ex)
            {
                Db.RollbackTran();
                throw ex;
            }
        }
@@ -572,6 +651,11 @@
                //{
                //    throw new Exception("参数异常,请检查状态是否为执行完成");
                //}
                var palletBind = Db.Queryable<BllPalletBind>().Where(m => m.IsDel == "0" && m.ASNNo == notice.ASNNo && m.Status != "2").ToList();
                if (palletBind != null && palletBind.Count > 0)
                {
                    throw new Exception("存在未入库完成托盘信息,不允许关单");
                }
                var sqlString = "";
@@ -603,7 +687,7 @@
            }
        }
        //入库单撤销申请
        public void CancelOrder(int id,string reason,int userId)
        public void CancelOrder(int id, string reason, int userId)
        {
            try
            {
@@ -612,29 +696,29 @@
                {
                    throw new Exception("未查询到入库单据信息");
                }
                if (notice.Status!="1" && notice.Status != "2")
                if (notice.Status != "1" && notice.Status != "2")
                {
                    throw new Exception("入库单据状态不是正在执行或执行完成,不能撤销");
                }
                var bind = Db.Queryable<BllPalletBind>().Where(m => m.IsDel == "0" && m.ASNNo == notice.ASNNo).ToList();
                if (bind.Count==0)
                if (bind.Count == 0)
                {
                    throw new Exception("未查询到入库单据的托盘绑定信息");
                }
                if (bind.Count(m=>m.Status== "1")>0)
                if (bind.Count(m => m.Status == "1") > 0)
                {
                    throw new Exception("当前入库单据的托盘绑定信息有正在执行的,请稍后完成后再撤销");
                }
                var auditLog = Db.Queryable<BllAuditLog>().Where(m => m.IsDel == "0" && m.Status == "0");
                var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.ASNNo == notice.ASNNo);
                if (auditLog.Count(m=>m.OrderNo == notice.ASNNo)>0)
                if (auditLog.Count(m => m.OrderNo == notice.ASNNo) > 0)
                {
                    throw new Exception("当前入库单据已有撤销审核,请等待审核完成");
                }
                var startStatusName = "";
                var endStatusName = "";
@@ -649,7 +733,7 @@
                        endStatusName = "正在执行";
                        break;
                    default:
                        throw new Exception("单据状态错误");
                        throw new Exception("单据状态错误");
                }
                var palletStr = "";
@@ -657,27 +741,46 @@
                var msgL = "";
                foreach (var item in bind)
                {
                    if (auditLog.Count(m=>m.OrderNo ==item.ASNNo && m.PalletNo.Contains(item.PalletNo)) >0)
                    if (auditLog.Count(m => m.OrderNo == item.ASNNo && m.PalletNo.Contains(item.PalletNo)) > 0)
                    {
                        continue;
                    }
                    if (!palletStr.Contains(item.PalletNo))
                    {
                        palletStr += item.PalletNo+";";
                        palletStr += item.PalletNo + ";";
                    }
                    var info = boxInfo.First(m => m.BindNo == item.Id);
                    //获取托盘绑定对应单据
                    var noticeDetail = Db.Queryable<BllArrivalNoticeDetail>().First(a => a.IsDel == "0" && a.Id == item.ASNDetailNo);
                    if (info != null)
                    {
                        if (!msgS.Contains(info.SkuNo))
                        {
                            msgS += info.SkuNo + ";";
                        }
                        if (!msgL.Contains(info.LotNo))
                        {
                            msgL += info.LotNo + ";";
                        }
                    }
                    else
                    {
                        if (!msgS.Contains(noticeDetail.SkuNo))
                        {
                            msgS += noticeDetail.SkuNo + ";";
                        }
                        if (!msgL.Contains(noticeDetail.LotNo))
                        {
                            msgL += noticeDetail.LotNo + ";";
                        }
                    }
                    
                    var info = boxInfo.First(m => m.BindNo == item.Id);
                    if (!msgS.Contains(info.SkuNo))
                    {
                        msgS += info.SkuNo + ";";
                    }
                    if (!msgL.Contains(info.LotNo))
                    {
                        msgL += info.LotNo + ";";
                    }
                }
                var time = DateTime.Now;
                var log = new BllAuditLog()
@@ -695,7 +798,7 @@
                    IsDel = "0",
                    CreateUser = userId,
                    CreateTime = time
                };
                };
                Db.Insertable(log).ExecuteCommand();
                new OperationASNServer().AddLogOperationAsn("入库作业", "入库单据", notice.ASNNo, "添加", $"添加了单据号为{notice.ASNNo}的单据撤销申请", userId);
            }
@@ -729,7 +832,7 @@
                {
                    //添加操作日志
                    new OperationASNServer().AddLogOperationAsn("入库作业", "入库单据", notice.ASNNo, "编辑", $"编辑了单据号为{notice.ASNNo}的备注信息", userId);
                }
                }
            }
            catch (Exception ex)
            {
@@ -869,6 +972,10 @@
                {
                    throw new Exception("未查询到单据信息");
                }
                if (notice.Status != "3")
                {
                    throw new Exception("复核失败,单据非关闭状态");
                }
                var detail = Db.Queryable<BllArrivalNoticeDetail>().Where(m => m.ASNNo == notice.ASNNo && m.IsDel == "0").ToList();
                if (detail.Count == 0)
                {
@@ -926,5 +1033,5 @@
        #endregion
    }
}