| | |
| | | using MES.Service.DB; |
| | | using Masuit.Tools; |
| | | using MES.Service.DB; |
| | | using MES.Service.Dto.service; |
| | | using MES.Service.Modes; |
| | | |
| | |
| | | { |
| | | // 根据AsnNo和MesNo对明细进行分组 |
| | | var groupedItems = itemOutLists |
| | | .GroupBy(item => new { item.MesNo, item.SqNo }) |
| | | // .GroupBy(item => new { item.MesNo, item.SqNo }) |
| | | .GroupBy(item => new { item.MesNo }) |
| | | .ToList(); |
| | | |
| | | int result = 1; |
| | |
| | | throw new NotImplementedException("入库单单号不能为空"); |
| | | } |
| | | |
| | | if (group.Key.SqNo == null) |
| | | { |
| | | throw new NotImplementedException("退货申请单行号不能为空"); |
| | | } |
| | | //if (group.Key.SqNo == null) |
| | | //{ |
| | | // throw new NotImplementedException("退货申请单行号不能为空"); |
| | | //} |
| | | |
| | | // 创建一个临时的itemOutFrom对象,使用分组的Key作为主要属性 |
| | | var tempItemOutFrom = new ItemOutFrom |
| | | { |
| | | //AsnNo = group.Key.AsnNo, |
| | | MesNo = group.Key.MesNo, |
| | | SqNo = group.Key.SqNo, |
| | | //SqNo = group.Key.SqNo, |
| | | // 继承原始itemOutFrom的其他属性 |
| | | RtnNo = itemOutFrom.RtnNo+ "-"+count.ToString(), |
| | | //RtnNo = itemOutFrom.RtnNo+ "-"+count.ToString(), |
| | | RtnNo = itemOutFrom.RtnNo, |
| | | Type = itemOutFrom.Type, |
| | | CreateBy = itemOutFrom.CreateBy, |
| | | FMRMODE = itemOutFrom.FMRMODE, |
| | |
| | | && s.Id == Convert.ToInt32(from.MesNo) |
| | | ).First(); |
| | | |
| | | if (mesInvItemIns == null) |
| | | { |
| | | throw new NotImplementedException("采购入库不存在"); |
| | | } |
| | | //if (mesInvItemIns == null) |
| | | //{ |
| | | // throw new NotImplementedException("采购入库不存在"); |
| | | //} |
| | | |
| | | var mesDepots = Db.Queryable<MesDepots>() |
| | | .Where(s => s.DepotId == Decimal.Parse(from.DepotId)).First(); |
| | |
| | | foreach (var itemOutList in items) |
| | | { |
| | | // 检查必要字段是否为空 |
| | | if (string.IsNullOrEmpty(itemOutList.SrcDocNo)) |
| | | { |
| | | throw new NotImplementedException("采购订单号不能为空"); |
| | | } |
| | | //if (string.IsNullOrEmpty(itemOutList.SrcDocNo)) |
| | | //{ |
| | | // throw new NotImplementedException("采购订单号不能为空"); |
| | | //} |
| | | |
| | | if (string.IsNullOrEmpty(itemOutList.SrcDocLineNo)) |
| | | { |
| | | throw new NotImplementedException("采购订单行号不能为空"); |
| | | } |
| | | //if (string.IsNullOrEmpty(itemOutList.SrcDocLineNo)) |
| | | //{ |
| | | // throw new NotImplementedException("采购订单行号不能为空"); |
| | | //} |
| | | |
| | | //if (string.IsNullOrEmpty(itemOutList.AsnLineNo)) |
| | | //{ |
| | |
| | | && s.OrderLineId == itemOutList.SrcDocLineNo) |
| | | .First(); |
| | | |
| | | if (mesRohInData == null) |
| | | { |
| | | throw new NotImplementedException("采购订单不存在"); |
| | | } |
| | | //if (mesRohInData == null) |
| | | //{ |
| | | // throw new NotImplementedException("采购订单不存在"); |
| | | //} |
| | | |
| | | //var deliveryDetail = Db.Queryable<DeliveryDetail>() |
| | | // .Where(a => Int32.Parse(a.ZzitemId) == |
| | |
| | | |
| | | var itemIdLinkU9 = Db.Queryable<MesLinkU9>() |
| | | .Where(s => s.TableType == "MES_ITEMS" |
| | | && s.U9Id == itemOutList.itemId).First(); |
| | | && s.U9Id == itemOutList.itemId &&s.OrgId== "1002011210000095").First(); |
| | | |
| | | if (mesLinkU9 == null) |
| | | { |
| | |
| | | throw new NotImplementedException("[" + itemOutList.itemId + |
| | | "]物料不存在,请同步给MES"); |
| | | } |
| | | var mesUnit = Db.Queryable<MesUnit>() |
| | | .Where(s => s.Id == int.Parse(mesItems.ItemUnit)).First(); |
| | | |
| | | var mesInvItemInCItems = Db.Queryable<MesInvItemInCItems>() |
| | | .Where(s => s.ItemInId == mesInvItemIns.Id |
| | | && s.ItemNo == mesItems.ItemNo |
| | | && s.Ebeln == itemOutList.SrcDocNo |
| | | && s.EbelnLineNo == |
| | | Decimal.Parse(itemOutList.SrcDocLineNo) |
| | | && s.SuppNo == mesSupplier.SuppNo |
| | | ).First(); |
| | | |
| | | if (mesInvItemInCItems == null) |
| | | if (itemOutList.SrcDocNo!=null&& itemOutList.SrcDocNo!="") |
| | | { |
| | | throw new NotImplementedException("没有对应的入库明细"); |
| | | var mesInvItemInCItems = Db.Queryable<MesInvItemInCItems>() |
| | | .Where(s => s.ItemInId == mesInvItemIns.Id |
| | | && s.ItemNo == mesItems.ItemNo |
| | | && s.Ebeln == itemOutList.SrcDocNo |
| | | && s.EbelnLineNo == |
| | | Decimal.Parse(itemOutList.SrcDocLineNo) |
| | | && s.SuppNo == mesSupplier.SuppNo |
| | | ).First(); |
| | | |
| | | if (mesInvItemInCItems == null) |
| | | { |
| | | throw new NotImplementedException("没有对应的入库明细"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // 确保CbillNo不为空 |
| | | if (string.IsNullOrEmpty(mesInvItemIns.CbillNo)) |
| | | { |
| | | throw new NotImplementedException("入库单关联的采购单号不能为空"); |
| | | } |
| | | |
| | | |
| | | mesInvItemOutItems.Add(new MesInvItemOutItems |
| | | { |
| | | ItemOutId = nextSequenceValue, |
| | | ItemNo = mesItems.ItemNo, |
| | | Quantity = Decimal.Parse(itemOutList.qty), |
| | | CreateBy = "PL017", |
| | | CreateDate = DateTime.Now, |
| | | Factory = "1000", |
| | | Company = "1000", |
| | | DepotCode = mesDepots.DepotCode, |
| | | WorkNo = itemOutList.SrcDocNo, // 确保WorkNo有值 |
| | | WorkLine = |
| | | Decimal.Parse(itemOutList.SrcDocLineNo), // 确保WorkLine有值 |
| | | EbelnK3id = Decimal.Parse(mesRohInData.ErpId), |
| | | LineK3id = Decimal.Parse(mesRohInData.EbelnK3id), |
| | | FType = 0, |
| | | Status = 0, |
| | | PbillNo = mesInvItemIns.CbillNo, // 确保PbillNo有值 |
| | | RkNo = from.MesNo, // 确保RkNo有值 |
| | | RkLine = mesInvItemInCItems.Id, // 确保RkLine有值 |
| | | RkQty = mesInvItemInCItems.Quantity, |
| | | TlQty = 0, |
| | | ItemId = Decimal.Parse(itemIdLinkU9.MesId), // 确保ItemId有值 |
| | | SqNo = itemOutList.SqNo, // 确保ItemId有值 |
| | | //ZzitemId = itemOutList.AsnLineNo, // 确保ItemId有值 |
| | | Unit = mesUnit.Fnumber, |
| | | }); |
| | | } |
| | | |
| | | |
| | | // 确保CbillNo不为空 |
| | | if (string.IsNullOrEmpty(mesInvItemIns.CbillNo)) |
| | | else |
| | | { |
| | | throw new NotImplementedException("入库单关联的采购单号不能为空"); |
| | | // var mesInvItemInCItems = Db.Queryable<MesInvItemInCItems>() |
| | | //.Where(s => s.ItemInId == mesInvItemIns.Id |
| | | // && s.ItemNo == mesItems.ItemNo |
| | | // && s.Ebeln == itemOutList.SrcDocNo |
| | | // && s.EbelnLineNo == |
| | | // Decimal.Parse(itemOutList.SrcDocLineNo) |
| | | // && s.SuppNo == mesSupplier.SuppNo |
| | | // ).First(); |
| | | |
| | | // if (mesInvItemInCItems == null) |
| | | // { |
| | | // throw new NotImplementedException("没有对应的入库明细"); |
| | | // } |
| | | |
| | | |
| | | |
| | | |
| | | //// 确保CbillNo不为空 |
| | | //if (string.IsNullOrEmpty(mesInvItemIns.CbillNo)) |
| | | //{ |
| | | // throw new NotImplementedException("入库单关联的采购单号不能为空"); |
| | | //} |
| | | |
| | | mesInvItemOutItems.Add(new MesInvItemOutItems |
| | | { |
| | | ItemOutId = nextSequenceValue, |
| | | ItemNo = mesItems.ItemNo, |
| | | Quantity = Decimal.Parse(itemOutList.qty), |
| | | CreateBy = "PL017", |
| | | CreateDate = DateTime.Now, |
| | | Factory = "1000", |
| | | Company = "1000", |
| | | DepotCode = mesDepots.DepotCode, |
| | | WorkNo = itemOutList.SrcDocNo, // 确保WorkNo有值 |
| | | WorkLine = |
| | | Decimal.Parse(itemOutList.SrcDocLineNo), // 确保WorkLine有值 |
| | | //EbelnK3id = Decimal.Parse(mesRohInData.ErpId), |
| | | //LineK3id = Decimal.Parse(mesRohInData.EbelnK3id), |
| | | FType = 0, |
| | | Status = 0, |
| | | //PbillNo = mesInvItemIns.CbillNo, // 确保PbillNo有值 |
| | | RkNo = from.MesNo, // 确保RkNo有值 |
| | | RkLine = null, // 确保RkLine有值 |
| | | RkQty = null, |
| | | TlQty = 0, |
| | | ItemId = Decimal.Parse(itemIdLinkU9.MesId), // 确保ItemId有值 |
| | | SqNo = itemOutList.SqNo, // 确保ItemId有值 |
| | | //ZzitemId = itemOutList.AsnLineNo, // 确保ItemId有值 |
| | | Unit = mesUnit.Fnumber, |
| | | }); |
| | | } |
| | | |
| | | mesInvItemOutItems.Add(new MesInvItemOutItems |
| | | { |
| | | ItemOutId = nextSequenceValue, |
| | | ItemNo = mesItems.ItemNo, |
| | | Quantity = Decimal.Parse(itemOutList.qty), |
| | | CreateBy = "PL017", |
| | | CreateDate = DateTime.Now, |
| | | Factory = "1000", |
| | | Company = "1000", |
| | | DepotCode = mesDepots.DepotCode, |
| | | WorkNo = itemOutList.SrcDocNo, // 确保WorkNo有值 |
| | | WorkLine = |
| | | Decimal.Parse(itemOutList.SrcDocLineNo), // 确保WorkLine有值 |
| | | EbelnK3id = Decimal.Parse(mesRohInData.ErpId), |
| | | LineK3id = Decimal.Parse(mesRohInData.EbelnK3id), |
| | | FType = 0, |
| | | Status = 0, |
| | | PbillNo = mesInvItemIns.CbillNo, // 确保PbillNo有值 |
| | | RkNo = from.MesNo, // 确保RkNo有值 |
| | | RkLine = mesInvItemInCItems.Id, // 确保RkLine有值 |
| | | RkQty = mesInvItemInCItems.Quantity, |
| | | TlQty = 0, |
| | | ItemId = Decimal.Parse(itemIdLinkU9.MesId), // 确保ItemId有值 |
| | | SqNo = itemOutList.SqNo, // 确保ItemId有值 |
| | | //ZzitemId = itemOutList.AsnLineNo, // 确保ItemId有值 |
| | | // Unit = item.Unit, |
| | | }); |
| | | |
| | | } |
| | | |
| | | var outItemCommand = Db.Insertable(mesInvItemOutItems) |