| | |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Inbound; |
| | | using static WIDESEA_Common.HouseInventoryIn; |
| | | using Parameter = WIDESEA_Common.Parameter; |
| | | |
| | | namespace WIDESEA_InboundService |
| | | { |
| | |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到该物料的信息"); |
| | | } |
| | | List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>(); |
| | | ///找数量匹配的 |
| | | List<Dt_InboundOrderDetail> inboundOrderDetails = inboundOrder.Details.Where(x => x.MaterielCode == materielCode && x.SupplierBatch == (models.FirstOrDefault()?.LotNo ?? "") && x.OrderQuantity > x.ReceiptQuantity && x.OrderQuantity == (quantitys.FirstOrDefault())).ToList(); |
| | | if (warehouse.WarehouseCode.Contains("BC")) |
| | | { |
| | | inboundOrderDetails = inboundOrder.Details.Where(x => x.MaterielCode == materielCode && x.SupplierBatch == (models.FirstOrDefault()?.LotNo ?? "") && x.OrderQuantity > x.ReceiptQuantity && x.OrderQuantity == (quantitys.FirstOrDefault())).ToList(); |
| | | } |
| | | else |
| | | { |
| | | inboundOrderDetails = inboundOrder.Details.Where(x => x.MaterielCode == materielCode && x.BatchNo == (models.FirstOrDefault()?.LotNo ?? "")).ToList(); |
| | | } |
| | | |
| | | |
| | | if (inboundOrderDetails == null || inboundOrderDetails.Count <= 0) |
| | | { |
| | |
| | | List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>(); |
| | | foreach (var model in models) |
| | | { |
| | | Dt_InboundOrderDetail? notGroupDetail = inboundOrderDetails.Where(x => x.OrderDetailStatus <= OrderDetailStatusEnum.Inbounding.ObjToInt() && x.MaterielCode == model.MaterielCode && x.SupplierBatch == model.LotNo && x.OrderQuantity > x.ReceiptQuantity).FirstOrDefault(); |
| | | |
| | | Dt_InboundOrderDetail notGroupDetail = new Dt_InboundOrderDetail(); |
| | | ///找数量匹配的 |
| | | if (warehouse.WarehouseCode.Contains("BC")) |
| | | { |
| | | notGroupDetail = inboundOrderDetails.Where(x => x.OrderDetailStatus <= OrderDetailStatusEnum.Inbounding.ObjToInt() && x.MaterielCode == model.MaterielCode && x.SupplierBatch == model.LotNo && x.OrderQuantity > x.ReceiptQuantity).FirstOrDefault(); |
| | | } |
| | | else |
| | | { |
| | | notGroupDetail = inboundOrderDetails.Where(x => x.OrderDetailStatus <= OrderDetailStatusEnum.Inbounding.ObjToInt() && x.MaterielCode == model.MaterielCode && x.BatchNo == model.LotNo && x.OrderQuantity > x.ReceiptQuantity).FirstOrDefault(); |
| | | } |
| | | |
| | | |
| | | if (notGroupDetail == null) |
| | | { |
| | |
| | | Id = inboundOrderDet.LinId.ObjToInt(), |
| | | DeliveryNote = model.DeliveryNote, |
| | | SupplierBatch = inboundOrderDet.SupplierBatch, |
| | | MaterieSpec = inboundOrderDet.MaterieSpec |
| | | MaterieSpec = inboundOrderDet.MaterieSpec, |
| | | OrinalLocation = inboundOrderDet.OrinalLocation |
| | | }; |
| | | |
| | | if (stockInfo.Id > 0) |
| | |
| | | .Select((cp, d, o) => cp) |
| | | .ToList(); |
| | | |
| | | float totalQty = CPinboundOrderDetails.Sum(x => x.QtyOfpcs); |
| | | //float totalQty = CPinboundOrderDetails.Sum(x => x.QtyOfpcs); |
| | | |
| | | |
| | | // 验证查询到的数据数量是否匹配 |
| | | if (CPinboundOrderDetails.Count < serialNumbers.Count) |
| | |
| | | .ToDictionary(g => g.Key, g => g.ToList()); |
| | | |
| | | |
| | | var existingStockBoxCodes = _stockRepository.StockInfoRepository.Db |
| | | .Queryable<Dt_StockInfo>() |
| | | .LeftJoin<Dt_StockInfoDetail>((s, d) => s.Id == d.StockId) |
| | | .LeftJoin<Dt_StockInfoDetailCP>((s, d, cp) => d.Id == cp.StockDetailId) |
| | | .Where((s, d, cp) => |
| | | serialNumbers.Contains(cp.BoxCode)) |
| | | .Select((s, d, cp) => cp.BoxCode) |
| | | .Distinct() |
| | | .ToList(); |
| | | |
| | | if (existingStockBoxCodes.Any()) |
| | | { |
| | | return WebResponseContent.Instance.Error($"以下箱号已在库存中:{string.Join(",", existingStockBoxCodes)}"); |
| | | } |
| | | |
| | | // 获取所有相关的入库单明细ID |
| | | var orderDetailIds = CPinboundOrderDetails.Select(x => x.OrderDetailId).Distinct().ToList(); |
| | |
| | | // 标记该明细为已完成组盘 |
| | | orderDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt(); |
| | | var recqty = orderDetail.ReceiptQuantity; |
| | | orderDetail.ReceiptQuantity = ((decimal)totalQty) + recqty; // 收货数量等于订单数量 |
| | | float totalQty = cpDetails.FirstOrDefault().QtyOfpcs; |
| | | orderDetail.ReceiptQuantity = (decimal)totalQty + recqty; // 收货数量等于订单数量 |
| | | |
| | | detailsToUpdate.Add(orderDetail); |
| | | } |
| | | |
| | | |
| | | |
| | | // 检查托盘是否已存在 |
| | | Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db |
| | |
| | | } |
| | | } |
| | | |
| | | List<Dt_CPInboundOrderDetail> cPInboundOrderDetail = new List<Dt_CPInboundOrderDetail>(); |
| | | // 创建库存明细 - 按订单明细创建 |
| | | foreach (var orderDetail in orderDetails) |
| | | { |
| | |
| | | .Select(x => x.BoxCode) |
| | | .ToList(); |
| | | |
| | | List<Dt_CPInboundOrderDetail> cPInboundOrderDetail = BaseDal.Db.Queryable<Dt_CPInboundOrderDetail>().Where(x => detailBoxCodes.Contains(x.BoxCode)).ToList(); |
| | | cPInboundOrderDetail = BaseDal.Db.Queryable<Dt_CPInboundOrderDetail>().Where(x => detailBoxCodes.Contains(x.BoxCode)).ToList(); |
| | | |
| | | List<Dt_StockInfoDetailCP> stockInfoDetailCP = new List<Dt_StockInfoDetailCP>(); |
| | | foreach (var item in cPInboundOrderDetail) |
| | | { |
| | |
| | | BatchNo = orderDetail.BatchNo, |
| | | SupplierBatch = orderDetail.SupplierBatch, |
| | | LinId = orderDetail.LinId, |
| | | StockQuantity = ((decimal)totalQty), |
| | | StockQuantity = (decimal)cPInboundOrderDetail.FirstOrDefault().QtyOfpcs, |
| | | Status = (int)StockStatusEmun.组盘暂存, |
| | | Creater = "WMS", |
| | | CreateDate = DateTime.Now, |
| | | Id = orderDetail.LinId.ObjToInt(), |
| | | //DeliveryNote = orderDetail.DeliveryNote, |
| | | MaterieSpec = orderDetail.MaterieSpec, |
| | | StockDetails = stockInfoDetailCP |
| | | StockDetails = stockInfoDetailCP, |
| | | OrinalLocation = orderDetail.OrinalLocation |
| | | }; |
| | | |
| | | if (stockInfo.Id > 0) |
| | |
| | | detailsToUpdate.Any(d => d.Id == x.Id) || |
| | | x.OrderDetailStatus == OrderDetailStatusEnum.GroupAndInbound.ObjToInt()); |
| | | |
| | | |
| | | inboundOrder.OrderStatus = InOrderStatusEnum.入库中.ObjToInt(); |
| | | |
| | | |
| | | // 事务处理 |
| | |
| | | // 更新订单 |
| | | _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder); |
| | | |
| | | _cPInboundOrderDetailRepository.UpdateData(CPinboundOrderDetails); |
| | | _cPInboundOrderDetailRepository.UpdateData(cPInboundOrderDetail); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | |
| | | |
| | | return content; |
| | | } |
| | | public string ReceiveWMSTaskin = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskin"]; |
| | | /// <summary> |
| | | /// 合托 |
| | | /// </summary> |
| | | /// <param name="saveModel"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent SYMaterielGroup(SaveModel saveModel) |
| | | { |
| | | |
| | | WebResponseContent webResponseContent = new WebResponseContent(); |
| | | try |
| | | { |
| | | var soussAddress = saveModel.MainData["soussAddress"]; |
| | | var targetAddress = saveModel.MainData["targetAddress"]; |
| | | |
| | | Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == soussAddress).First(); |
| | | Dt_StockInfo stockInfo1 = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == targetAddress).First(); |
| | | Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == stockInfo1.WarehouseId); |
| | | if (stockInfo == null || stockInfo1 == null) |
| | | { |
| | | throw new Exception("库存未找到托盘号"); |
| | | } |
| | | foreach (var item in stockInfo.Details) |
| | | { |
| | | item.StockId = stockInfo1.Id; |
| | | } |
| | | var houseSyncretism = new HouseSyncretism |
| | | { |
| | | ApiType = "AsnController", |
| | | Method = "AsrsGroudingAsn", |
| | | Parameters = new List<HouseSyncretism.data> |
| | | { |
| | | new HouseSyncretism.data |
| | | { |
| | | Lpn=stockInfo.PalletCode, |
| | | MoveType=0, |
| | | WareHouseCode=warehouse.WarehouseCode, |
| | | |
| | | } |
| | | } |
| | | }; |
| | | |
| | | var authResult = AuthenticateWithWMS(); |
| | | if (authResult.IsSuccess) |
| | | { |
| | | houseSyncretism.Context = new Dictionary<string, string> |
| | | { |
| | | { "Ticket", authResult.Ticket }, |
| | | { "InvOrgId", authResult.InvOrgId } |
| | | |
| | | }; |
| | | |
| | | var response = HttpHelper.Post<MomRequestContent>(ReceiveWMSTaskin, houseSyncretism, "立库入库数量回传WMS"); |
| | | // 判断Success的值 |
| | | if (!response.Success) |
| | | { |
| | | throw new Exception($"操作失败: {response.Message ?? "未提供错误信息"}"); |
| | | } |
| | | |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | stockInfo1.Details.AddRange(stockInfo.Details); |
| | | _stockRepository.StockInfoRepository.UpdateData(stockInfo1); |
| | | stockInfo.Details.Clear(); |
| | | _stockRepository.StockInfoRepository.UpdateData(stockInfo); |
| | | _unitOfWorkManage.CommitTran(); |
| | | webResponseContent = WebResponseContent.Instance.OK("合托成功"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | webResponseContent = WebResponseContent.Instance.Error($"组盘失败:{ex.Message}"); |
| | | } |
| | | return webResponseContent; |
| | | } |
| | | |
| | | private (bool IsSuccess, string Ticket, string InvOrgId) AuthenticateWithWMS() |
| | | { |
| | | var authentication = new Authentication |
| | | { |
| | | ApiType = "AuthenticationController", |
| | | Parameters = new List<Parameter> |
| | | { |
| | | new Parameter { Value = "LK-Admin" }, |
| | | new Parameter { Value = "LK-Admin" } |
| | | }, |
| | | Method = "Login", |
| | | }; |
| | | |
| | | var response = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, authentication, "登录WMS账号"); |
| | | |
| | | if (response.Context != null) |
| | | { |
| | | return (true, response.Context["Ticket"].ToString(), response.Context["InvOrgId"].ToString()); |
| | | } |
| | | |
| | | return (false, null, null); |
| | | } |
| | | |
| | | |
| | | public int GetPalletType(Dt_Warehouse warehouse, string palletCode) |
| | | { |
| | |
| | | { |
| | | return content.Error($"未找到仓库信息"); |
| | | } |
| | | if (warehouse.WarehouseCode.Contains("TestJCLK")) |
| | | if (warehouse.WarehouseCode.Contains("CP")) |
| | | { |
| | | if (item.SupplierBatch == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | List<Dt_CPInboundOrderDetail> cPInboundOrderDetail = new List<Dt_CPInboundOrderDetail>(); |
| | | foreach (var list in item.BoxList) |
| | | { |
| | | Dt_CPInboundOrderDetail cPInboundOrderDetail1 = new Dt_CPInboundOrderDetail() |
| | | { |
| | | BoxId = (float)list.BoxId, |
| | | BoxCode = list.BoxCode, |
| | | DateCode = list.DateCode, |
| | | JobId = (float)list.JobId, |
| | | PartNum = list.PartNum, |
| | | QtyOfpcs = (float)list.QtyOfpcs, |
| | | QtyOfxout = (float)list.QtyOfxout, |
| | | CPOrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | Creater = "上游WMS", |
| | | }; |
| | | cPInboundOrderDetail.Add(cPInboundOrderDetail1); |
| | | } |
| | | |
| | | Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail() |
| | | { |
| | | OrderId = orderDetail1.OrderId, |
| | |
| | | MaterielName = item.MaterielName, |
| | | MaterieSpec = item.MaterieSpec, |
| | | Creater = "上游WMS", |
| | | SupplierBatch = item.SupplierBatch |
| | | SupplierBatch = item.SupplierBatch, |
| | | OrinalLocation = item.OrinalLocation, |
| | | CPDetails = cPInboundOrderDetail |
| | | }; |
| | | _inboundRepository.InboundOrderDetailRepository.AddData(orderDetail); |
| | | //_inboundRepository.InboundOrderDetailRepository.AddData(orderDetail); |
| | | Db.InsertNav(orderDetail).Include(x => x.CPDetails).ExecuteCommand(); |
| | | } |
| | | } |
| | | else |
| | |
| | | MaterieSpec = item.MaterieSpec, |
| | | Creater = "上游WMS", |
| | | SupplierBatch = item.SupplierBatch, |
| | | OrinalLocation = item.OrinalLocation, |
| | | CPDetails = cPInboundOrderDetail |
| | | }; |
| | | |
| | |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// erp单据下发 |
| | | /// </summary> |
| | | /// <param name="addInboundOrder"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent Save(AddInboundOrderModel addInboundOrder) |
| | | { |
| | | try |