| | |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.ERP; |
| | | using WIDESEA_DTO.Stock; |
| | | using WIDESEA_IBasicRepository; |
| | | using WIDESEA_IBasicService; |
| | |
| | | |
| | | namespace WIDESEA_OutboundService |
| | | { |
| | | |
| | | |
| | | public partial class OutboundOrderDetailService : ServiceBase<Dt_OutboundOrderDetail, IOutboundOrderDetailRepository>, IOutboundOrderDetailService |
| | | { |
| | | |
| | | public WebResponseContent LockOutboundStock(int orderDetailId) |
| | | { |
| | | Dt_OutboundOrderDetail outboundOrderDetail = BaseDal.QueryFirst(x => x.Id == orderDetailId); |
| | |
| | | } |
| | | Dt_OutboundOrder outboundOrder = _outboundRepository.OutboundOrderRepository.QueryFirst(x => x.Id == outboundOrderDetails.FirstOrDefault().OrderId); |
| | | List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); |
| | | List<Dt_OutboundOrderDetail> groupDetails = outboundOrderDetails.GroupBy(x => new { x.MaterielCode, x.BatchNo }).Select(x => new Dt_OutboundOrderDetail { OrderQuantity = x.Sum(v => v.OrderQuantity) - x.Sum(v => v.LockQuantity), MaterielCode = x.Key.MaterielCode, BatchNo = x.Key.BatchNo }).ToList(); |
| | | List<Dt_Warehouse> warehouse = _basicService.WarehouseService.Repository.QueryData(x => x.WarehouseDes == outboundOrder.OutWareHouse); |
| | | List<Dt_OutboundOrderDetail> groupDetails = outboundOrderDetails.GroupBy(x => new { x.MaterielCode, x.BatchNo , x.LocationName}).Select(x => new Dt_OutboundOrderDetail { OrderQuantity = x.Sum(v => v.OrderQuantity) - x.Sum(v => v.LockQuantity), MaterielCode = x.Key.MaterielCode, BatchNo = x.Key.BatchNo,LocationName = x.Key.LocationName}).ToList(); |
| | | List<Dt_Warehouse> warehouse = new List<Dt_Warehouse>(); |
| | | if (outboundOrder.OutWareHouse == "SC01_BC") |
| | | { |
| | | warehouse = _basicService.WarehouseService.Repository.QueryData(x => x.WarehouseDes == outboundOrder.OutWareHouse || x.WarehouseDes =="SC02_BC"); |
| | | } |
| | | else |
| | | { |
| | | warehouse = _basicService.WarehouseService.Repository.QueryData(x => x.WarehouseDes == outboundOrder.OutWareHouse); |
| | | } |
| | | List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); |
| | | List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); |
| | | foreach (var item in groupDetails) |
| | |
| | | |
| | | decimal needQuantity = originalNeedQuantity; |
| | | |
| | | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, warehouse); |
| | | List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>(); |
| | | ///åºåºæå®åºä½åºåºå¤æ |
| | | if (item.LocationName != null && item.LocationName != "") |
| | | { |
| | | stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, warehouse).Where(x=>x.LocationCode == item.LocationName).ToList(); |
| | | } |
| | | else |
| | | { |
| | | stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, warehouse); |
| | | } |
| | | |
| | | if (!stockInfos.Any()) |
| | | { |
| | | throw new Exception($"æªæ¾å°å¯åé
åºå"); |
| | | } |
| | | List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, item.MaterielCode, needQuantity, out decimal residueQuantity); |
| | | List<Dt_StockInfo> autoAssignStocks = new List<Dt_StockInfo>(); |
| | | decimal newResidueQuantity = 0; |
| | | |
| | | item.LockQuantity += needQuantity - residueQuantity; |
| | | autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, item.MaterielCode, needQuantity, out decimal residueQuantity); |
| | | newResidueQuantity = residueQuantity; |
| | | |
| | | item.LockQuantity += needQuantity - newResidueQuantity; |
| | | outStocks.AddRange(autoAssignStocks); |
| | | decimal assignQuantity = needQuantity - residueQuantity; |
| | | decimal assignQuantity = needQuantity - newResidueQuantity; |
| | | |
| | | List<Dt_OutboundOrderDetail> details = outboundOrderDetails.Where(x => !string.IsNullOrEmpty(x.BatchNo) ? x.BatchNo == item.BatchNo : true && x.MaterielCode == item.MaterielCode).ToList(); |
| | | |
| | |
| | | { |
| | | palletAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == item.MaterielCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//åºåºè¯¦æ
å·²åé
æ°é |
| | | } |
| | | decimal palletOutboundQuantity = autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity); |
| | | decimal palletOutboundQuantity = 0; |
| | | if (warehouse.Any(x => x.WarehouseCode.Contains("DW")) || warehouse.Any(x => x.WarehouseCode.Contains("YS"))) |
| | | { |
| | | palletOutboundQuantity = autoAssignStocks[j].Details.Where(x => x.BatchNo == item.BatchNo).Sum(x => x.OutboundQuantity); |
| | | |
| | | } |
| | | else |
| | | { |
| | | palletOutboundQuantity = autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity); |
| | | |
| | | } |
| | | if (palletAssignQuantity < palletOutboundQuantity)//妿åºåºè¯¦æ
å·²åé
æ°éå°äºæçå·²åé
æ°éï¼åå¯ä»¥ç»§ç»æ·»å 该æçåºåºä¿¡æ¯ |
| | | { |
| | | decimal orderDetailNeedQuantity = details[i].OrderQuantity - detailAssignQuantity; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList())); |
| | | } |
| | | |
| | | return (outStocks, outboundOrderDetails, outStockLockInfos, locationInfos); |
| | | } |
| | | |
| | | private (bool, string) CheckSelectStockDeital(Dt_OutboundOrderDetail outboundOrderDetail, List<StockSelectViewDTO> stockSelectViews) |
| | | { |
| | | if (outboundOrderDetail == null) |
| | |
| | | } |
| | | return (true, "æå"); |
| | | } |
| | | |
| | | |
| | | public string ToCancelOutFeedbackERP = WIDESEA_Core.Helper.AppSettings.Configuration["CancelOutFeedbackERP"]; |
| | | public WebResponseContent CancelOutFeedbackERP(int[] keys) |
| | | { |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = _outboundRepository.OutboundOrderDetailRepository.QueryData(x => keys.Contains(x.Id)); |
| | | |
| | | if (outboundOrderDetails == null || outboundOrderDetails.Count == 0) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°åºåºåæç»ä¿¡æ¯"); |
| | | } |
| | | if (outboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus > OrderDetailStatusEnum.New.ObjToInt() && x.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) != null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æéåºåºåæç»åå¨åºåºä¸æå·²å®æ"); |
| | | } |
| | | Dt_OutboundOrder outboundOrder = _outboundRepository.OutboundOrderRepository.QueryFirst(x => x.Id == outboundOrderDetails[0].OrderId); |
| | | if(outboundOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªéè¿è¯¥æç»æ¾å°åºåºåä¿¡æ¯"); |
| | | } |
| | | if (!outboundOrder.System.Equals("ERP")) |
| | | { |
| | | return WebResponseContent.Instance.Error("该åºåºåæ®éERPæ¨éï¼æ æ³åæ¶"); |
| | | } |
| | | string ids =""; |
| | | try |
| | | { |
| | | foreach (var item in outboundOrderDetails) |
| | | { |
| | | ids = item.LinId; |
| | | var postContent = new MultipartFormDataContent(); |
| | | postContent.Add(new StringContent(ids), "ids"); |
| | | string result = string.Empty; |
| | | HttpClient client = null; |
| | | using (client = new HttpClient()) |
| | | { |
| | | // 2. åéè¯·æ± |
| | | string url = $"{ToCancelOutFeedbackERP}?ids={Uri.EscapeDataString(ids)}"; |
| | | var response = HttpHelper.Post<WebResponseContent>(url, "åºåºæç»åæ¶åä¼ ERP"); |
| | | |
| | | if (response.Code !=0) |
| | | { |
| | | throw new Exception($"æä½å¤±è´¥: {response.msg ?? "æªæä¾é误信æ¯"}"); |
| | | } |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | _outboundRepository.OutboundOrderDetailRepository.DeleteAndMoveIntoHty(outboundOrderDetails, OperateType.äººå·¥åæ¶); |
| | | |
| | | //æ£æ¥è¯¥ä¸»è®¢åæ¯å¦è¿æå©ä½æç» |
| | | int remainingDetailsCount = _outboundRepository.OutboundOrderDetailRepository |
| | | .Db.Queryable<Dt_OutboundOrderDetail>() |
| | | .Where(d => d.OrderId == outboundOrder.Id) |
| | | .Count(); |
| | | |
| | | // å¦ææ²¡æå©ä½æç»ï¼åå é¤ä¸»è®¢å |
| | | if (remainingDetailsCount == 0) |
| | | { |
| | | _outboundRepository.OutboundOrderRepository.DeleteAndMoveIntoHty(outboundOrder, OperateType.äººå·¥åæ¶); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | // å设ERPè¿åæåæ¶è¿åæåååº |
| | | return WebResponseContent.Instance.OK(); |
| | | |
| | | } |
| | | catch (HttpRequestException ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | // å¤çHTTP请æ±ç¸å
³å¼å¸¸ |
| | | return WebResponseContent.Instance.Error($"HTTP请æ±é误: {ex.Message}"); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | // å¤çå
¶ä»å¼å¸¸ |
| | | return WebResponseContent.Instance.Error($"å¤ç失败: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |