| | |
| | | using WIDESEA_Common.CommonEnum; |
| | | using WIDESEA_Common.TaskEnum; |
| | | using WIDESEA_IBasicService; |
| | | using static HslCommunication.Profinet.Knx.KnxCode; |
| | | using System.Collections; |
| | | using WIDESEA_Common.AllocateEnum; |
| | | using WIDESEA_Model.Models.Basic; |
| | | using WIDESEA_IOutboundService; |
| | | using WIDESEA_DTO.CalcOut; |
| | | using Newtonsoft.Json.Serialization; |
| | | using Newtonsoft.Json; |
| | | using WIDESEA_DTO.Basic; |
| | | |
| | | namespace WIDESEA_InboundService |
| | | { |
| | |
| | | private readonly IRepository<Dt_TakeStockOrderDetail> _takeStockOrderDetail; |
| | | private readonly IRepository<Dt_Task> _taskRepository; |
| | | private readonly ILocationInfoService _locationInfoService; |
| | | public TakeStockOrderService(IRepository<Dt_TakeStockOrder> BaseDal, IUnitOfWorkManage unitOfWorkManage,IRepository<Dt_TakeStockOrder> takeStockOrder,IRepository<Dt_StockInfo> stockInfoRepository,IRepository<Dt_TakeStockOrderDetail> takeStockOrderDetail,IRepository<Dt_Task> taskRepository,ILocationInfoService locationInfoService) : base(BaseDal) |
| | | private readonly IRepository<Dt_InboundOrder> _inboundOrderRepository; |
| | | private readonly IRepository<Dt_OutboundOrder> _outboundOrderRepository; |
| | | private readonly IRepository<Dt_InboundOrderDetail> _inboundOrderDetailRepository; |
| | | private readonly IRepository<Dt_OutboundOrderDetail> _outboundOrderDetailRepository; |
| | | private readonly IOutboundPickingService _outboundPickingService; |
| | | private readonly IRepository<Dt_StockInfoDetail> _stockInfoDetailRepository; |
| | | private readonly IOutboundService _outboundService; |
| | | private readonly IFeedbackMesService _feedbackMesService; |
| | | private readonly IESSApiService _eSSApiService; |
| | | public TakeStockOrderService(IRepository<Dt_TakeStockOrder> BaseDal, IUnitOfWorkManage unitOfWorkManage,IRepository<Dt_TakeStockOrder> takeStockOrder,IRepository<Dt_StockInfo> stockInfoRepository,IRepository<Dt_TakeStockOrderDetail> takeStockOrderDetail,IRepository<Dt_Task> taskRepository,ILocationInfoService locationInfoService, IRepository<Dt_InboundOrder> inboundOrderRepository,IRepository<Dt_OutboundOrder> outboundOrderRepository,IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_OutboundOrderDetail> outboundOrderDetailRepository, IOutboundPickingService outboundPickingService, IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IOutboundService outboundService,IFeedbackMesService feedbackMesService,IESSApiService eSSApiService) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _takeStockOrder = takeStockOrder; |
| | |
| | | _takeStockOrderDetail = takeStockOrderDetail; |
| | | _taskRepository = taskRepository; |
| | | _locationInfoService = locationInfoService; |
| | | _inboundOrderRepository = inboundOrderRepository; |
| | | _outboundOrderRepository = outboundOrderRepository; |
| | | _inboundOrderDetailRepository = inboundOrderDetailRepository; |
| | | _outboundOrderDetailRepository = outboundOrderDetailRepository; |
| | | _outboundPickingService = outboundPickingService; |
| | | _stockInfoDetailRepository = stockInfoDetailRepository; |
| | | _outboundService = outboundService; |
| | | _feedbackMesService = feedbackMesService; |
| | | _eSSApiService = eSSApiService; |
| | | } |
| | | |
| | | private Dictionary<string, string> stations = new Dictionary<string, string> |
| | | { |
| | | {"2-1","2-9" }, |
| | | {"3-1","3-9" }, |
| | | }; |
| | | |
| | | private Dictionary<string, string> movestations = new Dictionary<string, string> |
| | | { |
| | | {"2-1","2-5" }, |
| | | {"3-1","3-5" }, |
| | | }; |
| | | public WebResponseContent ValidateBoxNo(string orderNo, string boxNo) |
| | | { |
| | | try |
| | |
| | | if (stockInfo == null) { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°è¯¥æçåºå"); |
| | | } |
| | | if(stockInfo.StockStatus != StockStatusEmun.çç¹åºåºå®æ.ObjToInt()) |
| | | if(stockInfo.StockStatus != StockStatusEmun.çç¹åºåºå®æ.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.çç¹åºå宿.ObjToInt()) |
| | | { |
| | | return WebResponseContent.Instance.Error("该æçå¤äºéçç¹ç¶æï¼è¯·æ£æ¥çç¹ä»»å¡"); |
| | | } |
| | | Dt_TakeStockOrder takeStockOrder = _takeStockOrder.QueryFirst(x=>x.OrderNo == orderNo); |
| | | Dt_TakeStockOrder takeStockOrder = _takeStockOrder.QueryFirst(x=>x.AllPalletCode.Contains(boxNo)&& x.TakeStockStatus == TakeStockStatusEnum.çç¹ä¸.ObjToInt()); |
| | | if (takeStockOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°è¯¥çç¹åæ®"); |
| | | return WebResponseContent.Instance.Error("该æçæªæ¾å°è¯¥çç¹åæ®"); |
| | | } |
| | | if (takeStockOrder.AllPalletCode.Contains(",")) |
| | | { |
| | |
| | | bool isMatch = remarkValues.Any(val => val.Equals(boxNo, StringComparison.OrdinalIgnoreCase)); |
| | | if (!isMatch) |
| | | { |
| | | return WebResponseContent.Instance.Error($"ç®±å·ã{boxNo}ãæªå¨çç¹åç®±å·ã{takeStockOrder.Remark}ã䏿¾å°å¹é
项"); |
| | | return WebResponseContent.Instance.Error($"ç®±å·ã{boxNo}ãæªå¨çç¹åç®±å·ã{takeStockOrder.AllPalletCode}ã䏿¾å°å¹é
项"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | bool isMatch = takeStockOrder.Remark.Trim().Equals(boxNo, StringComparison.OrdinalIgnoreCase); |
| | | if (!isMatch) |
| | | { |
| | | return WebResponseContent.Instance.Error($"ç®±å·ã{boxNo}ãä¸çç¹åç®±å·ã{takeStockOrder.Remark}ãä¸å¹é
"); |
| | | } |
| | | } |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | var resultData = new { takeStockOrder = takeStockOrder.OrderNo }; |
| | | return WebResponseContent.Instance.OK(data:resultData); |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | |
| | | { |
| | | TakeStockId = takeStockOrder.Id, |
| | | MaterielCode = stockInfoDetail.MaterielCode, |
| | | MaterielName = stockInfoDetail.MaterielName??"", |
| | | MaterielName = stockInfoDetail.MaterielName ?? "", |
| | | BatchNo = stockInfoDetail.BatchNo, |
| | | TakePalletCode = completeStockTakeDTO.boxNo, |
| | | TakeDetalStatus = TakeStockDetailStatusEnum.çç¹å®æ.ObjToInt(), |
| | | TakeDetalStatus = TakeStockDetailStatusEnum.æªè¿è¡å¹³è´¦å¤ç.ObjToInt(), |
| | | Unit = stockInfoDetail.Unit, |
| | | SysQty = completeStockTakeDTO.stockQuantity, |
| | | Qty =completeStockTakeDTO.actualQuantity, |
| | | Remark = completeStockTakeDTO.stockQuantity-completeStockTakeDTO.actualQuantity>=0 ?"çäº":"çç", |
| | | Qty = completeStockTakeDTO.actualQuantity, |
| | | Remark = "çäº", |
| | | barcode = completeStockTakeDTO.barcode, |
| | | WarehouseCode = stockInfoDetail.WarehouseCode??"", |
| | | WarehouseCode = stockInfoDetail.WarehouseCode ?? "", |
| | | FactoryArea = stockInfoDetail.FactoryArea, |
| | | SupplyCode = stockInfoDetail.SupplyCode??"", |
| | | SupplyCode = stockInfoDetail.SupplyCode ?? "", |
| | | TakeStockNo = takeStockOrder.OrderNo, |
| | | DifferenceQty = completeStockTakeDTO.actualQuantity - completeStockTakeDTO.stockQuantity |
| | | |
| | | }; |
| | | stockInfoDetail.StockId = 0; |
| | | stockInfoDetail.OrderNo = takeStockOrder.OrderNo; |
| | | stockInfo.StockStatus = StockStatusEmun.çç¹åºå宿.ObjToInt(); |
| | | _unitOfWorkManage.BeginTran(); |
| | | _takeStockOrderDetail.AddData(takeStockOrderDetail); |
| | | _stockInfoDetailRepository.UpdateData(stockInfoDetail); |
| | | _stockInfoRepository.UpdateData(stockInfo); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | return WebResponseContent.Instance.OK("çç¹å®æï¼è¯·å走该å¼å¸¸æç®±è¿è¡å¹³è´¦å¤çï¼"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent ReturnBox(string orderNo, string boxNo) |
| | | public WebResponseContent ReturnBox(string orderNo, string boxNo, string sourceAddress) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | |
| | | { |
| | | return content.Error("æªæ¾å°è¯¥çç¹åæ®"); |
| | | } |
| | | var stock = _stockInfoRepository.QueryFirst(x => x.PalletCode == boxNo); |
| | | var stock = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == boxNo).Includes(x=>x.Details).First(); |
| | | |
| | | if (stock == null) |
| | | { |
| | |
| | | } |
| | | |
| | | var task = _taskRepository.QueryFirst(x => x.PalletCode == boxNo); |
| | | |
| | | |
| | | if (task != null) |
| | | { |
| | | return content.Error($"æç{boxNo}åå¨ä»»å¡ååºå¤±è´¥!"); |
| | | return content.Error($"æç{boxNo}åå¨ä»»å¡ï¼ååºå¤±è´¥!"); |
| | | } |
| | | if(stock.StockStatus != StockStatusEmun.çç¹åºåºå®æ.ObjToInt()) |
| | | if(stock.StockStatus != StockStatusEmun.çç¹åºåºå®æ.ObjToInt() && stock.StockStatus != StockStatusEmun.çç¹åºå宿.ObjToInt()) |
| | | { |
| | | return content.Error("该æçç¶æä¸å¯¹,ä¸å
许çç¹å
¥åº"); |
| | | } |
| | | stock.StockStatus = StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt(); |
| | | var palletCodes = new HashSet<string>(StringComparer.OrdinalIgnoreCase); |
| | | if (!string.IsNullOrEmpty(takeStockOrder.AllPalletCode)) |
| | | { |
| | | palletCodes = takeStockOrder.AllPalletCode |
| | | .Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries) |
| | | .Select(p => p.Trim()) |
| | | .ToHashSet(StringComparer.OrdinalIgnoreCase); |
| | | } |
| | | int overPalletCodeCount = _stockInfoRepository.QueryData(x => palletCodes.Contains(x.PalletCode) && (x.StockStatus == StockStatusEmun.åºåºå®æ.ObjToInt() || x.StockStatus == StockStatusEmun.å
¥åºå®æ.ObjToInt() || x.StockStatus == StockStatusEmun.åºåºéå®.ObjToInt()|| x.StockStatus == StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt())).Count(); |
| | | bool hasRelatedTasks = palletCodes.Count == overPalletCodeCount + 1; |
| | | |
| | | takeStockOrder.TakeStockStatus = TakeStockStatusEnum.çç¹å®æ.ObjToInt(); |
| | | if (hasRelatedTasks) |
| | | { |
| | | takeStockOrder.TakeStockStatus = (int)TakeStockStatusEnum.çç¹å®æ; |
| | | } |
| | | stock.StockStatus = StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt(); |
| | | // åé
æ°è´§ä½ |
| | | var newLocation = _locationInfoService.AssignLocation(stock.LocationType); |
| | | |
| | | if (newLocation == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("没æç©ºé²åºä½å¯ååº"); |
| | | } |
| | | |
| | | var newTask = new Dt_Task() |
| | | { |
| | |
| | | NextAddress = "", |
| | | OrderNo = takeStockOrder.OrderNo, |
| | | Roadway = newLocation.RoadwayNo, |
| | | SourceAddress = takeStockOrder.Remark, |
| | | SourceAddress = stations.GetValueOrDefault(sourceAddress)??"", |
| | | TargetAddress = newLocation.LocationCode, |
| | | TaskStatus = (int)TaskStatusEnum.New, |
| | | TaskType = TaskTypeEnum.InInventory.ObjToInt(), |
| | | PalletType = stock.PalletType, |
| | | WarehouseId = stock.WarehouseId |
| | | }; |
| | | if (stock.Details.Count <= 0) |
| | | { |
| | | stock.PalletType = (int)PalletTypeEnum.Empty; |
| | | newTask.TaskType = TaskTypeEnum.InEmpty.ObjToInt(); |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | _stockInfoRepository.UpdateData(stock); |
| | | _takeStockOrder.UpdateData(takeStockOrder); |
| | | _taskRepository.AddData(newTask); |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | //var moveResult = await _eSSApiService.MoveContainerAsync(new MoveContainerRequest |
| | | //{ |
| | | // slotCode = movestations[station], |
| | | // containerCode = palletCode |
| | | //}); |
| | | var moveResult = _eSSApiService.MoveContainerAsync(new MoveContainerRequest |
| | | { |
| | | slotCode = movestations[sourceAddress], |
| | | containerCode = boxNo |
| | | }); |
| | | return content.OK(); |
| | | |
| | | } |
| | |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent ManualReconciliation(int id) |
| | | { |
| | | try |
| | | { |
| | | Dt_TakeStockOrderDetail takeStockOrderDetail = _takeStockOrderDetail.QueryFirst(x=>x.Id == id); |
| | | if(takeStockOrderDetail == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°è¯¥çç¹å·®å¼è®°å½"); |
| | | } |
| | | else |
| | | { |
| | | if(takeStockOrderDetail.TakeDetalStatus != TakeStockDetailStatusEnum.æªè¿è¡å¹³è´¦å¤ç.ObjToInt()) |
| | | { |
| | | return WebResponseContent.Instance.Error("该记å½å·²ç»è¿è¡äºå¹³è´¦æä½"); |
| | | } |
| | | takeStockOrderDetail.DifferenceQty = 0; |
| | | takeStockOrderDetail.TakeDetalStatus = TakeStockDetailStatusEnum.å·²è¿è¡å¹³è´¦å¤ç.ObjToInt(); |
| | | } |
| | | _takeStockOrderDetail.UpdateData(takeStockOrderDetail); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent SelectOrder(string remark, int id) |
| | | { |
| | | try |
| | | { |
| | | Dt_TakeStockOrderDetail takeStockOrderDetail = _takeStockOrderDetail.QueryFirst(x => x.Id == id); |
| | | if (takeStockOrderDetail == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°è¯¥çç¹å·®å¼è®°å½"); |
| | | } |
| | | else |
| | | { |
| | | //æ¥ææ¶å |
| | | if (takeStockOrderDetail.Remark == "çç") |
| | | { |
| | | List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>(); |
| | | List<Dt_InboundOrder> inboundOrders = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Where(x => x.BusinessType == "12" && x.OrderStatus != InOrderStatusEnum.å
¥åºå®æ.ObjToInt()).Includes(x => x.Details).ToList(); |
| | | foreach (var inboundOrder in inboundOrders) |
| | | { |
| | | |
| | | var matchedDetails = inboundOrder.Details |
| | | |
| | | .Where(detail => !string.IsNullOrEmpty(detail.MaterielCode) |
| | | && detail.MaterielCode == takeStockOrderDetail.MaterielCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt()) |
| | | |
| | | .WhereIF(!string.IsNullOrEmpty(takeStockOrderDetail.FactoryArea), |
| | | detail => !string.IsNullOrEmpty(inboundOrder.FactoryArea) |
| | | && inboundOrder.FactoryArea == takeStockOrderDetail.FactoryArea) |
| | | .WhereIF(!string.IsNullOrEmpty(takeStockOrderDetail.WarehouseCode), |
| | | detail => !string.IsNullOrEmpty(detail.WarehouseCode) |
| | | && detail.WarehouseCode == takeStockOrderDetail.WarehouseCode) |
| | | .WhereIF(!string.IsNullOrEmpty(takeStockOrderDetail.BatchNo), |
| | | detail => !string.IsNullOrEmpty(detail.BatchNo) |
| | | && detail.BatchNo == takeStockOrderDetail.BatchNo) |
| | | |
| | | .ToList(); |
| | | |
| | | // å°å¹é
çæç»æ·»å å°æ»å表 |
| | | if (matchedDetails.Any()) |
| | | { |
| | | inboundOrderDetails.AddRange(matchedDetails); |
| | | } |
| | | } |
| | | return WebResponseContent.Instance.OK("æå",data: inboundOrderDetails); |
| | | } |
| | | else |
| | | { |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>(); |
| | | List<Dt_OutboundOrder> outboundOrders = _outboundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => x.BusinessType == "23" && x.OrderStatus != OutOrderStatusEnum.åºåºå®æ.ObjToInt()).Includes(x => x.Details).ToList(); |
| | | foreach (var outboundOrder in outboundOrders) |
| | | { |
| | | var matchedDetails = outboundOrder.Details |
| | | .Where(detail => !string.IsNullOrWhiteSpace(detail.MaterielCode) |
| | | && detail.MaterielCode == takeStockOrderDetail.MaterielCode && detail.OrderQuantity-detail.MoveQty-detail.OverOutQuantity>0) |
| | | .WhereIF(!string.IsNullOrWhiteSpace(takeStockOrderDetail.FactoryArea), |
| | | detail => !string.IsNullOrWhiteSpace(outboundOrder.FactoryArea) |
| | | && outboundOrder.FactoryArea == takeStockOrderDetail.FactoryArea) |
| | | .WhereIF(!string.IsNullOrWhiteSpace(takeStockOrderDetail.WarehouseCode), |
| | | detail => !string.IsNullOrWhiteSpace(detail.WarehouseCode) |
| | | && detail.WarehouseCode == takeStockOrderDetail.WarehouseCode) |
| | | .Where(detail => string.IsNullOrWhiteSpace(detail.BatchNo)|| |
| | | detail.BatchNo == takeStockOrderDetail.BatchNo) |
| | | |
| | | .Where(detail => string.IsNullOrWhiteSpace(detail.SupplyCode) || |
| | | detail.SupplyCode == takeStockOrderDetail.SupplyCode) |
| | | .ToList(); |
| | | |
| | | if (matchedDetails.Any()) |
| | | { |
| | | outboundOrderDetails.AddRange(matchedDetails); |
| | | } |
| | | } |
| | | return WebResponseContent.Instance.OK("æå", data: outboundOrderDetails); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent DocumentReconciliation(string barcode) |
| | | { |
| | | WebResponseContent webResponseContent = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_TakeStockOrderDetail takeStockOrderDetail = _takeStockOrderDetail.QueryFirst(x => x.barcode == barcode); |
| | | if (takeStockOrderDetail == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°è¯¥çç¹å·®å¼æ°æ®"); |
| | | } |
| | | Dt_OutboundOrderDetail outboundOrderDetail = _outboundOrderDetailRepository.QueryFirst(x => x.Remark == takeStockOrderDetail.TakeStockNo && (x.OrderQuantity-x.LockQuantity-x.MoveQty)>0); |
| | | if (outboundOrderDetail == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°éæ©çæåå¹³è´¦åæ®"); |
| | | } |
| | | if(outboundOrderDetail.MaterielCode != takeStockOrderDetail.MaterielCode) |
| | | { |
| | | return WebResponseContent.Instance.Error("䏿åå¹³è´¦åæ®ç©æç¼ç ä¸å¹é
"); |
| | | } |
| | | if (!string.IsNullOrWhiteSpace(outboundOrderDetail.BatchNo)&& outboundOrderDetail.BatchNo != takeStockOrderDetail.BatchNo) |
| | | { |
| | | return WebResponseContent.Instance.Error("䏿åå¹³è´¦åæ®ç©ææ¹æ¬¡ä¸å¹é
"); |
| | | } |
| | | if (!string.IsNullOrWhiteSpace(outboundOrderDetail.SupplyCode) && outboundOrderDetail.SupplyCode != takeStockOrderDetail.SupplyCode) |
| | | { |
| | | return WebResponseContent.Instance.Error("䏿åå¹³è´¦åæ®ä¾åºåä¸å¹é
"); |
| | | } |
| | | Dt_OutboundOrder outboundOrder = _outboundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == outboundOrderDetail.OrderId).Includes(x => x.Details).First(); |
| | | |
| | | takeStockOrderDetail.TakeDetalStatus = TakeStockDetailStatusEnum.ææ¶æå平账å¤ç.ObjToInt(); |
| | | OutboundCompleteRequestDTO request = new OutboundCompleteRequestDTO() |
| | | { |
| | | OrderNo = outboundOrder.OrderNo, |
| | | PalletCode = takeStockOrderDetail.TakePalletCode, |
| | | Barcode = takeStockOrderDetail.barcode, |
| | | Operator = App.User.UserName |
| | | }; |
| | | webResponseContent = CompleteOutboundWithBarcode(request,outboundOrderDetail.Id); |
| | | takeStockOrderDetail.DifferenceQty = 0; |
| | | _takeStockOrderDetail.UpdateData(takeStockOrderDetail); |
| | | return WebResponseContent.Instance.OK(data: webResponseContent); |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | |
| | | } |
| | | } |
| | | public WebResponseContent CompleteOutboundWithBarcode(OutboundCompleteRequestDTO request ,int orderDetailId) |
| | | { |
| | | WebResponseContent content = WebResponseContent.Instance; |
| | | |
| | | OutboundCompleteResponseDTO response = new(); |
| | | try |
| | | { |
| | | // 1. æ ¹æ®æçå·æ¥æ¾åºåä¿¡æ¯ |
| | | Dt_StockInfo stockInfo = _stockInfoRepository.QueryFirst(x => x.PalletCode == request.PalletCode); |
| | | if (stockInfo == null) |
| | | { |
| | | response.Success = false; |
| | | response.Message = $"æçå· {request.PalletCode} 对åºçåºåä¸åå¨"; |
| | | return WebResponseContent.Instance.Error($"æçå· {request.PalletCode} 对åºçåºåä¸åå¨"); |
| | | } |
| | | |
| | | // 2. æ ¹æ®æ¡ç æ¥æ¾åºåæç» |
| | | Dt_StockInfoDetail stockDetail = _stockInfoDetailRepository.QueryFirst(x => x.Barcode == request.Barcode); |
| | | if (stockDetail == null) |
| | | { |
| | | response.Success = false; |
| | | response.Message = $"æ¡ç {request.Barcode} 对åºçåºåæç»ä¸åå¨"; |
| | | return WebResponseContent.Instance.Error($"æ¡ç {request.Barcode} 对åºçåºåæç»ä¸åå¨"); |
| | | } |
| | | |
| | | |
| | | |
| | | // 4. æ¥æ¾åºåºåä¿¡æ¯ |
| | | Dt_OutboundOrder outboundOrder = _outboundOrderRepository.QueryFirst(o => o.OrderNo == request.OrderNo); |
| | | if (outboundOrder == null) |
| | | { |
| | | response.Success = false; |
| | | response.Message = $"åºåºå {request.OrderNo} ä¸åå¨"; |
| | | return WebResponseContent.Instance.Error($"åºåºå {request.OrderNo} ä¸åå¨"); |
| | | } |
| | | |
| | | Dt_OutboundOrderDetail outboundOrderDetail = _outboundOrderDetailRepository.QueryFirst(x => x.Id == orderDetailId); |
| | | if (outboundOrderDetail == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°åºåºåæç»"); |
| | | } |
| | | // å®é
åºåºé |
| | | decimal actualOutboundQuantity = outboundOrderDetail.OrderQuantity-outboundOrderDetail.LockQuantity-outboundOrderDetail.MoveQty; |
| | | |
| | | |
| | | // 8. 夿æ¯å¦éè¦æå
ï¼å½åºåºæ°éå°äºåºåæ°éæ¶éè¦æå
ï¼ |
| | | bool isUnpacked = actualOutboundQuantity < stockDetail.StockQuantity; |
| | | List<MaterialCodeReturnDTO> returnDTOs = new List<MaterialCodeReturnDTO>(); |
| | | string newBarcode = string.Empty; |
| | | // 9. å¼å¯äºå¡ |
| | | _unitOfWorkManage.BeginTran(); |
| | | try |
| | | { |
| | | decimal beforeQuantity = stockDetail.StockQuantity; // åå§åºåé |
| | | |
| | | Dt_AllocateMaterialInfo allocateMaterialInfo = new Dt_AllocateMaterialInfo(); |
| | | |
| | | // æ ¹æ®æ¯å¦æå
æ§è¡ä¸åçæä½ |
| | | if (isUnpacked) |
| | | { |
| | | (string NewBarcode, List<MaterialCodeReturnDTO> MaterialCodeReturnDTOs) result = _outboundService.PerformUnpackOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, 0, outboundOrder.Id, outboundOrder.OrderNo); |
| | | |
| | | returnDTOs = result.MaterialCodeReturnDTOs; |
| | | newBarcode = result.NewBarcode; |
| | | |
| | | MaterialCodeReturnDTO returnDTO = returnDTOs.First(x => x.Barcode == newBarcode); |
| | | |
| | | if (outboundOrder.OrderType != 0) |
| | | { |
| | | allocateMaterialInfo = new Dt_AllocateMaterialInfo() |
| | | { |
| | | Barcode = returnDTO.Barcode, |
| | | BatchNo = returnDTO.BatchNo, |
| | | FactoryArea = returnDTO.FactoryArea, |
| | | MaterialCode = returnDTO.MaterialCode, |
| | | MaterialName = returnDTO.MaterialName, |
| | | OrderId = outboundOrder.Id, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | Quantity = returnDTO.Quantity, |
| | | SupplyCode = returnDTO.SuplierCode, |
| | | Unit = stockDetail.Unit |
| | | }; |
| | | } |
| | | |
| | | } |
| | | else |
| | | { |
| | | _outboundService.PerformFullOutboundOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, 0); |
| | | |
| | | if (outboundOrder.OrderType != 0) |
| | | { |
| | | allocateMaterialInfo = new Dt_AllocateMaterialInfo() |
| | | { |
| | | Barcode = stockDetail.Barcode, |
| | | BatchNo = stockDetail.BatchNo, |
| | | FactoryArea = stockDetail.FactoryArea, |
| | | MaterialCode = stockDetail.MaterielCode, |
| | | MaterialName = stockDetail.MaterielName, |
| | | OrderId = outboundOrder.Id, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | Quantity = stockDetail.StockQuantity, |
| | | SupplyCode = stockDetail.SupplyCode, |
| | | Unit = stockDetail.Unit |
| | | }; |
| | | } |
| | | |
| | | } |
| | | |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>(); |
| | | |
| | | outboundOrderDetails.Add(outboundOrderDetail); |
| | | |
| | | decimal allocatedQuantity = actualOutboundQuantity; |
| | | List<Dt_OutboundOrderDetail> updateDetails = new(); |
| | | foreach (var item in outboundOrderDetails) |
| | | { |
| | | if (allocatedQuantity <= 0) break; |
| | | |
| | | decimal barcodeQuantity = allocatedQuantity; |
| | | |
| | | if (item.LockQuantity - item.OverOutQuantity >= allocatedQuantity) |
| | | { |
| | | item.OverOutQuantity += allocatedQuantity; |
| | | item.CurrentDeliveryQty += allocatedQuantity; |
| | | allocatedQuantity = 0; |
| | | } |
| | | else |
| | | { |
| | | barcodeQuantity = allocatedQuantity; |
| | | allocatedQuantity -= (item.LockQuantity - item.OverOutQuantity); |
| | | item.OverOutQuantity = allocatedQuantity; |
| | | item.LockQuantity = allocatedQuantity; |
| | | item.CurrentDeliveryQty = allocatedQuantity; |
| | | } |
| | | |
| | | updateDetails.Add(item); |
| | | |
| | | List<Barcodes> barcodesList = new List<Barcodes>(); |
| | | Barcodes barcodes = new Barcodes |
| | | { |
| | | Barcode = isUnpacked ? newBarcode : stockDetail?.Barcode, |
| | | Qty = barcodeQuantity, |
| | | SupplyCode = stockDetail?.SupplyCode ?? "", |
| | | BatchNo = stockDetail?.BatchNo ?? "", |
| | | Unit = stockDetail?.Unit ?? "" |
| | | }; |
| | | if (!string.IsNullOrEmpty(item.ReturnJsonData)) |
| | | { |
| | | barcodesList = JsonConvert.DeserializeObject<List<Barcodes>>(item.ReturnJsonData) ?? new List<Barcodes>(); |
| | | } |
| | | barcodesList.Add(barcodes); |
| | | JsonSerializerSettings settings = new JsonSerializerSettings |
| | | { |
| | | ContractResolver = new CamelCasePropertyNamesContractResolver() |
| | | }; |
| | | item.ReturnJsonData = JsonConvert.SerializeObject(barcodesList, settings); |
| | | } |
| | | |
| | | // æ´æ°åºåºåæç»çå·²åºåºæ°é |
| | | _outboundOrderDetailRepository.UpdateData(updateDetails); |
| | | |
| | | // æ´æ°éå®è®°å½ç累计已åºåºæ°éï¼éè¦æ´æ°è¯¥æçè¯¥ç©æçææç¸å
³è®°å½ï¼ |
| | | //UpdateLockInfoAllocatedQuantity(stockInfo.Id, stockDetail.MaterielCode, stockDetail.BatchNo, actualOutboundQuantity); |
| | | |
| | | // æäº¤äºå¡ |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | // æå»ºè¿åä¿¡æ¯ |
| | | ScannedStockDetailDTO scannedDetail = new ScannedStockDetailDTO |
| | | { |
| | | StockDetailId = stockDetail.Id, |
| | | PalletCode = stockInfo.PalletCode, |
| | | MaterielCode = stockDetail.MaterielCode, |
| | | MaterielName = stockDetail.MaterielName, |
| | | BatchNo = stockDetail.BatchNo, |
| | | OriginalBarcode = request.Barcode, |
| | | BeforeQuantity = beforeQuantity, |
| | | AfterQuantity = isUnpacked ? actualOutboundQuantity : 0, |
| | | ChangeQuantity = -actualOutboundQuantity, |
| | | IsUnpacked = isUnpacked, |
| | | MaterialCodes = returnDTOs |
| | | }; |
| | | |
| | | response.Success = true; |
| | | response.Message = "åºåºå®æ"; |
| | | response.ScannedDetail = scannedDetail; |
| | | response.UpdatedDetails = updateDetails; |
| | | |
| | | if (!string.IsNullOrEmpty(newBarcode)) |
| | | { |
| | | // ç©ææ°æ¡ç åä¼ |
| | | _feedbackMesService.BarcodeFeedback(newBarcode); |
| | | } |
| | | List<Dt_OutboundOrderDetail> details = _outboundOrderDetailRepository.QueryData(x => x.OrderId == outboundOrder.Id); |
| | | if(details.All(x => x.OverOutQuantity >= x.OrderQuantity - x.MoveQty)) |
| | | { |
| | | _feedbackMesService.OutboundFeedback(outboundOrder.OrderNo); |
| | | outboundOrder.OrderStatus = OutOrderStatusEnum.åºåºå®æ.ObjToInt(); |
| | | _outboundOrderRepository.UpdateData(outboundOrder); |
| | | } |
| | | |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | response.Success = false; |
| | | response.Message = $"åºåºå¤ç失败ï¼{ex.Message}"; |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | |
| | | content = WebResponseContent.Instance.OK(data: response); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error("å¤çåºåºå®æå¤±è´¥ï¼" + ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public WebResponseContent StockTakeGroupPallet(string barcode, string boxNo) |
| | | { |
| | | throw new NotImplementedException(); |
| | | } |
| | | } |
| | | |
| | | } |