| | |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common.MaterielEnum; |
| | | using WIDESEA_Common.OrderEnum; |
| | | using WIDESEA_Common.WareHouseEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.ERP; |
| | | using WIDESEA_IBasicRepository; |
| | | using WIDESEA_IOutboundRepository; |
| | | using WIDESEA_IOutboundService; |
| | |
| | | public IProDeliveryOrderRepository Repository => BaseDal; |
| | | private readonly IBasicRepository _basicRepository; |
| | | private readonly IMapper _mapper; |
| | | public ProDeliveryOrderService(IProDeliveryOrderRepository BaseDal, IBasicRepository basicRepository, IMapper mapper) : base(BaseDal) |
| | | private readonly IProDeliveryOrderDetailRepository _proDeliveryOrderDetailRepository; |
| | | public ProDeliveryOrderService(IProDeliveryOrderRepository BaseDal, IBasicRepository basicRepository, IMapper mapper, IProDeliveryOrderDetailRepository proDeliveryOrderDetailRepository) : base(BaseDal) |
| | | { |
| | | _basicRepository = basicRepository; |
| | | _mapper = mapper; |
| | | _proDeliveryOrderDetailRepository = proDeliveryOrderDetailRepository; |
| | | } |
| | | /// <summary> |
| | | /// æ¥æ¶ERPæåéå®åºåºä¿¡æ¯ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent ReceiveProDeliveryOrder(ERPProDeliveryDTO eRPProDeliveryDTO) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (eRPProDeliveryDTO == null) |
| | | { |
| | | return content.Error("éå®åºåºä¿¡æ¯ä¸è½ä¸ºç©º"); |
| | | } |
| | | Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == eRPProDeliveryDTO.WarehouseCode); |
| | | if (warehouse == null) |
| | | { |
| | | return content.Error($"ä»åºä¿¡æ¯ä¸åå¨{eRPProDeliveryDTO.WarehouseCode}"); |
| | | } |
| | | //è·åææç©æ |
| | | List<Dt_MaterielInfo> materielInfos = _basicRepository.MaterielInfoRepository.QueryData(x => x.WarehouseId == warehouse.WarehouseId && x.MaterielInvOrgId == MaterielInvOrgEnum.æ°å.ObjToInt()); |
| | | |
| | | //è·åææå®¢æ· |
| | | List<Dt_CustomerInfo> customerInfos = _basicRepository.CustomerInfoRepository.QueryData(); |
| | | |
| | | //夿æ¯å¦åå¨ç©æ |
| | | DeliveryDetailItem? deliveryDetailItem = eRPProDeliveryDTO.DeliveryDetail.FirstOrDefault(x => !materielInfos.Select(x => x.MaterielCode).Contains(x.MaterialCode)); |
| | | if (deliveryDetailItem != null) |
| | | { |
| | | return content.Error($"ç©æä¿¡æ¯{deliveryDetailItem.MaterialCode}ä¸åå¨"); |
| | | } |
| | | |
| | | //夿æ¯å¦åå¨å®¢æ· |
| | | DeliveryDetailItem? deliveryDetailCustom = eRPProDeliveryDTO.DeliveryDetail.FirstOrDefault(x => !customerInfos.Select(x => x.CustomerCode).Contains(x.Customer)); |
| | | |
| | | if (deliveryDetailCustom != null) |
| | | { |
| | | return content.Error($"客æ·ä¿¡æ¯{deliveryDetailCustom.Customer}ä¸åå¨"); |
| | | } |
| | | |
| | | //è·åææéå®åºåºä¿¡æ¯ |
| | | List<Dt_ProDeliveryOrder> proDeliveryOrdersOld = BaseDal.Db.Queryable<Dt_ProDeliveryOrder>().Includes(x => x.Details).ToList(); |
| | | |
| | | if (eRPProDeliveryDTO.OperateType == 1) |
| | | { |
| | | //夿é夿å
¥ |
| | | Dt_ProDeliveryOrder? proDeliveryOrderOld = proDeliveryOrdersOld.FirstOrDefault(x => x.DeliveryCode == eRPProDeliveryDTO.DeliveryCode); |
| | | if (proDeliveryOrderOld != null) |
| | | { |
| | | return content.Error($"éå®åºåºåå·{proDeliveryOrderOld.DeliveryCode}ä¿¡æ¯å·²åå¨"); |
| | | } |
| | | List<Dt_ProDeliveryOrderDetail> proDeliveryOrderDetails = eRPProDeliveryDTO.DeliveryDetail.Select(x => _mapper.Map<Dt_ProDeliveryOrderDetail>(x)).ToList(); |
| | | Dt_ProDeliveryOrder proDeliveryOrderAdd = _mapper.Map<Dt_ProDeliveryOrder>(eRPProDeliveryDTO); |
| | | proDeliveryOrderDetails.ForEach(x => |
| | | { |
| | | Dt_MaterielInfo? materielInfo = materielInfos.FirstOrDefault(t => t.MaterielCode == x.MaterialCode); |
| | | x.MaterielName = materielInfo?.MaterielName; |
| | | x.Unit = materielInfo?.MaterielUnit; |
| | | }); |
| | | proDeliveryOrderAdd.Details = proDeliveryOrderDetails; |
| | | proDeliveryOrderAdd.WarehouseId = warehouse.WarehouseId; |
| | | //æ°å¢ |
| | | BaseDal.Db.InsertNav(proDeliveryOrderAdd).Include(x => x.Details).ExecuteCommand(); |
| | | |
| | | } |
| | | else if (eRPProDeliveryDTO.OperateType == 2) |
| | | { |
| | | //夿æ¯å¦åå¨ |
| | | Dt_ProDeliveryOrder? proDeliveryOrderOld = proDeliveryOrdersOld.FirstOrDefault(x => x.DeliveryCode == eRPProDeliveryDTO.DeliveryCode); |
| | | if (proDeliveryOrderOld == null) |
| | | { |
| | | return content.Error($"éå®åºåºåå·{eRPProDeliveryDTO.DeliveryCode}ä¿¡æ¯ä¸åå¨"); |
| | | } |
| | | if (proDeliveryOrderOld.ProDeliveryStatus != OutOrderStatusEnum.æªå¼å§.ObjToInt()) |
| | | { |
| | | return content.Error($"éå®åºåºåå·{proDeliveryOrderOld.DeliveryCode}ç¶æä¸º{(OutOrderStatusEnum)proDeliveryOrderOld.ProDeliveryStatus}"); |
| | | } |
| | | List<Dt_ProDeliveryOrderDetail> proDeliveryOrderDetails = eRPProDeliveryDTO.DeliveryDetail.Select(x => _mapper.Map<Dt_ProDeliveryOrderDetail>(x)).ToList(); |
| | | Dt_ProDeliveryOrder proDeliveryOrder = _mapper.Map<Dt_ProDeliveryOrder>(eRPProDeliveryDTO); |
| | | proDeliveryOrder.Id = proDeliveryOrderOld.Id; |
| | | proDeliveryOrderDetails.ForEach(x => |
| | | { |
| | | Dt_MaterielInfo? materielInfo = materielInfos.FirstOrDefault(t => t.MaterielCode == x.MaterialCode); |
| | | x.MaterielName = materielInfo?.MaterielName; |
| | | x.Unit = materielInfo?.MaterielUnit; |
| | | }); |
| | | proDeliveryOrder.Details = proDeliveryOrderDetails; |
| | | proDeliveryOrder.WarehouseId = warehouse.WarehouseId; |
| | | //æ´æ° |
| | | BaseDal.Db.UpdateNav(proDeliveryOrder).Include(x => x.Details).ExecuteCommand(); |
| | | } |
| | | else if (eRPProDeliveryDTO.OperateType == 3) |
| | | { |
| | | //夿æ¯å¦åå¨ |
| | | Dt_ProDeliveryOrder? proDeliveryOrderOld = proDeliveryOrdersOld.FirstOrDefault(x => x.DeliveryCode == eRPProDeliveryDTO.DeliveryCode); |
| | | if (proDeliveryOrderOld == null) |
| | | { |
| | | return content.Error($"éå®åºåºåå·{eRPProDeliveryDTO.DeliveryCode}ä¿¡æ¯ä¸åå¨"); |
| | | } |
| | | if (proDeliveryOrderOld.ProDeliveryStatus != OutOrderStatusEnum.æªå¼å§.ObjToInt()) |
| | | { |
| | | return content.Error($"éå®åºåºåå·{proDeliveryOrderOld.DeliveryCode}ç¶æä¸º{(OutOrderStatusEnum)proDeliveryOrderOld.ProDeliveryStatus}"); |
| | | } |
| | | //å é¤ |
| | | BaseDal.Db.DeleteNav(proDeliveryOrderOld).Include(x => x.Details).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | return content.Error("æªæ¾å°æä½ç±»å"); |
| | | } |
| | | //æ´æ°æ°æ® |
| | | return content.OK("æ¥æ¶æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// ERPæåéå®åºåºåé
åºå |
| | | /// </summary> |
| | | public (List<Dt_ProStockInfo>, List<Dt_ProDeliveryOrder>, List<Dt_ProDeliveryOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignProStockOutbound(List<Dt_ProDeliveryOrder> proDeliveryOrders,List<Dt_ProDeliveryOrderDetail> deliveryOrderDetails) |
| | | { |
| | | List<Dt_ProStockInfo> outStocks = new List<Dt_ProStockInfo>(); |
| | | |
| | | //åºåºè¯¦æ
|
| | | List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); |
| | | //è´§ä½åå¨ |
| | | List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); |
| | | |
| | | //foreach (var item in ) |
| | | //{ |
| | | |
| | | //} |
| | | |
| | | //foreach (var item in deliveryOrderDetails) |
| | | //{ |
| | | // decimal needQuantity = item.ReqQuantity; |
| | | // //è·åå¯ç¨åºå |
| | | // List<Dt_ProStockInfo> stockInfos = _stockService.ProStockInfoService.GetUseableStocks(item.MaterialCode, WarehouseEnum.LLDCP.ObjToInt()).Where(x => !outStocks.Select(x => x.PalletCode).Contains(x.PalletCode)).ToList(); |
| | | // if (!stockInfos.Any()) |
| | | // { |
| | | // continue; |
| | | // } |
| | | // //åé
å®é
åºå |
| | | // List<Dt_ProStockInfo> autoAssignStocks = _stockService.ProStockInfoService.GetOutboundStocks(stockInfos, needQuantity); |
| | | // //æ·»å åºååé
|
| | | // outStocks.AddRange(autoAssignStocks); |
| | | // //è®¢åæ°é |
| | | // decimal orderQuantity = item.ReqQuantity; |
| | | // bool assignStop = true; |
| | | // while (assignStop) |
| | | // { |
| | | // //åºåºè®¢åæç»å·²åé
æ°é |
| | | // decimal detailAssignQuantity = outStockLockInfos.Where(x => x.OrderDetailId == item.OutDetailId).Sum(x => x.AssignQuantity); |
| | | |
| | | // decimal orderDetailNeedQuantity = item.ReqQuantity - detailAssignQuantity; |
| | | |
| | | // decimal useStockLength = autoAssignStocks[0].proStockInfoDetails |
| | | // .Sum(x => x.StockQty); |
| | | // if (orderDetailNeedQuantity > useStockLength) |
| | | // { |
| | | |
| | | // //çæè¯¦æ
|
| | | // Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(item, autoAssignStocks[0], useStockLength); |
| | | // outStockLockInfos.Add(outStockLockInfo); |
| | | // item.AssignTotalUsage += useStockLength; |
| | | // autoAssignStocks.Remove(autoAssignStocks[0]); |
| | | // } |
| | | // else |
| | | // { |
| | | // //çæè¯¦æ
|
| | | // Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(item, autoAssignStocks[0], orderDetailNeedQuantity); |
| | | // outStockLockInfos.Add(outStockLockInfo); |
| | | // item.AssignTotalUsage = orderQuantity; |
| | | // autoAssignStocks.Remove(autoAssignStocks[0]); |
| | | // assignStop = false; |
| | | // } |
| | | // } |
| | | // item.OutMESOrderStatus = OutOrderStatusEnum.åºåºä¸.ObjToInt(); |
| | | // locationInfos.AddRange(_basicRepository.LocationInfoRepository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList())); |
| | | //} |
| | | |
| | | return (outStocks, proDeliveryOrders, deliveryOrderDetails, outStockLockInfos, locationInfos); |
| | | } |
| | | } |
| | | } |