|  |  |  | 
|---|
|  |  |  | using AutoMapper; | 
|---|
|  |  |  | using Castle.Core.Resource; | 
|---|
|  |  |  | using Org.BouncyCastle.Asn1.Cmp; | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | using System.Collections.Generic; | 
|---|
|  |  |  | using System.Linq; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (outOrderDTO.OType==2) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString()); | 
|---|
|  |  |  | warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA71.ToString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Dt_ProOutOrderDetail> proOutOrderDetails = new List<Dt_ProOutOrderDetail>(); | 
|---|
|  |  |  | Dictionary<string,string> keyValuePairs =new Dictionary<string, string>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | .Select((master, detail) => detail) | 
|---|
|  |  |  | .ToList(); | 
|---|
|  |  |  | proStockInfoDetails = proStockInfoDetails.OrderBy(x => x.DateCode).ThenBy(x => x.CreateDate).ToList(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<int> stockIds = proStockInfoDetails.Select(x => x.ProStockId).Distinct().ToList(); | 
|---|
|  |  |  | //è·åææå¹³åºä¸»è¡¨ | 
|---|
|  |  |  | List<Dt_ProStockInfo> proStockInfos = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>().Where(x => stockIds.Contains(x.Id)).Includes(x => x.proStockInfoDetails).ToList(); | 
|---|
|  |  |  | List<Dt_ProStockInfo> delProStockInfos = new List<Dt_ProStockInfo>(); | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> delStockInfoDetails = new List<Dt_ProStockInfoDetail>(); | 
|---|
|  |  |  | foreach (var item in outProStocks) | 
|---|
|  |  |  | { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //è·ååºå | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> outStocks = proStockInfoDetails.Where(x=>x.ProductCode==item.Partnum).ToList(); | 
|---|
|  |  |  | if (outStocks.Count==0 || outStocks==null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error($"{item.Partnum}产ååå·åºåä¸åå¨"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | foreach (var itemOut in outStocks) | 
|---|
|  |  |  | foreach (var itemOut in proStockInfoDetails.Where(x => x.ProductCode == item.Partnum).ToList()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (item.Quantity==0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //æ´æ°åºåºæç»åæ°é | 
|---|
|  |  |  | proOutOrderDetail.OverQtyPcs += item.Quantity; | 
|---|
|  |  |  | item.Quantity -= item.Quantity; | 
|---|
|  |  |  | float Range = itemOut.StockPcsQty / itemOut.SETQty; | 
|---|
|  |  |  | itemOut.SETQty = item.Quantity / Range; | 
|---|
|  |  |  | int Range = (int)itemOut.StockPcsQty / (int)itemOut.SETQty; | 
|---|
|  |  |  | if (Range == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error($"{itemOut.BagNo}åå
æ°é转æ¢å¤±è´¥,è¯·æ£æ¥,Range:{Range}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int outSet =item.Quantity / Range; | 
|---|
|  |  |  | if (outSet == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error($"{itemOut.BagNo}åå
æ°é转æ¢å¤±è´¥,è¯·æ£æ¥,outSet:{outSet}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | itemOut.SETQty -= outSet; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | itemOut.StockPcsQty -= item.Quantity; | 
|---|
|  |  |  | item.Quantity = 0; | 
|---|
|  |  |  | if (proOutOrderDetail.OverQtyPcs > proOutOrderDetail.QtyPcs) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error($"åºåºå{proOutOrder.ProOutOrderNo}éå®è®¢å{item.SoNumber}æ°é溢åº{proOutOrderDetail.OverQtyPcs - proOutOrderDetail.QtyPcs}"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (item.Quantity>0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error($"æªæ¾å°{item.SoNumber}坿£ååºå"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (proOutOrder.Details.Count == proOutOrder.Details.Where(x => x.ProOrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | Dt_ProOutOrderDetail? proOutOrderDetail = proOutOrder.Details.FirstOrDefault(x => x.ProOrderDetailStatus <= OrderDetailStatusEnum.Over.ObjToInt()); | 
|---|
|  |  |  | return content.Error($"{proOutOrderDetail?.SaleOrder}éå®è®¢åæ°ééåº{proOutOrderDetail?.QtyPcs},å¯åº{proOutOrderDetail?.OverQtyPcs}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //è·åå é¤çåºå主表 | 
|---|
|  |  |  | List<int> delStockIds = delStockInfoDetails.Select(x => x.ProStockId).Distinct().ToList(); | 
|---|
|  |  |  | List<int> delStockDetailIds = delStockInfoDetails.Select(x => x.Id).ToList(); | 
|---|
|  |  |  | foreach (var item in delStockIds) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_ProStockInfo proStockInfo = proStockInfos.FirstOrDefault(x => x.Id == item); | 
|---|
|  |  |  | Dt_ProStockInfoDetail? proStockInfoDetail = proStockInfo.proStockInfoDetails.FirstOrDefault(x => !delStockDetailIds.Contains(x.Id)); | 
|---|
|  |  |  | if (proStockInfoDetail == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | delProStockInfos.Add(proStockInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //æ´æ°æ°æ® | 
|---|
|  |  |  | _unitOfWorkManage.BeginTran(); | 
|---|
|  |  |  | if (delStockInfoDetails.Count > 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _stockRepository.ProStockInfoDetailRepository.DeleteAndMoveIntoHty(delStockInfoDetails, OperateTypeEnum.èªå¨å é¤); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | _stockRepository.ProStockInfoDetailRepository.DeleteAndMoveIntoHty(delStockInfoDetails, OperateTypeEnum.èªå¨å é¤); | 
|---|
|  |  |  | _stockRepository.ProStockInfoRepository.DeleteAndMoveIntoHty(delProStockInfos, OperateTypeEnum.èªå¨å®æ); | 
|---|
|  |  |  | _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfoDetails); | 
|---|
|  |  |  | BaseDal.UpdateData(proOutOrder); | 
|---|
|  |  |  | _outboundRepository.ProOutOrderDetailRepository.UpdateData(proOutOrder.Details); | 
|---|