| | |
| | | private readonly IStockRepository _stockRepository; |
| | | private IPalletTypeInfoRepository _palletTypeInfoRepository; |
| | | private readonly IReturnOrderRepository _returnOrderRepository; |
| | | private readonly ICPInboundOrderDetailRepository _cPInboundOrderDetailRepository; |
| | | |
| | | |
| | | public IInboundOrderRepository Repository => BaseDal; |
| | | |
| | | public InboundOrderService(IInboundOrderRepository BaseDal, IMapper mapper, IBasicService basicService, IBasicRepository basicRepository, IInboundRepository inboundRepository, IUnitOfWorkManage unitOfWorkManage, ITaskRepository taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IInboundOrder_HtyService inboundOrderHtyService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IWarehouseService warehouseService, IStockRepository stockRepository, IPalletTypeInfoRepository palletTypeInfoRepository,IReturnOrderRepository returnOrderRepository) : base(BaseDal) |
| | | public InboundOrderService(IInboundOrderRepository BaseDal, IMapper mapper, IBasicService basicService, IBasicRepository basicRepository, IInboundRepository inboundRepository, IUnitOfWorkManage unitOfWorkManage, ITaskRepository taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IInboundOrder_HtyService inboundOrderHtyService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IWarehouseService warehouseService, IStockRepository stockRepository, IPalletTypeInfoRepository palletTypeInfoRepository, IReturnOrderRepository returnOrderRepository, ICPInboundOrderDetailRepository cPInboundOrderDetailRepository) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | |
| | | _stockRepository = stockRepository; |
| | | _palletTypeInfoRepository = palletTypeInfoRepository; |
| | | _returnOrderRepository = returnOrderRepository; |
| | | _cPInboundOrderDetailRepository = cPInboundOrderDetailRepository; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 组盘 |
| | | /// PDA扫码组盘 |
| | | /// </summary> |
| | | /// <param name="materielGroupDTO"></param> |
| | | /// <returns></returns> |
| | |
| | | return WebResponseContent.Instance.Error($"未找到该物料的信息"); |
| | | } |
| | | ///找数量匹配的 |
| | | 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(); |
| | | 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 (inboundOrderDetails == null || inboundOrderDetails.Count <= 0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未在入库单明细中找到该物料信息或数量不匹配"); |
| | | return WebResponseContent.Instance.Error($"未在入库单明细中找到该物料信息或数量不匹配"); |
| | | } |
| | | var inboundOrderDet = inboundOrderDetails.FirstOrDefault(); |
| | | |
| | |
| | | { |
| | | //if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt()) |
| | | //{ |
| | | return WebResponseContent.Instance.Error($"托盘号重复,该托盘已组过物料"); |
| | | return WebResponseContent.Instance.Error($"托盘号重复,该托盘已组过物料"); |
| | | //} |
| | | //beforeQuantity = stockInfo.Details.Sum(x => x.StockQuantity); |
| | | } |
| | |
| | | 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 = inboundOrderDetails.Where(x => x.OrderDetailStatus <= OrderDetailStatusEnum.Inbounding.ObjToInt() && x.MaterielCode == model.MaterielCode && x.SupplierBatch == model.LotNo && x.OrderQuantity > x.ReceiptQuantity).FirstOrDefault(); |
| | | |
| | | if (notGroupDetail == null) |
| | | { |
| | |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 成品组盘 |
| | | /// </summary> |
| | | /// <param name="materielGroupDTO"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent CPMaterielGroup(SaveModel saveModel) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var orderNo = saveModel.MainData["orderNo"].ToString(); |
| | | var palletCode = saveModel.MainData["palletCode"].ToString(); |
| | | var warehouseId = saveModel.MainData["warehouseId"].ObjToInt(); |
| | | var serialNumbers = new List<string>(); |
| | | var quantities = new List<decimal>(); |
| | | var lotNos = new List<string>(); |
| | | var materielCodes = new List<string>(); |
| | | |
| | | foreach (var item in saveModel.DelKeys) |
| | | { |
| | | var delKeyDict = item as IDictionary<string, object>; |
| | | if (delKeyDict == null) |
| | | { |
| | | string json = JsonConvert.SerializeObject(item); |
| | | delKeyDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(json); |
| | | } |
| | | |
| | | // 处理序列号 |
| | | if (!delKeyDict.TryGetValue("serialNumber", out object serialNumberObj) || serialNumberObj == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("缺少serialNumber字段或值为空"); |
| | | } |
| | | |
| | | string serialNumber = serialNumberObj.ToString(); |
| | | if (string.IsNullOrWhiteSpace(serialNumber)) |
| | | { |
| | | return WebResponseContent.Instance.Error("serialNumber的值为空"); |
| | | } |
| | | serialNumbers.Add(serialNumber); |
| | | } |
| | | // 获取仓库信息 |
| | | Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId); |
| | | if (warehouse == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到该仓库信息"); |
| | | } |
| | | |
| | | // 获取入库单信息 |
| | | Dt_InboundOrder inboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>() |
| | | .Where(x => x.OrderNo == orderNo && x.WarehouseId == warehouse.WarehouseId) |
| | | .Includes(x => x.Details) |
| | | .First(); |
| | | |
| | | if (inboundOrder == null || inboundOrder.Details == null || inboundOrder.Details.Count <= 0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到入库单信息"); |
| | | } |
| | | |
| | | // 批量查询所有相关箱号的CP入库单明细 |
| | | List<Dt_CPInboundOrderDetail> CPinboundOrderDetails = BaseDal.Db.Queryable<Dt_CPInboundOrderDetail>() |
| | | .LeftJoin<Dt_InboundOrderDetail>((cp, d) => cp.OrderDetailId == d.Id) |
| | | .LeftJoin<Dt_InboundOrder>((cp, d, o) => d.OrderId == o.Id) |
| | | .Where((cp, d, o) => |
| | | o.OrderNo == orderNo && |
| | | o.WarehouseId == warehouse.WarehouseId && |
| | | serialNumbers.Contains(cp.BoxCode) |
| | | ) |
| | | .Select((cp, d, o) => cp) |
| | | .ToList(); |
| | | |
| | | float totalQty = CPinboundOrderDetails.Sum(x => x.QtyOfpcs); |
| | | |
| | | // 验证查询到的数据数量是否匹配 |
| | | if (CPinboundOrderDetails.Count < serialNumbers.Count) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到所有对应的箱号信息,找到{CPinboundOrderDetails.Count}条,期望{serialNumbers.Count}条"); |
| | | } |
| | | |
| | | // 按照箱号分组,用于后续处理 |
| | | var cpDetailsByBoxCode = CPinboundOrderDetails |
| | | .GroupBy(x => x.BoxCode) |
| | | .ToDictionary(g => g.Key, g => g.ToList()); |
| | | |
| | | |
| | | |
| | | // 获取所有相关的入库单明细ID |
| | | var orderDetailIds = CPinboundOrderDetails.Select(x => x.OrderDetailId).Distinct().ToList(); |
| | | |
| | | // 查询对应的入库单明细 |
| | | List<Dt_InboundOrderDetail> inboundOrderDetails = BaseDal.Db.Queryable<Dt_InboundOrderDetail>() |
| | | .Where(x => orderDetailIds.Contains(x.Id)) |
| | | .ToList(); |
| | | |
| | | // 按订单明细ID分组,检查每个明细的所有箱号是否都扫描了 |
| | | var detailsByOrderDetailId = CPinboundOrderDetails |
| | | .GroupBy(x => x.OrderDetailId) |
| | | .ToDictionary(g => g.Key, g => g.ToList()); |
| | | |
| | | // 获取相关的订单明细 |
| | | List<Dt_InboundOrderDetail> orderDetails = new List<Dt_InboundOrderDetail>(); |
| | | List<Dt_InboundOrderDetail> detailsToUpdate = new List<Dt_InboundOrderDetail>(); |
| | | |
| | | // 检查每个订单明细是否完成了所有箱号的扫描 |
| | | foreach (var kvp in detailsByOrderDetailId) |
| | | { |
| | | int orderDetailId = kvp.Key; |
| | | var cpDetails = kvp.Value; |
| | | |
| | | // 获取订单明细 |
| | | var orderDetail = inboundOrder.Details.FirstOrDefault(x => x.Id == orderDetailId); |
| | | if (orderDetail == null) |
| | | { |
| | | orderDetail = BaseDal.Db.Queryable<Dt_InboundOrderDetail>() |
| | | .First(x => x.Id == orderDetailId); |
| | | } |
| | | |
| | | if (orderDetail == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到订单明细ID:{orderDetailId}"); |
| | | } |
| | | |
| | | orderDetails.Add(orderDetail); |
| | | |
| | | // 标记该明细为已完成组盘 |
| | | orderDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt(); |
| | | var recqty = orderDetail.ReceiptQuantity; |
| | | orderDetail.ReceiptQuantity = ((decimal)totalQty) + recqty; // 收货数量等于订单数量 |
| | | |
| | | detailsToUpdate.Add(orderDetail); |
| | | } |
| | | |
| | | // 检查托盘是否已存在 |
| | | Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db |
| | | .Queryable<Dt_StockInfo>() |
| | | .Where(x => x.PalletCode == palletCode) |
| | | .Includes(x => x.Details) |
| | | .First(); |
| | | |
| | | if (stockInfo == null) |
| | | { |
| | | // 创建新托盘 |
| | | stockInfo = new Dt_StockInfo() |
| | | { |
| | | BatchNo = "", // 使用入库单批次号 |
| | | PalletCode = palletCode, |
| | | PalletType = GetPalletType(warehouse, palletCode), |
| | | IsFull = true, |
| | | StockStatus = (int)StockStatusEmun.组盘暂存, |
| | | Creater = "WMS", |
| | | CreateDate = DateTime.Now, |
| | | MaterialType = (int)InventoryMaterialType.原材料, |
| | | Materialweight = 0, |
| | | Wlstatus = (int)InventoryMaterialStatus.合格, |
| | | Mgeneratetime = DateTime.Now, |
| | | WarehouseId = warehouse.WarehouseId, |
| | | Details = new List<Dt_StockInfoDetail>() |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | // 如果托盘已存在,检查是否已经是组盘暂存状态 |
| | | if (stockInfo.StockStatus != (int)StockStatusEmun.组盘暂存) |
| | | { |
| | | return WebResponseContent.Instance.Error($"托盘号重复,该托盘已组过物料"); |
| | | } |
| | | } |
| | | |
| | | // 创建库存明细 - 按订单明细创建 |
| | | foreach (var orderDetail in orderDetails) |
| | | { |
| | | // 获取该明细对应的所有箱号 |
| | | var detailBoxCodes = detailsByOrderDetailId[orderDetail.Id] |
| | | .Select(x => x.BoxCode) |
| | | .ToList(); |
| | | |
| | | List<Dt_CPInboundOrderDetail> 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) |
| | | { |
| | | Dt_StockInfoDetailCP stockInfoDetailCP1 = new Dt_StockInfoDetailCP() |
| | | { |
| | | BoxId = item.BoxId, |
| | | BoxCode = item.BoxCode, |
| | | DateCode = item.DateCode, |
| | | JobId = item.JobId, |
| | | PartNum = item.PartNum, |
| | | QtyOfpcs = item.QtyOfpcs, |
| | | QtyOfxout = item.QtyOfxout, |
| | | CPStockDetailStatus = (int)StockStatusEmun.组盘暂存, |
| | | Creater = "上游WMS", |
| | | }; |
| | | stockInfoDetailCP.Add(stockInfoDetailCP1); |
| | | |
| | | item.CPOrderDetailStatus = InOrderStatusEnum.入库中.ObjToInt(); |
| | | } |
| | | |
| | | // 创建库存明细 |
| | | Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail() |
| | | { |
| | | MaterielCode = orderDetail.MaterielCode, |
| | | MaterielName = orderDetail.MaterielName, |
| | | OrderNo = inboundOrder.OrderNo, |
| | | BatchNo = orderDetail.BatchNo, |
| | | SupplierBatch = orderDetail.SupplierBatch, |
| | | LinId = orderDetail.LinId, |
| | | StockQuantity = ((decimal)totalQty), |
| | | Status = (int)StockStatusEmun.组盘暂存, |
| | | Creater = "WMS", |
| | | CreateDate = DateTime.Now, |
| | | Id = orderDetail.LinId.ObjToInt(), |
| | | //DeliveryNote = orderDetail.DeliveryNote, |
| | | MaterieSpec = orderDetail.MaterieSpec, |
| | | StockDetails = stockInfoDetailCP |
| | | }; |
| | | |
| | | if (stockInfo.Id > 0) |
| | | { |
| | | stockInfoDetail.StockId = stockInfo.Id; |
| | | } |
| | | stockInfo.Details.Add(stockInfoDetail); |
| | | } |
| | | |
| | | // 检查入库单是否所有明细都已完成组盘 |
| | | bool allDetailsCompleted = inboundOrder.Details.All(x => |
| | | detailsToUpdate.Any(d => d.Id == x.Id) || |
| | | x.OrderDetailStatus == OrderDetailStatusEnum.GroupAndInbound.ObjToInt()); |
| | | |
| | | |
| | | |
| | | // 事务处理 |
| | | _unitOfWorkManage.BeginTran(); |
| | | try |
| | | { |
| | | if (stockInfo.Id == 0) |
| | | { |
| | | _stockRepository.StockInfoRepository.Db.InsertNav(stockInfo) |
| | | .Include(x => x.Details).ThenInclude(x => x.StockDetails) |
| | | .ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | _stockRepository.StockInfoRepository.Db.UpdateNav(stockInfo) |
| | | .Include(x => x.Details, new UpdateNavOptions() |
| | | { |
| | | OneToManyInsertOrUpdate = true |
| | | }).ThenInclude(x => x.StockDetails) |
| | | .ExecuteCommand(); |
| | | } |
| | | |
| | | // 更新订单明细 |
| | | if (detailsToUpdate.Count > 0) |
| | | { |
| | | _inboundRepository.InboundOrderDetailRepository.UpdateData(detailsToUpdate); |
| | | } |
| | | |
| | | // 更新订单 |
| | | _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder); |
| | | |
| | | _cPInboundOrderDetailRepository.UpdateData(CPinboundOrderDetails); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | content = WebResponseContent.Instance.OK("组盘成功"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | throw new Exception($"组盘事务处理失败:{ex.Message}", ex); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"组盘失败:{ex.Message}"); |
| | | } |
| | | |
| | | return content; |
| | | } |
| | | |
| | | public int GetPalletType(Dt_Warehouse warehouse, string palletCode) |
| | | { |
| | | |
| | |
| | | { |
| | | return content.Error($"未找到仓库信息"); |
| | | } |
| | | if (item.SupplierBatch == null) |
| | | if (warehouse.WarehouseCode.Contains("CP")) |
| | | { |
| | | return content.Error("供应商批次不可为空"); |
| | | } |
| | | Dt_InboundOrder inboundOrderOld = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == model.AsnNo).Includes(x => x.Details).First(); |
| | | |
| | | if (inboundOrderOld != null) |
| | | { |
| | | if (inboundOrderOld.OrderStatus == InOrderStatusEnum.入库完成.ObjToInt()) |
| | | if (item.SupplierBatch == null) |
| | | { |
| | | inboundOrderOld.OrderStatus = InOrderStatusEnum.入库中.ObjToInt(); |
| | | _inboundRepository.InboundOrderRepository.UpdateData(inboundOrderOld); |
| | | return content.Error("供应商批次不可为空"); |
| | | } |
| | | Dt_InboundOrderDetail orderDetail1 = BaseDal.Db.Queryable<Dt_InboundOrderDetail>().Where(x => x.OrderId == inboundOrderOld.Id).First(); |
| | | Dt_InboundOrderDetail? inboundOrderDetailOld = inboundOrderOld.Details?.FirstOrDefault(x => x.LinId == item.LinId && x.MaterielCode == item.MaterielCode); |
| | | if (inboundOrderDetailOld != null) |
| | | Dt_InboundOrder inboundOrderOld = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == model.AsnNo).Includes(x => x.Details).First(); |
| | | |
| | | if (inboundOrderOld != null) |
| | | { |
| | | inboundOrderDetailOld.OrderQuantity += item.OrderQuantity; |
| | | _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetailOld); |
| | | if (inboundOrderOld.OrderStatus == InOrderStatusEnum.入库完成.ObjToInt()) |
| | | { |
| | | inboundOrderOld.OrderStatus = InOrderStatusEnum.入库中.ObjToInt(); |
| | | _inboundRepository.InboundOrderRepository.UpdateData(inboundOrderOld); |
| | | } |
| | | Dt_InboundOrderDetail orderDetail1 = BaseDal.Db.Queryable<Dt_InboundOrderDetail>().Where(x => x.OrderId == inboundOrderOld.Id).First(); |
| | | Dt_InboundOrderDetail? inboundOrderDetailOld = inboundOrderOld.Details?.FirstOrDefault(x => x.LinId == item.LinId && x.MaterielCode == item.MaterielCode); |
| | | if (inboundOrderDetailOld != null) |
| | | { |
| | | inboundOrderDetailOld.OrderQuantity += item.OrderQuantity; |
| | | _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetailOld); |
| | | } |
| | | else |
| | | { |
| | | Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail() |
| | | { |
| | | OrderId = orderDetail1.OrderId, |
| | | MaterielCode = item.MaterielCode, |
| | | BatchNo = item.BatchNo, |
| | | OrderQuantity = item.OrderQuantity, |
| | | ReceiptQuantity = 0, |
| | | OverInQuantity = 0, |
| | | OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | LinId = item.LinId, |
| | | LPNNo = item.LPNNo, |
| | | MaterielName = item.MaterielName, |
| | | MaterieSpec = item.MaterieSpec, |
| | | Creater = "上游WMS", |
| | | SupplierBatch = item.SupplierBatch |
| | | }; |
| | | _inboundRepository.InboundOrderDetailRepository.AddData(orderDetail); |
| | | } |
| | | } |
| | | 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, |
| | | MaterielCode = item.MaterielCode, |
| | | BatchNo = item.BatchNo, |
| | | OrderQuantity = item.OrderQuantity, |
| | |
| | | OverInQuantity = 0, |
| | | OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | LinId = item.LinId, |
| | | LPNNo = item.LPN_No, |
| | | LPNNo = item.LPNNo, |
| | | MaterielName = item.MaterielName, |
| | | MaterieSpec = item.MaterieSpec, |
| | | Creater = "上游WMS", |
| | | SupplierBatch = item.SupplierBatch, |
| | | CPDetails = cPInboundOrderDetail |
| | | }; |
| | | |
| | | Dt_InboundOrder inboundOrder = new Dt_InboundOrder() |
| | | { |
| | | OrderNo = model.AsnNo, |
| | | UpperOrderNo = model.AsnNo, |
| | | WarehouseId = warehouse.WarehouseId, |
| | | //SupplierId = "", |
| | | OrderStatus = InboundStatusEnum.未开始.ObjToInt(), |
| | | CreateType = CreateType.UpperSystemPush.ObjToInt(), |
| | | Remark = "", |
| | | TransactionCode = model.TransactionCode, |
| | | InoutType = model.OrderType, |
| | | OrderType = model.InoutType.ObjToInt(), |
| | | Creater = "上游WMS", |
| | | System = model.System, |
| | | Details = new List<Dt_InboundOrderDetail> { orderDetail } |
| | | }; |
| | | //switch (model.OrderType)//单据类型 |
| | | //{ |
| | | // case 1: |
| | | // inboundOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt(); |
| | | // break; |
| | | // case 3: |
| | | // inboundOrder.OrderType = InOrderTypeEnum.CustomerRecovery.ObjToInt(); |
| | | // break; |
| | | // case 6: |
| | | // inboundOrder.OrderType = InOrderTypeEnum.SaleReturn.ObjToInt(); |
| | | // break; |
| | | // default: |
| | | // break; |
| | | //}; |
| | | |
| | | |
| | | Db.InsertNav(inboundOrder).Include(x => x.Details).ThenInclude(x => x.CPDetails).ExecuteCommand(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (item.SupplierBatch == null) |
| | | { |
| | | return content.Error("供应商批次不可为空"); |
| | | } |
| | | Dt_InboundOrder inboundOrderOld = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == model.AsnNo).Includes(x => x.Details).First(); |
| | | |
| | | if (inboundOrderOld != null) |
| | | { |
| | | if (inboundOrderOld.OrderStatus == InOrderStatusEnum.入库完成.ObjToInt()) |
| | | { |
| | | inboundOrderOld.OrderStatus = InOrderStatusEnum.入库中.ObjToInt(); |
| | | _inboundRepository.InboundOrderRepository.UpdateData(inboundOrderOld); |
| | | } |
| | | Dt_InboundOrderDetail orderDetail1 = BaseDal.Db.Queryable<Dt_InboundOrderDetail>().Where(x => x.OrderId == inboundOrderOld.Id).First(); |
| | | Dt_InboundOrderDetail? inboundOrderDetailOld = inboundOrderOld.Details?.FirstOrDefault(x => x.LinId == item.LinId && x.MaterielCode == item.MaterielCode); |
| | | if (inboundOrderDetailOld != null) |
| | | { |
| | | inboundOrderDetailOld.OrderQuantity += item.OrderQuantity; |
| | | _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetailOld); |
| | | } |
| | | else |
| | | { |
| | | Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail() |
| | | { |
| | | OrderId = orderDetail1.OrderId, |
| | | MaterielCode = item.MaterielCode, |
| | | BatchNo = item.BatchNo, |
| | | OrderQuantity = item.OrderQuantity, |
| | | ReceiptQuantity = 0, |
| | | OverInQuantity = 0, |
| | | OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | LinId = item.LinId, |
| | | LPNNo = item.LPNNo, |
| | | MaterielName = item.MaterielName, |
| | | MaterieSpec = item.MaterieSpec, |
| | | Creater = "上游WMS", |
| | | SupplierBatch = item.SupplierBatch |
| | | }; |
| | | _inboundRepository.InboundOrderDetailRepository.AddData(orderDetail); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail() |
| | | { |
| | | MaterielCode = item.MaterielCode, |
| | | BatchNo = item.BatchNo, |
| | | OrderQuantity = item.OrderQuantity, |
| | | ReceiptQuantity = 0, |
| | | OverInQuantity = 0, |
| | | OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | LinId = item.LinId, |
| | | LPNNo = item.LPNNo, |
| | | MaterielName = item.MaterielName, |
| | | MaterieSpec = item.MaterieSpec, |
| | | Creater = "上游WMS", |
| | | SupplierBatch = item.SupplierBatch |
| | | }; |
| | | _inboundRepository.InboundOrderDetailRepository.AddData(orderDetail); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail() |
| | | { |
| | | MaterielCode = item.MaterielCode, |
| | | BatchNo = item.BatchNo, |
| | | OrderQuantity = item.OrderQuantity, |
| | | ReceiptQuantity = 0, |
| | | OverInQuantity = 0, |
| | | OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | LinId = item.LinId, |
| | | LPNNo = item.LPN_No, |
| | | MaterielName = item.MaterielName, |
| | | MaterieSpec = item.MaterieSpec, |
| | | Creater = "上游WMS", |
| | | SupplierBatch = item.SupplierBatch |
| | | }; |
| | | |
| | | Dt_InboundOrder inboundOrder = new Dt_InboundOrder() |
| | | { |
| | | OrderNo = model.AsnNo, |
| | | UpperOrderNo = model.AsnNo, |
| | | WarehouseId = warehouse.WarehouseId, |
| | | //SupplierId = "", |
| | | OrderStatus = InboundStatusEnum.未开始.ObjToInt(), |
| | | CreateType = CreateType.UpperSystemPush.ObjToInt(), |
| | | Remark = "", |
| | | TransactionCode = model.TransactionCode, |
| | | InoutType = model.OrderType, |
| | | OrderType = model.InoutType.ObjToInt(), |
| | | Creater = "上游WMS", |
| | | System = model.System, |
| | | Details = new List<Dt_InboundOrderDetail> { orderDetail } |
| | | }; |
| | | //switch (model.OrderType)//单据类型 |
| | | //{ |
| | | // case 1: |
| | | // inboundOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt(); |
| | | // break; |
| | | // case 3: |
| | | // inboundOrder.OrderType = InOrderTypeEnum.CustomerRecovery.ObjToInt(); |
| | | // break; |
| | | // case 6: |
| | | // inboundOrder.OrderType = InOrderTypeEnum.SaleReturn.ObjToInt(); |
| | | // break; |
| | | // default: |
| | | // break; |
| | | //}; |
| | | Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | |
| | | Dt_InboundOrder inboundOrder = new Dt_InboundOrder() |
| | | { |
| | | OrderNo = model.AsnNo, |
| | | UpperOrderNo = model.AsnNo, |
| | | WarehouseId = warehouse.WarehouseId, |
| | | //SupplierId = "", |
| | | OrderStatus = InboundStatusEnum.未开始.ObjToInt(), |
| | | CreateType = CreateType.UpperSystemPush.ObjToInt(), |
| | | Remark = "", |
| | | TransactionCode = model.TransactionCode, |
| | | InoutType = model.OrderType, |
| | | OrderType = model.InoutType.ObjToInt(), |
| | | Creater = "上游WMS", |
| | | System = model.System, |
| | | Details = new List<Dt_InboundOrderDetail> { orderDetail } |
| | | }; |
| | | //switch (model.OrderType)//单据类型 |
| | | //{ |
| | | // case 1: |
| | | // inboundOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt(); |
| | | // break; |
| | | // case 3: |
| | | // inboundOrder.OrderType = InOrderTypeEnum.CustomerRecovery.ObjToInt(); |
| | | // break; |
| | | // case 6: |
| | | // inboundOrder.OrderType = InOrderTypeEnum.SaleReturn.ObjToInt(); |
| | | // break; |
| | | // default: |
| | | // break; |
| | | //}; |
| | | Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | |
| | | } |
| | | } |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | |
| | | |
| | | } |
| | | finally |
| | | { |
| | |
| | | MaterielName = model.MaterielName, |
| | | SupplierBatch = model.SupplierBatch, |
| | | OrderQuantity = model.OrderQuantity, |
| | | BatchNo ="PC"+$"{datePart}{randomNum}", |
| | | BatchNo = "PC" + $"{datePart}{randomNum}", |
| | | OrderDetailStatus = InOrderStatusEnum.未开始.ObjToInt(), |
| | | Creater = "WMS", |
| | | CreateDate = DateTime.Now, |
| | |
| | | .Where(d => d.OrderId == inboundOrder.Id) |
| | | .Count(); |
| | | //检查明细完成的个数 |
| | | int overCount = _inboundRepository.InboundOrderDetailRepository |
| | | int overCount = _inboundRepository.InboundOrderDetailRepository |
| | | .Db.Queryable<Dt_InboundOrderDetail>() |
| | | .Where(d => d.OrderId == inboundOrder.Id && d.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()) |
| | | .Count(); |
| | |
| | | _inboundRepository.InboundOrderRepository.DeleteAndMoveIntoHty(inboundOrder, OperateType.人工取消); |
| | | } |
| | | //如果取消以后明细已经全部完成 |
| | | if (remainingDetailsCount == overCount) |
| | | if (remainingDetailsCount == overCount) |
| | | { |
| | | inboundOrder.OrderStatus = InOrderStatusEnum.入库完成.ObjToInt(); |
| | | _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder); |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | //反拣回库单 |
| | | public WebResponseContent ReceiveReturnOrder(List<HouseReturnOrder> houseReturnOrder) |
| | | { |
| | | try |
| | |
| | | Random random = new Random(); |
| | | List<Dt_ReturnOrder> returnOrders = new List<Dt_ReturnOrder>(); |
| | | _unitOfWorkManage.BeginTran(); |
| | | foreach(var item in houseReturnOrder) |
| | | foreach (var item in houseReturnOrder) |
| | | { |
| | | int randomNum = random.Next(1, 1000); |
| | | string datePart = DateTime.Now.ToString("yyyyMMdd"); |
| | | Dt_ReturnOrder returnOrder = _returnOrderRepository.QueryFirst(x => x.LPNNo == item.LPNNo && x.OrderStatus == InOrderStatusEnum.未开始.ObjToInt()); |
| | | if(returnOrder == null) |
| | | if (returnOrder == null) |
| | | { |
| | | Dt_ReturnOrder newReturnOrder = new Dt_ReturnOrder |
| | | { |
| | |
| | | if (stockInfo == null) |
| | | { |
| | | Dt_Warehouse warehouse = _warehouseService.Repository.QueryData(x => x.WarehouseCode == item.WarehouseCode).FirstOrDefault(); |
| | | if(warehouse == null) |
| | | if (warehouse == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"该仓库编号{item.WarehouseCode}未配置"); |
| | | } |
| | |
| | | Materialweight = 0, |
| | | Wlstatus = (int)InventoryMaterialStatus.合格, |
| | | Mgeneratetime = DateTime.Now, |
| | | Details = new List<Dt_StockInfoDetail> { stockInfoDetail} |
| | | Details = new List<Dt_StockInfoDetail> { stockInfoDetail } |
| | | }; |
| | | Db.InsertNav(stockInfo1).Include(x => x.Details).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | outboundOrderDetail = new Dt_OutboundOrderDetail |
| | | outboundOrderDetail = new Dt_OutboundOrderDetail |
| | | { |
| | | MaterielCode = item.MaterielCode, |
| | | MaterielName = item.MaterielName, |
| | | MaterieSpec = item.MaterieSpec, |
| | | BatchNo = item.BatchNo, |
| | | OrderQuantity = stockInfo.Details.Sum(x=>x.StockQuantity), |
| | | OrderQuantity = stockInfo.Details.Sum(x => x.StockQuantity), |
| | | Remark = item.Remark, |
| | | LinId = item.LinId, |
| | | LPNNo = item.LPNNo, |
| | |
| | | CreateDate = DateTime.Now, |
| | | LocationName = item.LocationCode |
| | | }; |
| | | outboundOrder = new Dt_OutboundOrder |
| | | outboundOrder = new Dt_OutboundOrder |
| | | { |
| | | OrderNo = "FJCK" + $"{datePart}{randomNum}", |
| | | UpperOrderNo = "WMSFJCK" + $"{datePart}{randomNum}", |
| | |
| | | CreateDate = DateTime.Now, |
| | | CreateType = OrderCreateTypeEnum.UpperSystemPush.ObjToInt(), |
| | | Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail } |
| | | }; |
| | | }; |
| | | Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | } |
| | | |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | returnOrder.ReceiptQuantity += item.OrderQuantity; |
| | | _returnOrderRepository.UpdateData(returnOrder); |
| | | _stockRepository.StockInfoRepository.UpdateData(stockInfo); |
| | | |
| | | |
| | | } |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch(Exception ex) |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | |
| | | List<string> materielCodes = materielInfos.Select(x => x.MaterielCode).Distinct().ToList(); |
| | | return WebResponseContent.Instance.OK("成功", data: materielCodes); |
| | | } |
| | | catch(Exception ex) |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |