| | |
| | | using WMS.Entity.BllSoEntity; |
| | | using Model.ModelVm.PdaVm; |
| | | using Model.ModelDto.PdaDto; |
| | | using Dm; |
| | | using Model.InterFaceModel; |
| | | |
| | | namespace WMS.BLL.BllPdaServer |
| | | { |
| | |
| | | public List<BoxInfoDto> GetBoxInfos(BoxInfoVm model) |
| | | { |
| | | try |
| | | { |
| | | { |
| | | string sqlString = string.Empty; |
| | | if (model.IsHuiKu == 0) |
| | | { |
| | |
| | | sqlString += $"group by BoxNo,SkuNo,SkuName,LotNo; "; |
| | | } |
| | | var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString); |
| | | |
| | | return models; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw ex; |
| | | } |
| | | } |
| | | |
| | | // 根据托盘号或箱码获取托盘信息 liudl |
| | | public List<PalletBindDto> GetPalletBindInfo(BllPalletBind model) |
| | | { |
| | | try |
| | | { |
| | | string sqlString = string.Empty; |
| | | sqlString = "select b.SkuNo,b.SkuName,a.LotNo,a.Qty,a.PalletNo,a.Id from BllPalletBind a left join BllArrivalNoticeDetail b on a.ASNDetailNo = b.Id where a.IsDel = '0' and b.IsDel = '0' "; |
| | | if (!string.IsNullOrEmpty(model.PalletNo)) |
| | | { |
| | | sqlString += $"and PalletNo = '{model.PalletNo}' and a.Status = '0' "; |
| | | } |
| | | else |
| | | { |
| | | throw new Exception("托盘号异常!"); |
| | | } |
| | | var models = Db.Ado.SqlQuery<PalletBindDto>(sqlString); |
| | | |
| | | return models; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // 删除已组信息 |
| | | public string DelPalletBind(BllPalletBind model) |
| | | { |
| | | string strMsg = ""; |
| | | string sqlString = string.Empty; |
| | | try |
| | | { |
| | | if (model.Id == 0) |
| | | { |
| | | throw new Exception("-1:托盘ID不可为0!"); |
| | | } |
| | | |
| | | //获取托盘绑定信息 |
| | | var bind = Db.Queryable<BllPalletBind>().First(a => a.IsDel == "0" && a.Status == "0" && a.Id == model.Id); |
| | | //验证托盘绑定信息是否为空 |
| | | if (bind == null) |
| | | { |
| | | throw new Exception("-1:未获取到对应托盘信息,请核实!"); |
| | | } |
| | | //判断托盘绑定信息是否不是等待执行 |
| | | if (bind.Status != "0") |
| | | { |
| | | throw new Exception("-1:该托盘已正在入库,请核实!"); |
| | | } |
| | | //获取是否有指定库位 |
| | | SysStorageLocat locat = new SysStorageLocat(); |
| | | int isNullLocat = 0; |
| | | //判断储位是否为空 |
| | | if (!string.IsNullOrWhiteSpace(bind.LocatNo)) |
| | | { |
| | | isNullLocat = 1; |
| | | locat = Db.Queryable<SysStorageLocat>().First(a=>a.IsDel == "0" && a.WareHouseNo == bind.WareHouseNo && a.RoadwayNo == bind.RoadwayNo && a.LocatNo == bind.LocatNo); |
| | | //判断储位地址是否为正在入库 |
| | | if (locat.Status != "2") |
| | | { |
| | | throw new Exception("-1:当前托盘绑定的储位地址不是正在入库,请核实!"); |
| | | } |
| | | } |
| | | //获取托盘信息 |
| | | var pallet = Db.Queryable<SysPallets>().First(a => a.IsDel == "0" && a.PalletNo == model.PalletNo); |
| | | //判断托盘信息是否为空 |
| | | if (pallet == null) |
| | | { |
| | | throw new Exception("-1:未获取到对应托盘信息,请核实!"); |
| | | } |
| | | //获取对应入库单据总单 |
| | | var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == bind.ASNNo); |
| | | //验证入库单总单信息 |
| | | if (notice == null) |
| | | { |
| | | throw new Exception("-1:未获取到对应入库单总单信息,请核实!"); |
| | | } |
| | | //获取对应入库单据明细 |
| | | var noticeDetail = Db.Queryable<BllArrivalNoticeDetail>().First(a => a.IsDel == "0" && a.Id == bind.ASNDetailNo); |
| | | //验证入库单单据明细 |
| | | if (noticeDetail == null) |
| | | { |
| | | throw new Exception("-1:未获取到对应入库单单据明细信息,请核实!"); |
| | | } |
| | | |
| | | |
| | | Db.BeginTran(); |
| | | //减少入库单明细数量 判断已组数量是否为0 再判断完成数量是否为0 |
| | | noticeDetail.FactQty -= bind.Qty; |
| | | //判断已组数量是否为0 |
| | | if (noticeDetail.FactQty == 0) |
| | | { |
| | | //判断是否有完成数量 |
| | | if (noticeDetail.CompleteQty == 0) |
| | | { |
| | | noticeDetail.Status = "0"; //入库单明细状态 |
| | | notice.Status = "0"; //入库单总单状态 |
| | | } |
| | | } |
| | | Db.Updateable(noticeDetail).ExecuteCommand(); |
| | | Db.Updateable(notice).ExecuteCommand(); |
| | | |
| | | |
| | | // 清除托盘绑定上信息 |
| | | //ASNNo,ASNDetailNo,Qty,FullQty,LotNo,LotText,SupplierLot,IsDel,UpdateTime,UpdateUser |
| | | bind.ASNNo = ""; //入库单号 |
| | | bind.ASNDetailNo = 0; //入库单明细id |
| | | bind.Qty = 0; //数量 |
| | | bind.FullQty = 0; //整托数量 |
| | | bind.LotNo = ""; //批次 |
| | | bind.LotText = ""; //批次描述 |
| | | bind.SupplierLot = ""; //供货批次 |
| | | bind.IsDel = "1"; //是否删除 |
| | | bind.UpdateTime = Db.GetDate(); //修改时间 |
| | | bind.UpdateUser = model.CreateUser; //修改人 |
| | | if (isNullLocat == 1) |
| | | { |
| | | bind.LocatNo = ""; //储位地址 |
| | | bind.RoadwayNo = ""; //所属巷道 |
| | | bind.WareHouseNo = ""; //所属仓库 |
| | | //修改储位信息状态 |
| | | locat.Status = "0"; //储位状态 0:空储位 |
| | | Db.Updateable(locat).ExecuteCommand(); |
| | | } |
| | | Db.Updateable(bind).ExecuteCommand(); |
| | | |
| | | //修改托盘信息状态 |
| | | pallet.Status = "0"; //0:未使用 |
| | | Db.Updateable(pallet).ExecuteCommand(); |
| | | |
| | | Db.CommitTran(); |
| | | return strMsg; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.RollbackTran(); |
| | | throw ex; |
| | | } |
| | | } |
| | | |
| | | // 平库完成入库操作 |
| | | public string CompleteInStock(PalletBindVm model) |
| | | { |
| | |
| | | #region 是否回流入库 |
| | | int iscount = 0; |
| | | //库存明细信息 |
| | | var stockDetail = Db.Queryable<DataStockDetail>().Where(a => a.IsDel == "0" && a.PalletNo == model.PalletNo).ToList(); |
| | | var stockDetail = Db.Queryable<DataStockDetail>().Where(a => a.IsDel == "0" && a.PalletNo == model.PalletNo).ToList(); |
| | | //验证库存是否拥有该托信息 |
| | | if (stockDetail != null && stockDetail.Count > 0) |
| | | { |
| | |
| | | #endregion |
| | | |
| | | #region 地码信息(储位信息) |
| | | var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LocatNo && w.Status == "0"); |
| | | var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LocatNo && w.Status == "0" && w.WareHouseNo == "W02"); |
| | | if (storageLocat == null) |
| | | { |
| | | strMsg = "-1:储位信息不存在或非空闲状态,请核查!"; |
| | |
| | | strMsg = "-1:箱码信息不存在,请核查!"; |
| | | return strMsg; |
| | | } |
| | | else |
| | | else |
| | | { |
| | | // 改变箱支关系表状态:已入库 |
| | | sqlString = $"Update BllBoxInfo set Status = '2' where PalletNo = '{model.PalletNo}' and ASNNo = '{model.ASNNo}' and Status = '1'"; |
| | |
| | | pallQty = boxinfo2.Sum(w => w.Qty); |
| | | //入库单明细完成数量增加 |
| | | noticeItem.CompleteQty += pallQty; |
| | | } |
| | | } |
| | | //判断入库数量增加后是否大于等于单据数量 |
| | | if (noticeItem.CompleteQty >= noticeItem.Qty) |
| | | { |
| | |
| | | sqlString = "select sum(qty) from BllBoxInfo where isdel = 0 and "; |
| | | sqlString += $"BindNo = '{palletbindInfo.Id}'"; |
| | | int inspectQty = Db.Ado.GetInt(sqlString); |
| | | |
| | | |
| | | // 添加库存明细表 |
| | | detailModel = new DataStockDetail() |
| | | { |
| | |
| | | |
| | | //修改组托状态 |
| | | palletbindInfo.Status = "2"; //2 入库完成 |
| | | palletbindInfo.WareHouseNo = "W02";//所属仓库 |
| | | palletbindInfo.LocatNo = model.LocatNo;//储位地址 |
| | | palletbindInfo.UpdateTime = serverTime; |
| | | palletbindInfo.UpdateUser = model.CreateUser; |
| | | palletbindInfo.CompleteTime = serverTime; //完成时间 |
| | |
| | | #endregion |
| | | |
| | | #endregion |
| | | } |
| | | } |
| | | storageLocat.Status = "1"; |
| | | storageLocat.UpdateTime= serverTime; //修改时间 |
| | | storageLocat.UpdateUser = model.CreateUser; //修改人 |
| | | //修改储位状态 |
| | | Db.Updateable(storageLocat).ExecuteCommand(); |
| | | |
| | | new OperationASNServer().AddLogOperationAsn("PDA模块", "平库入库", model.PalletNo, "完成", $"在PDA上完成单据号为:{model.ASNNo}的托盘码为:{model.PalletNo}的平库入库操作", (int)model.CreateUser); |
| | | |
| | |
| | | try |
| | | { |
| | | //入库中 |
| | | var aSNNoList= Db.Ado.SqlQuery<string>($"SELECT DISTINCT ASNNo from BllPalletBind where IsDel=0 and Status=0 and PalletNo='{palletNo}' ").ToList(); |
| | | var aSNNoList = Db.Ado.SqlQuery<string>($"SELECT DISTINCT ASNNo from BllPalletBind where IsDel=0 and Status=0 and PalletNo='{palletNo}' ").ToList(); |
| | | if (aSNNoList.Count <= 0) |
| | | { |
| | | //库外托盘或平库托盘 |
| | |
| | | //拼托入库 |
| | | public void CompleteInStockLing(PdaLingAsnVm model, int userId) |
| | | { |
| | | try |
| | | try |
| | | { |
| | | if (string.IsNullOrWhiteSpace(model.AsnNo)) |
| | | { |
| | |
| | | foreach (var item in boxinfo) |
| | | { |
| | | if (!string.IsNullOrEmpty(item.PalletNo)) |
| | | { |
| | | { |
| | | throw new Exception("-1:该箱码已绑定其他托盘,请先解绑托盘!"); |
| | | } |
| | | bNum += item.Qty; |
| | | bNum += item.Qty; |
| | | } |
| | | if (bNum == boxinfo[0].FullQty) |
| | | { |
| | |
| | | //修改入库单总单信息 |
| | | arrival.Status = "2"; |
| | | arrival.CompleteTime = serverTime; |
| | | arrival.UpdateUser =userId; |
| | | arrival.UpdateUser = userId; |
| | | arrival.UpdateTime = serverTime; |
| | | Db.Updateable(arrival).ExecuteCommand(); |
| | | } |
| | |
| | | |
| | | #region 库存明细表 |
| | | var boxinfoItem = boxinfo.First(); |
| | | var detailModel = Db.Queryable<DataStockDetail>() .First(it => it.PalletNo == model.PalletNo && it.LotNo == arrivalnotice.LotNo |
| | | var detailModel = Db.Queryable<DataStockDetail>().First(it => it.PalletNo == model.PalletNo && it.LotNo == arrivalnotice.LotNo |
| | | && it.SkuNo == arrivalnotice.SkuNo && it.Standard == arrivalnotice.Standard && it.IsDel == "0"); |
| | | var stId = 0; |
| | | if (detailModel == null || detailModel.Id == 0) |
| | |
| | | { |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(model.ASNNo)) |
| | | { |
| | | throw new Exception("请选择入库单据!"); |
| | | } |
| | | if (string.IsNullOrEmpty(model.BoxNo)) |
| | | { |
| | | throw new Exception("箱码不能为空!"); |
| | | throw new Exception("请扫描外箱条码!"); |
| | | } |
| | | var order = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.ASNNo); |
| | | if (order == null) |
| | | { |
| | | throw new Exception("入库单据不存在!"); |
| | | } |
| | | string sqlString = string.Empty; |
| | | //入库单类型,0:成品入库 1:采购入库 2:中间品入库 3:退货入库 4:车间余料退回入库 5:其它入库 6:代储入库 |
| | | if (order.Type == "0" || order.Type == "3" || order.Type == "5" || order.Type == "6") |
| | | { |
| | | 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; "; |
| | | } |
| | | else |
| | | { |
| | | sqlString = "select BoxNo, SkuNo,SkuName, LotNo, SUM(Qty) as Qty from BLLLabelBoxNo where IsDel = '0' "; |
| | | sqlString += $"and BoxNo = '{model.BoxNo}' and IsUse='0' "; |
| | | sqlString += $"group by BoxNo,SkuNo,SkuName,LotNo; "; |
| | | } |
| | | 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) |
| | | { |
| | |
| | | throw ex; |
| | | } |
| | | } |
| | | |
| | | |
| | | public void BindPallet(PdaPalletBindVm model, int userId, string origin) |
| | | { |
| | |
| | | { |
| | | throw new Exception("-1:托盘号不可为空!"); |
| | | } |
| | | if (string.IsNullOrEmpty(model.BoxNo)) |
| | | //判断物料数量是否为0 为0判断箱码信息 不为0继续 |
| | | if (model.SkuQty == 0) |
| | | { |
| | | throw new Exception("-1:箱码信息不可为空!"); |
| | | } |
| | | |
| | | if (model.IsContinue == "1") |
| | | { |
| | | if (string.IsNullOrWhiteSpace(model.TailBoxNo)) |
| | | if (string.IsNullOrEmpty(model.BoxNo)) |
| | | { |
| | | throw new Exception("-1:开启连续组托时,尾箱码信息不可为空!"); |
| | | throw new Exception("-1:箱码信息不可为空!"); |
| | | } |
| | | |
| | | if (model.IsContinue == "1") |
| | | { |
| | | if (string.IsNullOrWhiteSpace(model.TailBoxNo)) |
| | | { |
| | | throw new Exception("-1:开启连续组托时,尾箱码信息不可为空!"); |
| | | } |
| | | |
| | | } |
| | | } |
| | | #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(); |
| | | |
| | | //托盘是否存在 |
| | |
| | | PalletNo = model.PalletNo, |
| | | PalletNo2 = "", |
| | | PalletNo3 = "", |
| | | Qty = 0, |
| | | Qty = model.SkuQty, |
| | | FullQty = pNum, |
| | | Status = "0", |
| | | Type = "0", |
| | |
| | | IsBelt = "0", |
| | | CreateUser = userId |
| | | }; |
| | | if (model.SkuQty > pNum) |
| | | { |
| | | throw new Exception($"绑定失败,{model.PalletNo}托盘绑定数量大于该物品托盘包装数量!"); |
| | | } |
| | | // 插入托盘绑定表 |
| | | bindId = Db.Insertable(bind).ExecuteReturnIdentity(); |
| | | } |
| | |
| | | } |
| | | |
| | | #region 箱码信息 |
| | | |
| | | var msgStr = $"箱号为{model.BoxNo}"; |
| | | var boxInfoList = new List<BllBoxInfo>(); |
| | | //首箱 |
| | | var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo && m.Status == "0").ToList(); |
| | | if (boxInfo.Count == 0) |
| | | if (model.SkuQty == 0) |
| | | { |
| | | throw new Exception("-1:箱码信息不存在!"); |
| | | } |
| | | boxInfoList.AddRange(boxInfo); |
| | | //是否连续组托 |
| | | if (model.IsContinue == "1") |
| | | { |
| | | //尾箱 |
| | | var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo && m.Status == "0").ToList(); |
| | | if (boxInfo2.Count == 0) |
| | | //首箱 |
| | | var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo && m.Status == "0").ToList(); |
| | | if (boxInfo.Count == 0) |
| | | { |
| | | throw new Exception("-1:尾箱码信息不存在!"); |
| | | throw new Exception("-1:箱码信息不存在!"); |
| | | } |
| | | boxInfoList.AddRange(boxInfo2); |
| | | var sql = $"select * from BllBoxInfo where IsDel = '0' and Status = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; "; |
| | | var list = Db.Ado.SqlQuery<BllBoxInfo>(sql); |
| | | boxInfoList.AddRange(list); |
| | | msgStr += $"尾箱号为{model.TailBoxNo}"; |
| | | } |
| | | #endregion |
| | | |
| | | // 更改箱支关系表 |
| | | var factQty = 0;//托盘总数量 |
| | | var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList(); |
| | | foreach (var g in boxGroup) |
| | | { |
| | | var boxFullQty = 0;//箱内总数量 |
| | | foreach (var box in g) |
| | | { |
| | | if (box.BindNo != null && box.BindNo != 0) |
| | | { |
| | | continue; |
| | | } |
| | | //箱内物料批次与单据明细不符合 |
| | | if (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo) |
| | | { |
| | | throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!"); |
| | | } |
| | | |
| | | box.ASNNo = model.AsnNo; |
| | | box.ASNDetailNo = model.AsnDetailId; |
| | | box.BindNo = bindId; |
| | | box.PalletNo = model.PalletNo; |
| | | box.Status = "1"; |
| | | box.CompleteTime = DateTime.Now; |
| | | box.UpdateTime = DateTime.Now; |
| | | box.UpdateUser = userId; |
| | | |
| | | factQty += box.Qty; |
| | | boxFullQty += box.Qty; |
| | | } |
| | | if (boxFullQty > bNum) |
| | | { |
| | | throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!"); |
| | | } |
| | | } |
| | | 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 + '{factQty}' 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; |
| | | } |
| | | } |
| | | // 绑定物料托盘 |
| | | public void BindPalletForLabelBox(PdaPalletBindVm model, int userId) |
| | | { |
| | | try |
| | | { |
| | | #region 判断 |
| | | |
| | | if (string.IsNullOrEmpty(model.AsnNo)) |
| | | { |
| | | throw new Exception("-1:单据号不可为空!"); |
| | | } |
| | | if (model.AsnDetailId == null || model.AsnDetailId == 0) |
| | | { |
| | | throw new Exception("-1:物料不可为空!"); |
| | | } |
| | | if (string.IsNullOrEmpty(model.PalletNo)) |
| | | { |
| | | throw new Exception("-1:托盘号不可为空!"); |
| | | } |
| | | if (string.IsNullOrEmpty(model.BoxNo)) |
| | | { |
| | | throw new Exception("-1:箱码信息不可为空!"); |
| | | } |
| | | |
| | | if (model.IsContinue == "1") |
| | | { |
| | | if (string.IsNullOrWhiteSpace(model.TailBoxNo)) |
| | | { |
| | | throw new Exception("-1:开启连续组托时,尾箱码信息不可为空!"); |
| | | } |
| | | |
| | | } |
| | | if (model.IsContinue == "0" && model.IsContinue2 == "1") |
| | | { |
| | | if (string.IsNullOrWhiteSpace(model.TailBoxNo01)) |
| | | { |
| | | throw new Exception("-1:开启连续组托时,二级码尾码信息不可为空!"); |
| | | } |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | 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 = 0, |
| | | 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 msgStr = $"箱号为{model.BoxNo}"; |
| | | var boxInfoList = new List<BllLabelBoxNo>(); |
| | | //首箱 |
| | | var boxInfo = Db.Queryable<BllLabelBoxNo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo && m.IsUse == "0" && 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.IsUse == "0" && m.Level == "1").ToList(); |
| | | if (boxInfo2.Count == 0) |
| | | //是否连续组托 |
| | | if (model.IsContinue == "1") |
| | | { |
| | | throw new Exception("-1:尾箱码信息不存在!"); |
| | | } |
| | | boxInfoList.AddRange(boxInfo2); |
| | | var sql = $"select * from BllLabelBoxNo where IsDel = '0' and IsUse = '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); |
| | | //尾箱 |
| | | var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo && m.Status == "0").ToList(); |
| | | if (boxInfo2.Count == 0) |
| | | { |
| | | throw new Exception("-1:尾箱码信息不存在!"); |
| | | } |
| | | boxInfoList.AddRange(boxInfo2); |
| | | var sql = $"select * from BllBoxInfo where IsDel = '0' and Status = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; "; |
| | | var list = Db.Ado.SqlQuery<BllBoxInfo>(sql); |
| | | boxInfoList.AddRange(list); |
| | | msgStr += $"尾箱号为{model.TailBoxNo}"; |
| | | } |
| | | 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; |
| | | } |
| | | } |
| | | boxInfoList.AddRange(boxInfo); |
| | | } |
| | | #endregion |
| | | #endregion |
| | | |
| | | // 更改箱支关系表 |
| | | decimal factQty = 0.00m;//托盘总数量 |
| | | var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList(); |
| | | foreach (var g in boxGroup) |
| | | if (model.SkuQty == 0) |
| | | { |
| | | decimal boxFullQty = 0.00m;//箱内总数量 |
| | | foreach (var box in g) |
| | | var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList(); |
| | | foreach (var g in boxGroup) |
| | | { |
| | | if (box.IsUse != "0") |
| | | var boxFullQty = 0;//箱内总数量 |
| | | foreach (var box in g) |
| | | { |
| | | continue; |
| | | } |
| | | //箱内物料批次与单据明细不符合 |
| | | if (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo) |
| | | { |
| | | throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!"); |
| | | } |
| | | if (box.BindNo != null && box.BindNo != 0) |
| | | { |
| | | continue; |
| | | } |
| | | //箱内物料批次与单据明细不符合 |
| | | if (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo) |
| | | { |
| | | throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!"); |
| | | } |
| | | |
| | | box.ASNNo = model.AsnNo; |
| | | box.ASNDetailNo = model.AsnDetailId; |
| | | box.IsUse = "1"; |
| | | box.CompleteTime = DateTime.Now; |
| | | box.UpdateTime = DateTime.Now; |
| | | box.UpdateUser = userId; |
| | | box.ASNNo = model.AsnNo; |
| | | box.ASNDetailNo = model.AsnDetailId; |
| | | box.BindNo = bindId; |
| | | box.PalletNo = model.PalletNo; |
| | | box.Status = "1"; |
| | | box.CompleteTime = DateTime.Now; |
| | | box.UpdateTime = DateTime.Now; |
| | | box.UpdateUser = userId; |
| | | |
| | | if (box.ParentBoxNo == "" && box.Level == "1") |
| | | { |
| | | factQty += box.Qty; |
| | | boxFullQty += box.Qty; |
| | | } |
| | | } |
| | | if (boxFullQty > bNum) |
| | | { |
| | | throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!"); |
| | | } |
| | | } |
| | | if (boxFullQty > bNum) |
| | | { |
| | | throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!"); |
| | | } |
| | | } |
| | | Db.Updateable(boxInfoList).ExecuteCommand(); |
| | | Db.Updateable(boxInfoList).ExecuteCommand(); |
| | | |
| | | // 更新托盘绑定表 |
| | | bind.Qty += factQty; |
| | | // 更新托盘绑定表 |
| | | bind.Qty += factQty; |
| | | } |
| | | if (bind.FullQty < bind.Qty) |
| | | { |
| | | throw new Exception("托盘绑定数量已超出该物料包装数量"); |
| | |
| | | { |
| | | bind.BitPalletMark = "0"; |
| | | } |
| | | if (bind.Qty > pNum) |
| | | { |
| | | throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!"); |
| | | } |
| | | Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand(); |
| | | |
| | | // 更改入库单明细已组数量 |
| | | var sqlString = string.Empty; |
| | | sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{factQty}' where id = '{model.AsnDetailId}';"; |
| | | if (factQty == 0) |
| | | { |
| | | sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{bind.Qty}' where id = '{model.AsnDetailId}';"; |
| | | } |
| | | else |
| | | { |
| | | sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{factQty}' where id = '{model.AsnDetailId}';"; |
| | | } |
| | | |
| | | Db.Ado.ExecuteCommand(sqlString); |
| | | |
| | | // 更改入库单及入库明细状态 |
| | |
| | | //添加托盘记录表数据 |
| | | 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); |
| | | new OperationASNServer().AddLogOperationAsn("PDA模块", "托盘绑定", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId); |
| | | |
| | | Db.CommitTran(); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | Db.RollbackTran(); |
| | | throw ex; |
| | | } |
| | | } |