|  |  |  | 
|---|
|  |  |  | using AutoMapper; | 
|---|
|  |  |  | using Castle.Core.Resource; | 
|---|
|  |  |  | using Org.BouncyCastle.Asn1.Cmp; | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | using System.Collections.Generic; | 
|---|
|  |  |  | using System.Linq; | 
|---|
|  |  |  | 
|---|
|  |  |  | _invokeERPService = invokeERPService; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// æ¥æ¶ERPæååºåºå | 
|---|
|  |  |  | /// æ¥æ¶ERPæååºåºåä¿¡æ¯(订ååºåº/å¯å®åºåº) | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public async Task<WebResponseContent> ProductDeliveryOrder(ErpProOutOrderDTO outOrderDTO) | 
|---|
|  |  |  | 
|---|
|  |  |  | keyValuePairs.Add(item.SaleOrder, responseContent.Data[0].Endcustomer); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | proOutOrderDetail.QtyPcs += proOutOrderDetail.SpareQty; | 
|---|
|  |  |  | proOutOrderDetails.Add(proOutOrderDetail); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_ProOutOrder  proOutOrder= new Dt_ProOutOrder() | 
|---|
|  |  |  | 
|---|
|  |  |  | content.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// éå®ææ´¾ | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public async Task<WebResponseContent> ProductSpecifyVer(ErpProductSpecifyVerDTO erpProductSpecifyVerDTO) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x=>x.WarehouseCode==erpProductSpecifyVerDTO.WaType); | 
|---|
|  |  |  | if (warehouse == null) | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"æªæ¾å°{erpProductSpecifyVerDTO.WaType}ä»åºä¿¡æ¯")); | 
|---|
|  |  |  | //æ¥è¯¢å¯ææ´¾åºå | 
|---|
|  |  |  | List<Dt_ProStockInfo> proStockInfos = Db.Queryable<Dt_ProStockInfo>().Where(x => x.ProStockAttribute == ProStockAttributeEnum.æå.ObjToInt()) | 
|---|
|  |  |  | .Includes(x => x.proStockInfoDetails) | 
|---|
|  |  |  | .Where(x => x.proStockInfoDetails | 
|---|
|  |  |  | .Any(v => | 
|---|
|  |  |  | v.SaleOrder == erpProductSpecifyVerDTO.OrderNo | 
|---|
|  |  |  | && v.ProductCode == erpProductSpecifyVerDTO.PCode | 
|---|
|  |  |  | && v.ProductVersion == erpProductSpecifyVerDTO.PVer | 
|---|
|  |  |  | && v.LotNumber == erpProductSpecifyVerDTO.PLot | 
|---|
|  |  |  | && v.DateCode == erpProductSpecifyVerDTO.DateCode | 
|---|
|  |  |  | && (v.SpecifyVer==null||v.SpecifyVer=="") | 
|---|
|  |  |  | )) | 
|---|
|  |  |  | .ToList(); | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> proStockInfoDetails = new List<Dt_ProStockInfoDetail>(); | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> specifyVerDetails = new List<Dt_ProStockInfoDetail>(); | 
|---|
|  |  |  | if (proStockInfos==null) | 
|---|
|  |  |  | return await Task.FromResult(content.Error("å¯ææ´¾åºåä¸åå¨")); | 
|---|
|  |  |  | proStockInfos = proStockInfos.OrderBy(x => x.proStockInfoDetails.FirstOrDefault()?.DateCode).ThenBy(x => x.CreateDate).ThenBy(x => x.proStockInfoDetails.Sum(x => x.StockPcsQty)).ToList(); | 
|---|
|  |  |  | foreach (var item in proStockInfos) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | proStockInfoDetails.AddRange(item.proStockInfoDetails); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (proStockInfoDetails.Sum(x=>x.StockPcsQty)< erpProductSpecifyVerDTO.QtyPcs) | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"å¯ææ´¾åºåæ°éä¸è¶³,å¯ç¨:{proStockInfoDetails.Sum(x => x.StockPcsQty)}")); | 
|---|
|  |  |  | float overQty = 0; | 
|---|
|  |  |  | foreach (var item in proStockInfoDetails) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | specifyVerDetails.Add(item); | 
|---|
|  |  |  | overQty += item.StockPcsQty; | 
|---|
|  |  |  | //已满足è·åæ°éä¸åæ´æ¹ | 
|---|
|  |  |  | if (overQty>= erpProductSpecifyVerDTO.QtyPcs) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | specifyVerDetails.ForEach(x => | 
|---|
|  |  |  | { | 
|---|
|  |  |  | x.SpecifyVer = erpProductSpecifyVerDTO.Ver; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | _unitOfWorkManage.BeginTran(); | 
|---|
|  |  |  | _stockRepository.ProStockInfoDetailRepository.UpdateData(specifyVerDetails); | 
|---|
|  |  |  | _unitOfWorkManage.CommitTran(); | 
|---|
|  |  |  | content.OK("ææ´¾æå"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _unitOfWorkManage.RollbackTran(); | 
|---|
|  |  |  | content.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return await Task.FromResult(content); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// æååºå¾
åè´§åº(å¹³åº)+忥ERPåºåº(ç»å®äºåºåºååºå) | 
|---|
|  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// æ¥è¯¢ERPè®¢åæ£é¤åºåæ°é | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | public async Task<WebResponseContent> OutProErpSync(string outProOrderNo) | 
|---|
|  |  |  | public WebResponseContent OutProErpSync(string outProOrderNo) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | 
|---|
|  |  |  | Dt_ProOutOrder proOutOrder = BaseDal.Db.Queryable<Dt_ProOutOrder>().Where(x=>x.ProOutOrderNo== outProOrderNo).Includes(x => x.Details).First(); | 
|---|
|  |  |  | if (proOutOrder==null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"æªæ¾å°æååºåºè®¢å{outProOrderNo}")); | 
|---|
|  |  |  | return content.Error($"æªæ¾å°æååºåºè®¢å{outProOrderNo}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (proOutOrder.ProOrderStatus>=OutOrderStatusEnum.åºåºå®æ.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"åºåºè®¢å已宿æå
³é")); | 
|---|
|  |  |  | return content.Error($"åºåºè®¢å已宿æå
³é"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //è°ç¨erpåºåºè®¢ååºåæ¥è¯¢æ¥å£ | 
|---|
|  |  |  | string response = _invokeERPService.InvokeOutProErpSync(outProOrderNo); | 
|---|
|  |  |  | ErpOutProSyncResponseContent erpOutProSyncResponse= response.DeserializeObject<ErpOutProSyncResponseContent>(); | 
|---|
|  |  |  | if (erpOutProSyncResponse.Code!=200) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"ERPåºåºè®¢åæ¥è¯¢æ¥å£è°ç¨å¤±è´¥,é误信æ¯:{erpOutProSyncResponse.Msg}")); | 
|---|
|  |  |  | return content.Error($"ERPåºåºè®¢åæ¥è¯¢æ¥å£è°ç¨å¤±è´¥,é误信æ¯:{erpOutProSyncResponse.Msg}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<OutProStock> outProStocks = erpOutProSyncResponse.Data; | 
|---|
|  |  |  | if (outProStocks.Count<=0 || outProStocks==null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"æååºåºè®¢å{outProOrderNo}ERPå½åæªæåºåºåºåä¿¡æ¯")); | 
|---|
|  |  |  | return content.Error($"æååºåºè®¢å{outProOrderNo}ERPå½åæªæåºåºåºåä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // éªè¯ææåºåºåå·æ¯å¦ä¸è´ | 
|---|
|  |  |  | OutProStock? outExist = outProStocks.FirstOrDefault(x => x.ShippingNumber != outProOrderNo); | 
|---|
|  |  |  | if (outExist != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error($"ERPè¿åäºåºåºè®¢å{outExist.ShippingNumber}åºåä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //è·åå¹³åºåºåº | 
|---|
|  |  |  | Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString()); | 
|---|
|  |  |  | if (warehouse==null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error("æªæ¾å°åºåºä¿¡æ¯")); | 
|---|
|  |  |  | return content.Error("æªæ¾å°åºåºä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | var productCodes = outProStocks.Select(x => x.Partnum).Distinct().ToList(); | 
|---|
|  |  |  | //è·åææå¹³åºåºå | 
|---|
|  |  |  | List<Dt_ProStockInfo> proStockInfos = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).Includes(x => x.proStockInfoDetails).ToList(); | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> proStockInfoDetails= new List<Dt_ProStockInfoDetail>(); | 
|---|
|  |  |  | foreach (var item in proStockInfos) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | proStockInfoDetails.AddRange(item.proStockInfoDetails); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | proStockInfoDetails = proStockInfoDetails.OrderBy(x => x.DateCode).ThenBy(x => x.CreateDate).ToList() ; | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> proStockInfoDetails = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo, Dt_ProStockInfoDetail>((master, detail) => master.Id == detail.ProStockId) | 
|---|
|  |  |  | .Where((master, detail) => master.WarehouseId == warehouse.WarehouseId && productCodes.Contains(detail.ProductCode)) | 
|---|
|  |  |  | .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) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //æ¥è¯¢åºåè®°å½ | 
|---|
|  |  |  | if (item.ShippingNumber != outProOrderNo) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"ERPè¿åäºåºåºè®¢å{item.ShippingNumber}åºåä¿¡æ¯")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //è·ååºå | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> outStocks = proStockInfoDetails.Where(x=>x.ProductCode==item.Partnum).ToList(); | 
|---|
|  |  |  | if (outStocks.Count==0 || outStocks==null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(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) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_ProOutOrderDetail? proOutOrderDetail = proOutOrder.Details.FirstOrDefault(x => x.SaleOrder == item.SoNumber && x.PCode == item.Partnum) ?? throw new Exception($"åºåºå{proOutOrder.ProOutOrderNo}æªæ¾å°éå®è®¢å{item.SoNumber}æç»,è¯·æ£æ¥"); | 
|---|
|  |  |  | if (item.Quantity >= itemOut.StockPcsQty) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_ProOutOrderDetail? proOutOrderDetail = proOutOrder.Details.FirstOrDefault(x => x.SaleOrder == item.SoNumber && x.PCode == item.Partnum); | 
|---|
|  |  |  | if (proOutOrderDetail == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"åºåºå{proOutOrder.ProOutOrderNo}æªæ¾å°éå®è®¢å{item.SoNumber}æç»,è¯·æ£æ¥")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //æ´æ°åºåºæç»åæ°é | 
|---|
|  |  |  | proOutOrderDetail.OverQtyPcs += itemOut.StockPcsQty; | 
|---|
|  |  |  | item.Quantity -= (int)itemOut.StockPcsQty; | 
|---|
|  |  |  | 
|---|
|  |  |  | proStockInfoDetails.Remove(itemOut); | 
|---|
|  |  |  | if (proOutOrderDetail.OverQtyPcs > proOutOrderDetail.QtyPcs) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"åºåºå{proOutOrder.ProOutOrderNo}éå®è®¢å{item.SoNumber}æ°é溢åº{proOutOrderDetail.OverQtyPcs - proOutOrderDetail.QtyPcs}")); | 
|---|
|  |  |  | return content.Error($"åºåºå{proOutOrder.ProOutOrderNo}éå®è®¢å{item.SoNumber}æ°é溢åº{proOutOrderDetail.OverQtyPcs - proOutOrderDetail.QtyPcs}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (proOutOrderDetail.ProOrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (item.Quantity < itemOut.StockPcsQty) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_ProOutOrderDetail? proOutOrderDetail = proOutOrder.Details.FirstOrDefault(x => x.SaleOrder == item.SoNumber && x.PCode == item.Partnum); | 
|---|
|  |  |  | if (proOutOrderDetail == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"åºåºå{proOutOrder.ProOutOrderNo}æªæ¾å°éå®è®¢å{item.SoNumber}æç»,è¯·æ£æ¥")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //æ´æ°åºåºæç»åæ°é | 
|---|
|  |  |  | proOutOrderDetail.OverQtyPcs += item.Quantity; | 
|---|
|  |  |  | item.Quantity -= item.Quantity; | 
|---|
|  |  |  | float Range = itemOut.StockPcsQty / itemOut.SETQty; | 
|---|
|  |  |  | itemOut.SETQty = item.Quantity / Range; | 
|---|
|  |  |  | if (Range == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error($"{itemOut.BagNo}åå
æ°é转æ¢å¤±è´¥,è¯·æ£æ¥"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int outSet = (int)(item.Quantity / Range); | 
|---|
|  |  |  | if (outSet == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error($"{itemOut.BagNo}åå
æ°é转æ¢å¤±è´¥,è¯·æ£æ¥"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | itemOut.SETQty -= outSet; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | itemOut.StockPcsQty -= item.Quantity; | 
|---|
|  |  |  | if (proOutOrderDetail.OverQtyPcs > proOutOrderDetail.QtyPcs) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"åºåºå{proOutOrder.ProOutOrderNo}éå®è®¢å{item.SoNumber}æ°é溢åº{proOutOrderDetail.OverQtyPcs - proOutOrderDetail.QtyPcs}")); | 
|---|
|  |  |  | return content.Error($"åºåºå{proOutOrder.ProOutOrderNo}éå®è®¢å{item.SoNumber}æ°é溢åº{proOutOrderDetail.OverQtyPcs - proOutOrderDetail.QtyPcs}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (proOutOrderDetail.ProOrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (item.Quantity>0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error($"æªæ¾å°{item.SoNumber}坿£ååºå"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (proOutOrder.Details.Count == proOutOrder.Details.Where(x => x.ProOrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_ProOutOrderDetail? proOutOrderDetail = proOutOrder.Details.FirstOrDefault(x => x.ProOrderDetailStatus <= OrderDetailStatusEnum.Over.ObjToInt()); | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"{proOutOrderDetail?.SaleOrder}éå®è®¢åæ°ééåº{proOutOrderDetail?.QtyPcs},å¯åº{proOutOrderDetail?.OverQtyPcs}")); | 
|---|
|  |  |  | 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.èªå¨å é¤); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | await _stockRepository.ProStockInfoDetailRepository.UpdateDataAsync(proStockInfoDetails); | 
|---|
|  |  |  | await BaseDal.UpdateDataAsync(proOutOrder); | 
|---|
|  |  |  | await _outboundRepository.ProOutOrderDetailRepository.UpdateDataAsync(proOutOrder.Details); | 
|---|
|  |  |  | _stockRepository.ProStockInfoDetailRepository.DeleteAndMoveIntoHty(delStockInfoDetails, OperateTypeEnum.èªå¨å é¤); | 
|---|
|  |  |  | _stockRepository.ProStockInfoRepository.DeleteAndMoveIntoHty(delProStockInfos, OperateTypeEnum.èªå¨å®æ); | 
|---|
|  |  |  | _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfoDetails); | 
|---|
|  |  |  | BaseDal.UpdateData(proOutOrder); | 
|---|
|  |  |  | _outboundRepository.ProOutOrderDetailRepository.UpdateData(proOutOrder.Details); | 
|---|
|  |  |  | _unitOfWorkManage.CommitTran(); | 
|---|
|  |  |  | return await Task.FromResult(content.OK()); | 
|---|
|  |  |  | return content.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _unitOfWorkManage.RollbackTran(); | 
|---|
|  |  |  | return await Task.FromResult(content.Error(ex.Message)); | 
|---|
|  |  |  | return content.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error("æªæ¾å°åºåºä¿¡æ¯")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //è·åææå¹³åºçæ°æ® | 
|---|
|  |  |  | List<Dt_ProStockInfo> AllproStockInfos = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>() | 
|---|
|  |  |  | .Where(x => x.WarehouseId == warehouse.WarehouseId) | 
|---|
|  |  |  | .Includes(x => x.proStockInfoDetails).ToList(); | 
|---|
|  |  |  | List<Dt_ProStockInfo> proStockInfos = new List<Dt_ProStockInfo>(); | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> proStockInfoDetails = new List<Dt_ProStockInfoDetail>(); | 
|---|
|  |  |  | foreach (var item in AllproStockInfos) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | proStockInfoDetails.AddRange(item.proStockInfoDetails); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //è·åææå¹³åºåºå | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> proStockInfoDetails = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo, Dt_ProStockInfoDetail>((master, detail) => master.Id == detail.ProStockId) | 
|---|
|  |  |  | .Where((master, detail) => master.WarehouseId == warehouse.WarehouseId && outProInfos.Select(x=>x.ProductCode).Contains(detail.ProductCode)) | 
|---|
|  |  |  | .Select((master, detail) => detail) | 
|---|
|  |  |  | .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(); | 
|---|
|  |  |  | proStockInfoDetails = proStockInfoDetails.OrderBy(x => x.DateCode).ThenBy(x => x.CreateDate).ThenBy(x=>x.StockPcsQty).ToList(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Dt_Warehouse> warehouses = await _basicRepository.WarehouseRepository.QueryDataAsync(x => x.WarehouseType == WarehouseTypEnum.æå.ToString()); | 
|---|
|  |  |  | //å°å
¶åç» | 
|---|
|  |  |  | outProInfos = outProInfos.GroupBy(x => x.ProductCode).Select(x=>new OutProInfoDTO() | 
|---|
|  |  |  | 
|---|
|  |  |  | OutQtys=x.Sum(x=>x.OutQtys) | 
|---|
|  |  |  | }).ToList(); | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> UpStockInfoDetails = new List<Dt_ProStockInfoDetail>(); | 
|---|
|  |  |  | List<Dt_ProStockInfo> DelStocks = new List<Dt_ProStockInfo>(); | 
|---|
|  |  |  | foreach (var item in outProInfos) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //è·ååºå | 
|---|
|  |  |  | 
|---|
|  |  |  | if (outStocks.Count <= 0 || outProInfos==null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"æªæ¾å°äº§å{item.ProductCode}åºå")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (outStocks.Sum(x=>x.StockPcsQty)< item.OutQtys) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"å¯ç¨å¹³åºæ°é{outStocks.Sum(x => x.StockPcsQty)}䏿»¡è¶³åºåºæ°é{item.OutQtys}")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | foreach (var outStock in outStocks) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | outStock.OutSETQty = outStock.OutboundQuantity / Range; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (outStock.OutSETQty==0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"{outStock.BagNo}åå
æ°é转æ¢å¤±è´¥,è¯·æ£æ¥")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | item.OutQtys -= (int)BeyondQtys; | 
|---|
|  |  |  | UpStockInfoDetails.Add(outStock); | 
|---|
|  |  |  | 
|---|
|  |  |  | outStock.OutboundQuantity = BeyondQtys; | 
|---|
|  |  |  | float Range = outStock.StockPcsQty / outStock.SETQty; | 
|---|
|  |  |  | outStock.OutSETQty = outStock.OutboundQuantity / Range; | 
|---|
|  |  |  | item.OutQtys -= (int)BeyondQtys; | 
|---|
|  |  |  | if (outStock.OutSETQty == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"{outStock.BagNo}åå
æ°é转æ¢å¤±è´¥,è¯·æ£æ¥")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | item.OutQtys = 0; | 
|---|
|  |  |  | UpStockInfoDetails.Add(outStock); | 
|---|
|  |  |  | proStockInfoDetails.Remove(outStock); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | outStock.OutboundQuantity = item.OutQtys; | 
|---|
|  |  |  | float Range = outStock.StockPcsQty / outStock.SETQty; | 
|---|
|  |  |  | outStock.OutSETQty = outStock.OutboundQuantity / Range; | 
|---|
|  |  |  | item.OutQtys -= item.OutQtys; | 
|---|
|  |  |  | if (outStock.OutSETQty == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"{outStock.BagNo}åå
æ°é转æ¢å¤±è´¥,è¯·æ£æ¥")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | item.OutQtys = 0; | 
|---|
|  |  |  | UpStockInfoDetails.Add(outStock); | 
|---|
|  |  |  | proStockInfoDetails.Remove(outStock); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return await Task.FromResult(content.Error($"{proOutOrderDetail?.SaleOrder}éå®è®¢åæ°ééåº{proOutOrderDetail?.QtyPcs},å¯åº{proOutOrderDetail?.OverQtyPcs}")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<StockOutItemsItem> stockOutItems = new List<StockOutItemsItem>(); | 
|---|
|  |  |  | if (proOutOrder.ProOrderStatus == OutOrderStatusEnum.åºåºå®æ.ObjToInt()) | 
|---|
|  |  |  | //è·åææå·²æ«ç å¾
åè´§çåºå | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> assOutStocks = _stockRepository.ProStockInfoDetailRepository.Db.Queryable<Dt_ProStockInfoDetail>() | 
|---|
|  |  |  | .Where(x => x.OutProNo == ProOutNo).ToList(); | 
|---|
|  |  |  | UpStockInfoDetails.AddRange(assOutStocks); | 
|---|
|  |  |  | foreach (var item in UpStockInfoDetails) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //è·åææå·²æ«ç å¾
åè´§çåºå | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> assOutStocks = _stockRepository.ProStockInfoDetailRepository.Db.Queryable<Dt_ProStockInfoDetail>() | 
|---|
|  |  |  | .Where(x => x.OutProNo == ProOutNo).ToList(); | 
|---|
|  |  |  | UpStockInfoDetails.AddRange(assOutStocks); | 
|---|
|  |  |  | foreach (var item in UpStockInfoDetails) | 
|---|
|  |  |  | StockOutItemsItem outItemsItem = new StockOutItemsItem() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | StockOutItemsItem outItemsItem = new StockOutItemsItem() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | PartNum = item.ProductCode, | 
|---|
|  |  |  | Rev = item.ProductVersion, | 
|---|
|  |  |  | SoNumber = item.OutDetailSaleNo, | 
|---|
|  |  |  | BatchNumber = item.ProductCode, | 
|---|
|  |  |  | QtyPcs = item.OutboundQuantity, | 
|---|
|  |  |  | QtySet = item.OutSETQty | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | stockOutItems.Add(outItemsItem); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | PartNum = item.ProductCode, | 
|---|
|  |  |  | Rev = item.ProductVersion, | 
|---|
|  |  |  | SoNumber = item.OutDetailSaleNo, | 
|---|
|  |  |  | BatchNumber = item.ProductCode, | 
|---|
|  |  |  | QtyPcs = item.OutboundQuantity, | 
|---|
|  |  |  | QtySet = item.OutSETQty | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | stockOutItems.Add(outItemsItem); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_Warehouse warehouseOut = warehouses.Where(x => x.WarehouseId == proOutOrder.WarehouseId).FirstOrDefault(); | 
|---|
|  |  |  | _unitOfWorkManage.BeginTran(); | 
|---|
|  |  |  | //å¤çåºåæ°æ®åä¸ä¼ ERP | 
|---|
|  |  |  | if (proOutOrder.ProOrderStatus == OutOrderStatusEnum.åºåºå®æ.ObjToInt()) | 
|---|
|  |  |  | //è·åå é¤åºå | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> delDetails = UpStockInfoDetails.Where(x => x.AssignDel == 1).ToList(); | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> UpDetails = UpStockInfoDetails.Where(x => x.AssignDel != 1).ToList(); | 
|---|
|  |  |  | //è·åå é¤çåºå主表 | 
|---|
|  |  |  | List<int> delStockIds = delDetails.Select(x => x.ProStockId).Distinct().ToList(); | 
|---|
|  |  |  | List<int> delStockDetailIds = delDetails.Select(x => x.Id).ToList(); | 
|---|
|  |  |  | foreach (var item in delStockIds) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //æååºåè®°å½åå¨å¾
å å
¥ | 
|---|
|  |  |  | ERPProOutOrderModel proOutOrderModel = new ERPProOutOrderModel() | 
|---|
|  |  |  | Dt_ProStockInfo proStockInfo = proStockInfos.FirstOrDefault(x=>x.Id==item); | 
|---|
|  |  |  | Dt_ProStockInfoDetail? proStockInfoDetail= proStockInfo.proStockInfoDetails.FirstOrDefault(x=> !delStockDetailIds.Contains(x.Id)); | 
|---|
|  |  |  | if (proStockInfoDetail==null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Way = 1, | 
|---|
|  |  |  | StockOutCode = _outboundOrderService.CreateCodeByRule(nameof(RuleCodeEnum.ProOutCOdeRule)), | 
|---|
|  |  |  | ConfirmedUserNo = App.User.UserName, | 
|---|
|  |  |  | AssignUserNo = App.User.UserName, | 
|---|
|  |  |  | WarehouseCode = warehouseOut.WarehouseCode, | 
|---|
|  |  |  | ShipDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), | 
|---|
|  |  |  | DeliverplanCode = proOutOrder.ProOutOrderNo, | 
|---|
|  |  |  | Remark = proOutOrder.Remark, | 
|---|
|  |  |  | StockOutItems = stockOutItems | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | //è·åå é¤åºå | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> delDetails = UpStockInfoDetails.Where(x=>x.AssignDel==1).ToList(); | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> UpDetails = UpStockInfoDetails.Where(x => x.AssignDel != 1).ToList(); | 
|---|
|  |  |  | //æ´æ°æ°æ® | 
|---|
|  |  |  | UpDetails.ForEach(x => | 
|---|
|  |  |  | { | 
|---|
|  |  |  | x.StockPcsQty -= x.OutboundQuantity; | 
|---|
|  |  |  | x.SETQty -= x.OutSETQty; | 
|---|
|  |  |  | x.OutDetailId = 0; | 
|---|
|  |  |  | x.OutDetailSaleNo = null; | 
|---|
|  |  |  | x.OutProNo = null; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | _stockRepository.ProStockInfoDetailRepository.DeleteAndMoveIntoHty(delDetails, OperateTypeEnum.èªå¨å®æ); | 
|---|
|  |  |  | await _stockRepository.ProStockInfoDetailRepository.UpdateDataAsync(UpDetails); | 
|---|
|  |  |  | //忥ERP | 
|---|
|  |  |  | string response = _invokeERPService.InvokeProOutApi(proOutOrderModel); | 
|---|
|  |  |  | ErpRequestContent erpRequestContent = response.DeserializeObject<ErpRequestContent>(); | 
|---|
|  |  |  | if (erpRequestContent.res != 1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new Exception("忥ERP失败,é误信æ¯:" + erpRequestContent.Data); | 
|---|
|  |  |  | DelStocks.Add(proStockInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | _unitOfWorkManage.BeginTran(); | 
|---|
|  |  |  | //å¤çåºåæ°æ®åä¸ä¼ ERP | 
|---|
|  |  |  | //æååºåè®°å½åå¨å¾
å å
¥ | 
|---|
|  |  |  | ERPProOutOrderModel proOutOrderModel = new ERPProOutOrderModel() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | await _stockRepository.ProStockInfoDetailRepository.UpdateDataAsync(UpStockInfoDetails); | 
|---|
|  |  |  | Way = 1, | 
|---|
|  |  |  | StockOutCode = _outboundOrderService.CreateCodeByRule(nameof(RuleCodeEnum.ProOutCOdeRule)), | 
|---|
|  |  |  | ConfirmedUserNo = App.User.UserName, | 
|---|
|  |  |  | AssignUserNo = App.User.UserName, | 
|---|
|  |  |  | WarehouseCode = warehouseOut.WarehouseCode, | 
|---|
|  |  |  | ShipDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), | 
|---|
|  |  |  | DeliverplanCode = proOutOrder.ProOutOrderNo, | 
|---|
|  |  |  | Remark = proOutOrder.Remark, | 
|---|
|  |  |  | StockOutItems = stockOutItems | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | //æ´æ°æ°æ® | 
|---|
|  |  |  | UpDetails.ForEach(x => | 
|---|
|  |  |  | { | 
|---|
|  |  |  | x.StockPcsQty -= x.OutboundQuantity; | 
|---|
|  |  |  | x.SETQty -= x.OutSETQty; | 
|---|
|  |  |  | x.OutDetailId = 0; | 
|---|
|  |  |  | x.OutDetailSaleNo = null; | 
|---|
|  |  |  | x.OutProNo = null; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | _stockRepository.ProStockInfoDetailRepository.DeleteAndMoveIntoHty(delDetails, OperateTypeEnum.èªå¨å®æ); | 
|---|
|  |  |  | _stockRepository.ProStockInfoRepository.DeleteAndMoveIntoHty(DelStocks, OperateTypeEnum.èªå¨å®æ); | 
|---|
|  |  |  | await _stockRepository.ProStockInfoDetailRepository.UpdateDataAsync(UpDetails); | 
|---|
|  |  |  | //忥ERP | 
|---|
|  |  |  | string response = _invokeERPService.InvokeProOutApi(proOutOrderModel); | 
|---|
|  |  |  | ErpRequestContent erpRequestContent = response.DeserializeObject<ErpRequestContent>(); | 
|---|
|  |  |  | if (erpRequestContent.res != 1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new Exception("忥ERP失败,é误信æ¯:" + erpRequestContent.Data); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | await _outboundRepository.ProOutOrderDetailRepository.UpdateDataAsync(proOutOrder.Details); | 
|---|
|  |  |  | await BaseDal.UpdateDataAsync(proOutOrder); | 
|---|