| | |
| | | { |
| | | throw new Exception("请扫描外箱条码!"); |
| | | } |
| | | string sqlString = string.Empty; |
| | | sqlString = "select ASNNo,BoxNo, SkuNo,SkuName, LotNo, Qty from BLLLabelBoxNo where IsDel = '0' "; |
| | | sqlString += $"and BoxNo = '{model.BoxNo}' "; |
| | | string sqlString = $@"SELECT |
| | | ASNNo, |
| | | BoxNo, |
| | | SkuNo, |
| | | SkuName, |
| | | LotNo, |
| | | SUM(Qty) as Qty |
| | | FROM BllBoxInfo |
| | | WHERE IsDel = '0' |
| | | AND Status='0' |
| | | AND BoxNo = '{model.BoxNo}' |
| | | GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo; "; |
| | | var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString); |
| | | if (models == null || models.Count <= 0) |
| | | { |
| | | sqlString = "select BoxNo, SkuNo,SkuName, LotNo, SUM(Qty) as Qty from BllBoxInfo where IsDel = '0' "; |
| | | sqlString += $"and BoxNo = '{model.BoxNo}' and Status='0' "; |
| | | sqlString += $"group by BoxNo,SkuNo,SkuName,LotNo; "; |
| | | |
| | | models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString); |
| | | } |
| | | if (models == null) |
| | | { |
| | | throw new Exception("箱码信息不存在!"); |
| | |
| | | |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | // 验证入库单总表 |
| | | var notice = Db.Queryable<BllArrivalNotice>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo); |
| | | if (notice == null) |
| | | { |
| | | throw new Exception("-1:当前物料及批次与单据无关联,请核实!"); |
| | | } |
| | | //入库单类型,0:成品入库 1:采购入库 2:中间品入库 3:退货入库 4:车间余料退回入库 5:其它入库 6:代储入库 |
| | | if (notice.Type == "0" || notice.Type == "3" || notice.Type == "5" || notice.Type == "6") |
| | | { |
| | | BindPalletForBox(model, userId, origin); |
| | | } |
| | | else |
| | | { |
| | | BindPalletForLabelBox(model, userId); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw ex; |
| | | } |
| | | } |
| | | // 绑定物料托盘 |
| | | private void BindPalletForBox(PdaPalletBindVm model, int userId, string origin) |
| | | { |
| | | try |
| | | { |
| | | |
| | | Db.BeginTran(); |
| | | |
| | | //托盘是否存在 |
| | |
| | | } |
| | | |
| | | #region 箱码信息 |
| | | |
| | | var msgStr = $"箱号为{model.BoxNo}"; |
| | | var boxInfoList = new List<BllBoxInfo>(); |
| | | //首箱 |
| | |
| | | #endregion |
| | | |
| | | // 更改箱支关系表 |
| | | var factQty = 0;//托盘总数量 |
| | | decimal factQty = 0.00m;//托盘总数量 |
| | | var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList(); |
| | | foreach (var g in boxGroup) |
| | | { |
| | |
| | | |
| | | // 更改入库单明细已组数量 |
| | | var sqlString = string.Empty; |
| | | sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{bind.Qty}' where id = '{model.AsnDetailId}';"; |
| | | sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{factQty}' where id = '{model.AsnDetailId}';"; |
| | | Db.Ado.ExecuteCommand(sqlString); |
| | | |
| | | // 更改入库单及入库明细状态 |
| | |
| | | new OperationASNServer().AddLogOperationAsn("PDA模块", "产品组托", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId); |
| | | |
| | | Db.CommitTran(); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | throw ex; |
| | | } |
| | | } |
| | | // 绑定物料托盘 |
| | | public void BindPalletForLabelBox(PdaPalletBindVm model, int userId) |
| | | { |
| | | try |
| | | { |
| | | Db.BeginTran(); |
| | | |
| | | //托盘是否存在 |
| | | var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo); |
| | | if (pallet == null) |
| | | { |
| | | throw new Exception("未查询到托盘信息,请核实!"); |
| | | } |
| | | // 验证入库单明细是否存在 |
| | | var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo); |
| | | if (detail == null) |
| | | { |
| | | throw new Exception("-1:当前物料及批次与单据无关联,请核实!"); |
| | | } |
| | | #region 包装 |
| | | var package = Db.Queryable<SysPackag>().Where(m => m.IsDel == "0"); |
| | | var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo); |
| | | var pack = package.First(m => m.IsDel == "0" && m.PackagNo == sku.PackagNo); |
| | | if (pack == null) |
| | | { |
| | | throw new Exception("-1:获取物料包装失败,请核实!"); |
| | | } |
| | | var pNum = 0;//托盘物品数量 |
| | | var bNum = 0;//箱码物品数量 |
| | | if (pack.L5Num.HasValue) |
| | | { |
| | | pNum = (int)pack.L5Num; |
| | | bNum = (int)pack.L4Num; |
| | | } |
| | | else if (pack.L4Num.HasValue) |
| | | { |
| | | pNum = (int)pack.L4Num; |
| | | bNum = (int)pack.L3Num; |
| | | } |
| | | else if (pack.L3Num.HasValue) |
| | | { |
| | | pNum = (int)pack.L3Num; |
| | | bNum = (int)pack.L2Num; |
| | | } |
| | | else if (pack.L2Num.HasValue) |
| | | { |
| | | pNum = (int)pack.L2Num; |
| | | bNum = (int)pack.L1Num; |
| | | } |
| | | else if (pack.L1Num.HasValue) |
| | | { |
| | | pNum = (int)pack.L1Num; |
| | | bNum = (int)pack.L1Num; |
| | | } |
| | | if (pNum == 0 || bNum == 0) |
| | | { |
| | | throw new Exception($"绑定失败,{detail.SkuNo}物品包装未找到!"); |
| | | } |
| | | #region 验证是否允许立库同托盘不同物料入库或同托盘同物料不同批次入库 |
| | | var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId); |
| | | if (palletBind != null) |
| | | { |
| | | var box = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BindNo == palletBind.Id && m.BitBoxMark == "0"); |
| | | if (box != null && (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo)) |
| | | { |
| | | var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045"); |
| | | if (funSetting == null || funSetting.IsEnable == "OFF") |
| | | { |
| | | throw new Exception($"不允许立库同托盘不同物料入库或同托盘不同批次入库!"); |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo); |
| | | var bindId = 0; |
| | | if (bind == null) |
| | | { |
| | | bind = new BllPalletBind |
| | | { |
| | | ASNNo = model.AsnNo, |
| | | ASNDetailNo = (int)model.AsnDetailId, |
| | | PalletNo = model.PalletNo, |
| | | PalletNo2 = "", |
| | | PalletNo3 = "", |
| | | Qty = model.SkuQty, |
| | | FullQty = pNum, |
| | | Status = "0", |
| | | Type = "0", |
| | | LotNo = detail.LotNo, |
| | | LotText = detail.LotText, |
| | | SupplierLot = "", |
| | | InspectMark = "0", |
| | | BitPalletMark = "1", |
| | | IsBale = "0", |
| | | IsBelt = "0", |
| | | CreateUser = userId |
| | | }; |
| | | // 插入托盘绑定表 |
| | | bindId = Db.Insertable(bind).ExecuteReturnIdentity(); |
| | | } |
| | | else |
| | | { |
| | | if (bind.Status != "0") |
| | | { |
| | | throw new Exception("-1:当前托盘正在执行中,绑定失败,请核实!"); |
| | | } |
| | | bindId = bind.Id; |
| | | } |
| | | |
| | | #region 箱码信息 |
| | | var boxInfoList = new List<BllLabelBoxNo>(); |
| | | var msgStr = $"箱号为{model.BoxNo}"; |
| | | //首箱 |
| | | var boxInfo = Db.Queryable<BllLabelBoxNo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo && m.Level == "1").ToList(); |
| | | if (boxInfo.Count == 0) |
| | | { |
| | | throw new Exception("-1:箱码信息不存在!"); |
| | | } |
| | | //是否连续组托 |
| | | if (model.IsContinue == "1") |
| | | { |
| | | boxInfoList.AddRange(boxInfo); |
| | | //尾箱 |
| | | var boxInfo2 = Db.Queryable<BllLabelBoxNo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo && m.Level == "1").ToList(); |
| | | if (boxInfo2.Count == 0) |
| | | { |
| | | throw new Exception("-1:尾箱码信息不存在!"); |
| | | } |
| | | boxInfoList.AddRange(boxInfo2); |
| | | var sql = $"select * from BllLabelBoxNo where IsDel = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}' and Level='1'; "; |
| | | var list = Db.Ado.SqlQuery<BllLabelBoxNo>(sql); |
| | | boxInfoList.AddRange(list); |
| | | |
| | | //找到相关的二级码 |
| | | foreach (var item in boxInfoList) |
| | | { |
| | | sql = $"select * from BllLabelBoxNo where IsDel = '0' and IsUse = '0' and ParentBoxNo='{item.BoxNo}' and Level = '2' "; |
| | | list = Db.Ado.SqlQuery<BllLabelBoxNo>(sql); |
| | | boxInfoList.AddRange(list); |
| | | } |
| | | msgStr += $"尾箱号为{model.TailBoxNo}"; |
| | | } |
| | | else |
| | | { |
| | | var boxInfoList2 = new List<BllLabelBoxNo>();//所有二级码 |
| | | decimal boxQty = 0.00m;//箱内二级码数量 |
| | | if (!string.IsNullOrEmpty(model.BoxNo01)) |
| | | { |
| | | //二级码首码 |
| | | var box01Info = Db.Queryable<BllLabelBoxNo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo01 && m.IsUse == "0" && m.Level == "2" && (string.IsNullOrEmpty(m.ParentBoxNo) || m.ParentBoxNo == model.BoxNo)).ToList(); |
| | | if (box01Info.Count == 0) |
| | | { |
| | | throw new Exception("-1:二级码首码信息不存在!"); |
| | | } |
| | | boxInfoList2.AddRange(box01Info); |
| | | if (model.IsContinue2 == "1") |
| | | { |
| | | //二级码尾码 |
| | | var box01Info2 = Db.Queryable<BllLabelBoxNo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo01 && m.IsUse == "0" && m.Level == "2" && (string.IsNullOrEmpty(m.ParentBoxNo) || m.ParentBoxNo == model.BoxNo)).ToList(); |
| | | if (box01Info2.Count == 0) |
| | | { |
| | | throw new Exception("-1:二级码尾码信息不存在!"); |
| | | } |
| | | boxInfoList2.AddRange(box01Info2); |
| | | //中间码 |
| | | var sql = $"select * from BllLabelBoxNo where IsDel = '0' and IsUse = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}' and Level='2' and (ParentBoxNo='' || ParentBoxNo='{model.BoxNo}'); "; |
| | | var list = Db.Ado.SqlQuery<BllLabelBoxNo>(sql); |
| | | boxInfoList2.AddRange(list); |
| | | } |
| | | foreach (var item in boxInfoList2) |
| | | { |
| | | item.ParentBoxNo = model.BoxNo; |
| | | boxQty += item.Qty; |
| | | } |
| | | boxInfoList.AddRange(boxInfoList2); |
| | | foreach (var item in boxInfo) |
| | | { |
| | | item.Qty += boxQty; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //找到相关的二级码 |
| | | foreach (var item in boxInfo) |
| | | { |
| | | string sql = $"select * from BllLabelBoxNo where IsDel = '0' and IsUse = '0' and ParentBoxNo='{item.BoxNo}' and Level = '2' "; |
| | | var list = Db.Ado.SqlQuery<BllLabelBoxNo>(sql); |
| | | boxInfoList.AddRange(list); |
| | | } |
| | | } |
| | | boxInfoList.AddRange(boxInfo); |
| | | } |
| | | #endregion |
| | | |
| | | #endregion |
| | | // 更改箱支关系表 |
| | | decimal factQty = 0.00m;//托盘总数量 |
| | | foreach (var box in boxInfoList) |
| | | { |
| | | //箱内物料批次与单据明细不符合 |
| | | if (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo) |
| | | { |
| | | throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!"); |
| | | } |
| | | if (box.IsUse != "0") |
| | | { |
| | | continue; |
| | | } |
| | | if (box.Level == "1") |
| | | { |
| | | if (box.Qty > bNum) |
| | | { |
| | | throw new Exception($"绑定失败,{box.BoxNo}箱码绑定数量大于该物品包装数量!"); |
| | | } |
| | | factQty += box.Qty; |
| | | } |
| | | //box.ASNNo = model.AsnNo; |
| | | //box.ASNDetailNo = model.AsnDetailId; |
| | | box.IsUse = "1"; |
| | | box.CompleteTime = DateTime.Now; |
| | | box.UpdateTime = DateTime.Now; |
| | | box.UpdateUser = userId; |
| | | } |
| | | Db.Updateable(boxInfoList).ExecuteCommand(); |
| | | |
| | | // 更新托盘绑定表 |
| | | bind.Qty += factQty; |
| | | if (bind.FullQty < bind.Qty) |
| | | { |
| | | throw new Exception("托盘绑定数量已超出该物料包装数量"); |
| | | } |
| | | |
| | | if (bind.FullQty == bind.Qty) |
| | | { |
| | | bind.BitPalletMark = "0"; |
| | | } |
| | | Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand(); |
| | | |
| | | // 更改入库单明细已组数量 |
| | | var sqlString = string.Empty; |
| | | sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{bind.Qty}' where id = '{model.AsnDetailId}';"; |
| | | Db.Ado.ExecuteCommand(sqlString); |
| | | |
| | | // 更改入库单及入库明细状态 |
| | | if (detail.Status == "0") |
| | | { |
| | | var sqlString2 = string.Empty; |
| | | sqlString2 += $"update BllArrivalNotice set Status = '1',CompleteTime= getDate() where ASNNo = '{model.AsnNo}' and Status ='0';"; |
| | | sqlString2 += $"update BllArrivalNoticeDetail set Status = '1',CompleteTime= getDate() where id = '{model.AsnDetailId}' and Status ='0';"; |
| | | Db.Ado.ExecuteCommand(sqlString2); |
| | | } |
| | | |
| | | // 更改托盘使用状态 |
| | | var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';"; |
| | | //添加托盘记录表数据 |
| | | sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','组盘','0',getDate(),{userId},NULL,NULL);"; |
| | | Db.Ado.ExecuteCommand(sqlStr); |
| | | new OperationASNServer().AddLogOperationAsn("PDA模块", "产品组托", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId); |
| | | |
| | | Db.CommitTran(); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | throw ex; |
| | | } |
| | | } |