| | |
| | | using WIDESEA_IStockRepository; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_OutboundRepository; |
| | | using WIDESEA_StockRepository; |
| | | |
| | | namespace WIDESEA_OutboundService |
| | |
| | | /// åé
åºåºåºå |
| | | /// </summary> |
| | | /// <param name="outboundOrderDetail"></param> |
| | | /// <param name="stockSelectViews"></param> |
| | | /// <param name="stockSelectViews">æå®åºå</param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(Dt_OutboundOrderDetail outboundOrderDetail, List<StockSelectViewDTO> stockSelectViews) |
| | |
| | | decimal originalNeedQuantity = outboundOrderDetail.OrderQuantity - outboundOrderDetail.LockQuantity; |
| | | |
| | | decimal needQuantity = originalNeedQuantity; |
| | | #region æ ¹æ®æçå·æ¥æ¾åºå |
| | | //List<Dt_StockInfo> outStocks = _stockService.StockInfoService.Repository.GetStockInfosByPalletCodes(stockSelectViews.Select(x => x.PalletCode).ToList()); |
| | | #endregion |
| | | |
| | | List<Dt_StockInfo> outStocks = _stockService.StockInfoService.Repository.GetStockInfosByPalletCodes(stockSelectViews.Select(x => x.PalletCode).ToList()); |
| | | decimal assignQuantity = 0; |
| | | outStocks.ForEach(x => |
| | | { |
| | | x.Details.ForEach(v => |
| | | { |
| | | assignQuantity += v.StockQuantity - v.OutboundQuantity; |
| | | }); |
| | | }); |
| | | |
| | | |
| | | List<Dt_StockInfoDetail> outStockDetails = _stockService.StockInfoDetailService.GetStockInfosByBatchNoCodes(stockSelectViews); |
| | | |
| | | List<Dt_StockInfo> outStocks = _stockService.StockInfoService.Repository.GetStockInfosByIds(outStockDetails.Select(x => x.StockId).ToList()); |
| | | |
| | | decimal assignQuantity = outStocks.Count; |
| | | #region MyRegion |
| | | //decimal assignQuantity = 0; |
| | | //outStocks.ForEach(x => |
| | | //{ |
| | | // x.Details.ForEach(v => |
| | | // { |
| | | // assignQuantity += v.StockQuantity - v.OutboundQuantity; |
| | | // }); |
| | | //}); |
| | | #endregion |
| | | |
| | | outboundOrderDetail.LockQuantity += assignQuantity; |
| | | outStocks.ForEach(x => |
| | |
| | | }); |
| | | }); |
| | | needQuantity -= assignQuantity; |
| | | #region æå®åºåºæ°éå°äºè®¢åæ°éèªå¨åé
满足æ¡ä»¶åºå |
| | | //if (outboundOrderDetail.OrderQuantity > outboundOrderDetail.LockQuantity) |
| | | //{ |
| | | // List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(outboundOrderDetail.MaterielCode); |
| | | // stockInfos = stockInfos.Where(x => !stockSelectViews.Select(v => v.PalletCode).Contains(x.PalletCode)).ToList(); |
| | | // List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, outboundOrderDetail.MaterielCode, needQuantity, out decimal residueQuantity); |
| | | // outboundOrderDetail.LockQuantity += needQuantity - residueQuantity; |
| | | // outStocks.AddRange(autoAssignStocks); |
| | | // outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.AssignOver.ObjToInt(); |
| | | // if (residueQuantity > 0) |
| | | // { |
| | | // outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.AssignOverPartial.ObjToInt(); |
| | | // } |
| | | //} |
| | | #endregion |
| | | |
| | | #region æªæå®åºåï¼èªå¨åé
åºå |
| | | if (outboundOrderDetail.OrderQuantity > outboundOrderDetail.LockQuantity) |
| | | { |
| | | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(outboundOrderDetail.MaterielCode); |
| | | stockInfos = stockInfos.Where(x => !stockSelectViews.Select(v => v.PalletCode).Contains(x.PalletCode)).ToList(); |
| | | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(outboundOrderDetail.MaterielCode);//è·åææåºå |
| | | |
| | | stockInfos = stockInfos.Where(x => !outStocks.Select(v => v.Id).Contains(x.Id)).ToList(); |
| | | List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, outboundOrderDetail.MaterielCode, needQuantity, out decimal residueQuantity); |
| | | outboundOrderDetail.LockQuantity += needQuantity - residueQuantity; |
| | | outStocks.AddRange(autoAssignStocks); |
| | | outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.AssignOver.ObjToInt(); |
| | | if (residueQuantity > 0) |
| | | { |
| | | outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.AssignOverPartial.ObjToInt(); |
| | | } |
| | | //outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.AssignOver.ObjToInt(); |
| | | //if (residueQuantity > 0) |
| | | //{ |
| | | // outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.AssignOverPartial.ObjToInt(); |
| | | //} |
| | | } |
| | | #endregion |
| | | |
| | | outboundOrderDetail.OrderDetailStatus = outboundOrderDetail.OrderQuantity > outboundOrderDetail.LockQuantity ? OrderDetailStatusEnum.AssignOverPartial.ObjToInt() : OrderDetailStatusEnum.AssignOver.ObjToInt(); |
| | | |
| | | |
| | | //æ·»å åºåºåé
详æ
|
| | | List<Dt_OutStockLockInfo> outStockLockInfos = _outStockLockInfoService.GetOutStockLockInfos(outboundOrder, outboundOrderDetail, outStocks); |
| | | |
| | | List<Dt_LocationInfo> locationInfos = _basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList()); |
| | | |
| | | return (outStocks, outboundOrderDetail, outStockLockInfos, locationInfos); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå®åºåéå®åºå |
| | | /// </summary> |
| | | /// <param name="orderDetailId"></param> |
| | | /// <param name="stockSelectViews"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent LockOutboundStock(int orderDetailId, List<StockSelectViewDTO> stockSelectViews) |
| | | { |
| | | try |
| | |
| | | Dt_OutboundOrderDetail outboundOrderDetail = BaseDal.QueryFirst(x => x.Id == orderDetailId); |
| | | (bool, string) checkResult = CheckSelectStockDeital(outboundOrderDetail, stockSelectViews); |
| | | if (!checkResult.Item1) throw new Exception(checkResult.Item2); |
| | | |
| | | //åé
åºåºåºå |
| | | (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = AssignStockOutbound(outboundOrderDetail, stockSelectViews); |
| | | |
| | | _unitOfWorkManage.BeginTran(); |
| | |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// éå®åºå |
| | | /// éå®åºå//䏿å®åºåéå®åºå |
| | | /// </summary> |
| | | /// <param name="keys"></param> |
| | | /// <returns></returns> |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éå®åºåºååºåæ°æ®ä¿®æ¹ |
| | | /// </summary> |
| | | /// <param name="stockInfos"></param> |
| | | /// <param name="outboundOrderDetails"></param> |
| | | /// <param name="outStockLockInfos"></param> |
| | | /// <param name="locationInfos"></param> |
| | | /// <param name="locationStatus"></param> |
| | | /// <param name="tasks"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent LockOutboundStockDataUpdate(List<Dt_StockInfo> stockInfos, List<Dt_OutboundOrderDetail> outboundOrderDetails, List<Dt_OutStockLockInfo> outStockLockInfos, List<Dt_LocationInfo> locationInfos, LocationStatusEnum locationStatus = LocationStatusEnum.Lock, List<Dt_Task>? tasks = null) |
| | | { |
| | | try |
| | | { |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfos); |
| | | #region ä¿®æ¹åºåååºå详æ
|
| | | List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>(); |
| | | foreach (var item in stockInfos) |
| | | { |
| | | if (item.StockStatus != StockStatusEmun.ç§»åºä¸.ObjToInt()) |
| | | { |
| | | item.StockStatus = locationStatus == LocationStatusEnum.InStock |
| | | ? StockStatusEmun.å·²å
¥åº.ObjToInt() : StockStatusEmun.åºåºéå®.ObjToInt(); |
| | | item.Details.ForEach(x => |
| | | { |
| | | x.Status = item.StockStatus; |
| | | }); |
| | | } |
| | | stockInfoDetails.AddRange(item.Details); |
| | | } |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfos); |
| | | _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetails); |
| | | BaseDal.UpdateData(outboundOrderDetails); |
| | | |
| | | #endregion |
| | | #region ä¿®æ¹åºåºåååºåºå详æ
|
| | | List<Dt_OutboundOrder> outboundOrders = _outboundRepository.OutboundOrderRepository.GetStockInfos(outboundOrderDetails.Select(x => x.OrderId).ToList()); |
| | | |
| | | foreach (var item in outboundOrderDetails) |
| | | { |
| | | var outboundOrder = outboundOrders.Where(x => x.Id == item.OrderId).FirstOrDefault(); |
| | | outboundOrder.Details.RemoveAll(x => x.Id == item.Id); |
| | | outboundOrder.Details.Add(item); |
| | | outboundOrder.OrderStatus = outboundOrder.Details.FirstOrDefault |
| | | (x => x.OrderDetailStatus != OrderDetailStatusEnum.New.ObjToInt()) != null |
| | | ? OutboundStatusEnum.åºåºä¸.ObjToInt() : OutboundStatusEnum.æªå¼å§.ObjToInt(); |
| | | //var outboundOrder = _outboundRepository.OutboundOrderRepository.QueryFirst(x => x.Id == item.OrderId); |
| | | //if (!outboundOrders.Any(x => x.Id == item.OrderId)) |
| | | //{ |
| | | // var outboundOrder = _outboundRepository.OutboundOrderRepository.GetStockInfo(item.OrderId); |
| | | // if (outboundOrder != null) |
| | | // { |
| | | // outboundOrder.Details.RemoveAll(x => x.Id == item.Id); |
| | | // outboundOrder.Details.Add(item); |
| | | // outboundOrder.OrderStatus = outboundOrder.Details.FirstOrDefault |
| | | // (x => x.OrderDetailStatus != OrderDetailStatusEnum.New.ObjToInt()) != null |
| | | // ? OutboundStatusEnum.åºåºä¸.ObjToInt() : OutboundStatusEnum.æªå¼å§.ObjToInt(); |
| | | // outboundOrders.Add(outboundOrder); |
| | | // } |
| | | //} |
| | | } |
| | | _outboundRepository.OutboundOrderRepository.UpdateData(outboundOrders); |
| | | BaseDal.UpdateData(outboundOrderDetails); |
| | | #endregion |
| | | |
| | | #region æ·»å åºåºè¯¦æ
|
| | | List<Dt_OutStockLockInfo> addOutStockLockInfos = outStockLockInfos.Where(x => x.Id == 0).ToList(); |
| | | if (addOutStockLockInfos != null && addOutStockLockInfos.Any()) |
| | | { |
| | | _outStockLockInfoService.Repository.AddData(addOutStockLockInfos); |
| | | } |
| | | #endregion |
| | | |
| | | #region ä¿®æ¹åºåºè¯¦æ
|
| | | List<Dt_OutStockLockInfo> updateOutStockLockInfos = outStockLockInfos.Where(x => x.Id > 0).ToList(); |
| | | if (updateOutStockLockInfos != null && updateOutStockLockInfos.Any()) |
| | | { |
| | | _outStockLockInfoService.Repository.UpdateData(updateOutStockLockInfos); |
| | | } |
| | | |
| | | #endregion |
| | | //æ·»å è´§ä½ä¿¡æ¯åæ´ |
| | | _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, locationStatus.ObjToInt(), StockChangeType.Outbound.ObjToInt(), "", tasks?.Select(x => x.TaskNum).ToList()); |
| | | _basicService.LocationInfoService.Repository.UpdateLocationStatus(locationInfos, locationStatus); |
| | | return WebResponseContent.Instance.OK(); |
| | |
| | | } |
| | | return (true, "æå"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¤éåé
|
| | | /// </summary> |
| | | /// <param name="orderDetailId"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent RevokeLockOutboundStock(int orderDetailId) |
| | | { |
| | | Dt_OutboundOrderDetail outboundOrderDetail = BaseDal.QueryFirst(x => x.Id == orderDetailId); |