| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common.LocationEnum; |
| | | using WIDESEA_Common.OrderEnum; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | |
| | | using WIDESEA_IRecordService; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_OutboundRepository; |
| | | |
| | | namespace WIDESEA_OutboundService |
| | | { |
| | |
| | | { |
| | | try |
| | | { |
| | | //æ´æ°åºå屿§ |
| | | _stockInfoService.ProStockInfoService.Repository.UpdateData(proStockInfos); |
| | | List<Dt_ProStockInfoDetail> proStockInfoDetails = new List<Dt_ProStockInfoDetail>(); |
| | | foreach (var item in proStockInfos) |
| | | { |
| | | proStockInfoDetails.AddRange(item.proStockInfoDetails); |
| | | } |
| | | //æ´æ°åºåæç» |
| | | proStockInfoDetails.ForEach(x => x.ProOutDetailStatus = StockStatusEmun.åºåºéå®.ObjToInt()); |
| | | _stockInfoService.ProStockInfoDetailService.Repository.UpdateData(proStockInfoDetails); |
| | | Dt_ProOutOrder proOutOrder = _proOutOrderRepository.QueryFirst(x => x.Id == proOutOrderDetails.FirstOrDefault().ProOrderId); |
| | | if (proOutOrder.ProOrderStatus == OutOrderStatusEnum.æªå¼å§.ObjToInt()) |
| | | { |
| | | proOutOrder.ProOrderStatus = OutOrderStatusEnum.åºåºä¸.ObjToInt(); |
| | | _proOutOrderRepository.UpdateData(proOutOrder); |
| | | } |
| | | BaseDal.UpdateData(proOutOrderDetails); |
| | | |
| | | List<Dt_OutProStockInfo> addOutStockLockInfos = outProStockInfos.Where(x => x.Id == 0).ToList(); |
| | |
| | | { |
| | | throw new Exception("æªæ¾å°æå订å"); |
| | | } |
| | | List<Dt_ProOutOrderDetail> groupDetails = proOutOrderDetails.GroupBy(x => new { x.SaleOrder, x.PCode, x.PVer, x.PLot, x.DateCode }).Select(x => new Dt_ProOutOrderDetail() |
| | | { |
| | | QtyPcs = x.Sum(x => x.QtyPcs) - x.Sum(x => x.OverQtyPcs), |
| | | SaleOrder = x.Key.SaleOrder, |
| | | PCode = x.Key.PCode, |
| | | PVer = x.Key.PVer, |
| | | PLot = x.Key.PLot, |
| | | DateCode = x.Key.DateCode, |
| | | }).ToList(); |
| | | foreach (var item in groupDetails) |
| | | foreach (var item in proOutOrderDetails) |
| | | { |
| | | float needQty = item.QtyPcs; |
| | | //æ¥æ¾å¯ç¨åºå |
| | |
| | | //è·ååºåºåºå |
| | | List<Dt_ProStockInfo> assignOutStocks = _stockInfoService.ProStockInfoService.GetOutboundStocks(stockInfoss, item, needQty, out float residueQuantity); |
| | | item.LockQtyPcs += needQty - residueQuantity; |
| | | outStocks.AddRange(assignOutStocks); |
| | | float assignQuantity = needQty - residueQuantity; |
| | | bool isCanLot = !string.IsNullOrEmpty(item.PLot); |
| | | bool isCanDate = !string.IsNullOrEmpty(item.DateCode); |
| | | List<Dt_ProOutOrderDetail> details = proOutOrderDetails |
| | | .Where(x => x.SaleOrder == item.SaleOrder && x.PCode == item.PCode && x.PVer == item.PVer |
| | | && (isCanLot ? x.PLot == item.PLot : true) |
| | | && (isCanDate ? x.DateCode == item.DateCode : true)) |
| | | .ToList(); |
| | | |
| | | for (int i = 0; i < details.Count; i++) |
| | | if (item.QtyPcs > item.LockQtyPcs) |
| | | { |
| | | float orderQuantity = details[i].QtyPcs; |
| | | for (int j = 0; j < assignOutStocks.Count; j++) |
| | | throw new Exception($"产åç¼ç {item.PCode},çæ¬{item.PVer.Substring(0, 1)}å¯åé
æ°éä¸è¶³,å¯ç¨æ°é{item.LockQtyPcs}"); |
| | | } |
| | | outStocks.AddRange(assignOutStocks); |
| | | //åé
åºåºçPCSæ°é |
| | | float assignQuantity = needQty; |
| | | //订åæç»çåºåºPCSæ°é |
| | | float orderQuantity = item.QtyPcs; |
| | | for (int j = 0; j < assignOutStocks.Count; j++) |
| | | { |
| | | //åºåºè®¢åæç»å·²åé
æ°é |
| | | float detailAssignQuantity = outProStockInfos.Where(x => x.OrderDetailId == item.Id).Sum(x => x.AssignQuantity); |
| | | |
| | | |
| | | float orderDetailNeedQuantity = item.QtyPcs - detailAssignQuantity; |
| | | //çæåºåºè¯¦æ
|
| | | if (orderDetailNeedQuantity > assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity)) |
| | | { |
| | | float detailAssignQuantity = outProStockInfos.Where(x => x.SaleOrder == item.SaleOrder && x.PCode == item.PCode && x.PVer == item.PVer |
| | | && (item.PLot.IsNotEmptyOrNull() ? x.PLot == item.PLot : false) |
| | | && (item.DateCode.IsNotEmptyOrNull() ? x.DateCode == item.PLot : false) |
| | | && x.OrderDetailId == details[i].Id).Sum(x => x.AssignQuantity);//åºåºè®¢åæç»å·²åé
æ°é |
| | | |
| | | float palletAssignQuantity = outProStockInfos.Where(x => x.SaleOrder == item.SaleOrder && x.PCode == item.PCode && x.PVer == item.PVer |
| | | && (item.PLot.IsNotEmptyOrNull() ? x.PLot == item.PLot : false) |
| | | && (item.DateCode.IsNotEmptyOrNull() ? x.DateCode == item.PLot : false |
| | | && x.PalletCode == assignOutStocks[j].PalletCode)).Sum(x => x.AssignQuantity); |
| | | //åºåºè¯¦æ
å·²åé
æ°é |
| | | palletAssignQuantity = outProStockInfos.Where(x => x.SaleOrder == item.SaleOrder && x.PCode == item.PCode && x.PVer == item.PVer |
| | | && (item.PLot.IsNotEmptyOrNull() ? x.PLot == item.PLot : false) |
| | | && (item.DateCode.IsNotEmptyOrNull() ? x.DateCode == item.PLot : false && x.PalletCode == assignOutStocks[j].PalletCode)).Sum(x => x.AssignQuantity);//åºåºè¯¦æ
å·²åé
æ°é |
| | | float palletOutboundQuantity = assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity); |
| | | if (palletAssignQuantity < palletOutboundQuantity)//妿åºåºè¯¦æ
å·²åé
æ°éå°äºæçå·²åé
æ°éï¼åå¯ä»¥ç»§ç»æ·»å 该æçåºåºä¿¡æ¯ |
| | | { |
| | | float orderDetailNeedQuantity = details[i].QtyPcs - detailAssignQuantity; |
| | | if (orderDetailNeedQuantity > assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity) - palletAssignQuantity) |
| | | { |
| | | details[i].LockQtyPcs += assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity) - palletAssignQuantity; |
| | | Dt_OutProStockInfo outStockLockInfo = _outProStockInfoService.GetOutStockLockInfo(proOutOrder, details[i], assignOutStocks[j], assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity) - palletAssignQuantity); |
| | | outProStockInfos.Add(outStockLockInfo); |
| | | } |
| | | else |
| | | { |
| | | Dt_OutProStockInfo outStockLockInfo = _outProStockInfoService.GetOutStockLockInfo(proOutOrder, details[i], assignOutStocks[j], details[i].QtyPcs - details[i].LockQtyPcs); |
| | | outProStockInfos.Add(outStockLockInfo); |
| | | details[i].LockQtyPcs = details[i].QtyPcs; |
| | | break; |
| | | } |
| | | |
| | | } |
| | | item.LockQtyPcs += assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity); |
| | | Dt_OutProStockInfo outStockLockInfo = _outProStockInfoService.GetOutStockLockInfo(proOutOrder, item, assignOutStocks[j], assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity)); |
| | | outProStockInfos.Add(outStockLockInfo); |
| | | } |
| | | else |
| | | { |
| | | Dt_OutProStockInfo outStockLockInfo = _outProStockInfoService.GetOutStockLockInfo(proOutOrder, item, assignOutStocks[j], item.QtyPcs - detailAssignQuantity); |
| | | outProStockInfos.Add(outStockLockInfo); |
| | | item.LockQtyPcs = item.QtyPcs; |
| | | break; |
| | | } |
| | | } |
| | | List<string> locationArr = outStocks.Select(x => x.LocationCode).ToList(); |