| | |
| | | /// <returns></returns> |
| | | public WebResponseContent AddDeliveryOrder(ErpProOutOrderDTO outOrderDTO) |
| | | { |
| | | WebResponseContent content=new WebResponseContent(); |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (BaseDal.QueryFirst(x => x.ProOutOrderNo == outOrderDTO.OrderNo) != null) |
| | | if (BaseDal.QueryFirst(x => x.ProOutOrderNo == outOrderDTO.OrderNo) != null) |
| | | { |
| | | return content.Error($"åºåºåå·{outOrderDTO.OrderNo}å·²åå¨!"); |
| | | } |
| | | Dt_Warehouse warehouse=null; |
| | | |
| | | Dt_Warehouse warehouse = null; |
| | | List<Dt_CustomerInfo> customerInfos = _basicRepository.CustomerInfoRepository.QueryData(); |
| | | if (outOrderDTO.OType==1 && string.IsNullOrEmpty(outOrderDTO.WaType)) |
| | | { |
| | | warehouse = _basicRepository.WarehouseRepository.QueryFirst(x=>x.WarehouseCode==WarehouseEnum.HA71.ToString()); |
| | | } |
| | | else if (outOrderDTO.OType==2) |
| | | |
| | | if (outOrderDTO.OType == 1 && string.IsNullOrEmpty(outOrderDTO.WaType)) |
| | | { |
| | | warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA71.ToString()); |
| | | } |
| | | else if (outOrderDTO.OType == 2) |
| | | { |
| | | 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>(); |
| | | Dictionary<string, string> keyValuePairs = new Dictionary<string, string>(); |
| | | |
| | | // å¤çåå§æç»å¹¶åå¨å°ä¸´æ¶å表 |
| | | var tempDetails = new List<Dt_ProOutOrderDetail>(); |
| | | foreach (var item in outOrderDTO.OrderDetails) |
| | | { |
| | | //å¤æå®¢æ·æ¯å¦åå¨ |
| | | Dt_CustomerInfo? customerInfo = customerInfos.Where(x=>x.Code== item.Customer).FirstOrDefault(); |
| | | if (customerInfo==null) |
| | | // å¤æå®¢æ·æ¯å¦åå¨ |
| | | Dt_CustomerInfo? customerInfo = customerInfos.FirstOrDefault(x => x.Code == item.Customer); |
| | | if (customerInfo == null) |
| | | { |
| | | return content.Error($"客æ·{item.Customer}ä¸åå¨!"); |
| | | } |
| | | |
| | | Dt_ProOutOrderDetail proOutOrderDetail = _mapper.Map<Dt_ProOutOrderDetail>(item); |
| | | if (!string.IsNullOrEmpty(item.SaleOrder)) |
| | | { |
| | | if (keyValuePairs!=null && keyValuePairs.ContainsKey(item.SaleOrder)) |
| | | if (keyValuePairs != null && keyValuePairs.ContainsKey(item.SaleOrder)) |
| | | { |
| | | proOutOrderDetail.EndCustomer = keyValuePairs[item.SaleOrder]; |
| | | } |
| | | else |
| | | { |
| | | string request = _invokeERPService.InvokeProSaleCustomer(item.SaleOrder); |
| | | ErpSaleCustomResponseContent responseContent=request.DeserializeObject<ErpSaleCustomResponseContent>(); |
| | | if (responseContent.Code!=200) |
| | | ErpSaleCustomResponseContent responseContent = request.DeserializeObject<ErpSaleCustomResponseContent>(); |
| | | if (responseContent.Code != 200) |
| | | { |
| | | return content.Error($"订å{item.SaleOrder}ç»ç«¯å®¢æ·è·å失败!"); |
| | | } |
| | | //夿ç»ç«¯å®¢æ·æ¯å¦åå¨ |
| | | Dt_CustomerInfo? customerInfoEnd = customerInfos.Where(x => x.Code == responseContent.Data[0].Endcustomer).FirstOrDefault(); |
| | | |
| | | // 夿ç»ç«¯å®¢æ·æ¯å¦åå¨ |
| | | Dt_CustomerInfo? customerInfoEnd = customerInfos.FirstOrDefault(x => x.Code == responseContent.Data[0].Endcustomer); |
| | | if (customerInfoEnd == null) |
| | | { |
| | | return content.Error($"ç»ç«¯å®¢æ·{responseContent.Data[0].Endcustomer}ä¸åå¨!"); |
| | | } |
| | | |
| | | proOutOrderDetail.EndCustomer = responseContent.Data[0].Endcustomer; |
| | | keyValuePairs.Add(item.SaleOrder, responseContent.Data[0].Endcustomer); |
| | | } |
| | | } |
| | | |
| | | // å
ç´¯å å½åæç»çæ°éï¼å
å«å¤åï¼ |
| | | proOutOrderDetail.QtyPcs += proOutOrderDetail.SpareQty; |
| | | proOutOrderDetails.Add(proOutOrderDetail); |
| | | tempDetails.Add(proOutOrderDetail); |
| | | } |
| | | Dt_ProOutOrder proOutOrder= new Dt_ProOutOrder() |
| | | |
| | | // ææ¡ä»¶åç»å¹¶åå¹¶æç» |
| | | var groupedDetails = tempDetails.GroupBy(detail => new |
| | | { |
| | | ProOutOrderNo= outOrderDTO.OrderNo, |
| | | WarehouseId= warehouse.WarehouseId, |
| | | ProOrderType= outOrderDTO.OType, |
| | | ProOrderStatus=OutOrderStatusEnum.æªå¼å§.ObjToInt(), |
| | | PlantShipDate= outOrderDTO.PlantShipDate.ObjToDate(), |
| | | Remark= outOrderDTO.Note, |
| | | Details= proOutOrderDetails |
| | | detail.PCode, |
| | | detail.PVer, |
| | | detail.PLot, |
| | | detail.DateCode, |
| | | }) |
| | | .Select(group => |
| | | { |
| | | // ååç»ä¸ç¬¬ä¸ä¸ªæç»ä½ä¸ºåºç¡ |
| | | var firstDetail = group.First(); |
| | | return new Dt_ProOutOrderDetail |
| | | { |
| | | // å¤å¶åºç¡ä¿¡æ¯ |
| | | PCode = firstDetail.PCode, |
| | | PVer = firstDetail.PVer, |
| | | PLot = firstDetail.PLot, |
| | | DateCode = firstDetail.DateCode, |
| | | EndCustomer = firstDetail.EndCustomer, |
| | | QtyPcs = group.Sum(d => d.QtyPcs), |
| | | // ç´¯å å¤åæ° |
| | | SpareQty = group.Sum(d => d.SpareQty) |
| | | }; |
| | | }); |
| | | |
| | | proOutOrderDetails.AddRange(groupedDetails); |
| | | |
| | | Dt_ProOutOrder proOutOrder = new Dt_ProOutOrder() |
| | | { |
| | | ProOutOrderNo = outOrderDTO.OrderNo, |
| | | WarehouseId = warehouse.WarehouseId, |
| | | ProOrderType = outOrderDTO.OType, |
| | | ProOrderStatus = OutOrderStatusEnum.æªå¼å§.ObjToInt(), |
| | | PlantShipDate = outOrderDTO.PlantShipDate.ObjToDate(), |
| | | Remark = outOrderDTO.Note, |
| | | Details = proOutOrderDetails |
| | | }; |
| | | |
| | | Db.InsertNav(proOutOrder).Include(x => x.Details).ExecuteCommand(); |
| | | content.OK("æå"); |
| | | } |