| | |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.Stock; |
| | | using WIDESEA_IBasicRepository; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_IOutboundRepository; |
| | | using WIDESEA_IOutboundService; |
| | | using WIDESEA_IRecordService; |
| | | using WIDESEA_IStockRepository; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | |
| | | public class OutboundOrderDetailService : ServiceBase<Dt_OutboundOrderDetail, IOutboundOrderDetailRepository>, IOutboundOrderDetailService |
| | | { |
| | | private readonly IStockInfoService _stockInfoService; |
| | | private readonly IStockInfoRepository _stockInfoRepository; |
| | | private readonly IStockInfoDetailService _stockInfoDetailService; |
| | | private readonly IOutStockLockInfoService _outStockLockInfoService; |
| | | private readonly IOutboundOrderRepository _outboundOrderRepository; |
| | | private readonly IStockInfoDetailRepository _stockInfoDetailRepository; |
| | | private readonly IOutStockLockInfoRepository _outStockLockInfoRepository; |
| | | private readonly ILocationInfoRepository _locationInfoRepository; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly ILocationStatusChangeRecordSetvice _locationStatusChangeRecordSetvice; |
| | | private readonly IOutboundOrderService _outboundOrderService; |
| | | private readonly ILocationInfoService _locationInfoService; |
| | | |
| | | public OutboundOrderDetailService(IOutboundOrderDetailRepository BaseDal, IStockInfoService stockInfoService, IStockInfoRepository stockInfoRepository, IOutStockLockInfoService outStockLockInfoService, IOutboundOrderRepository outboundOrderRepository, IStockInfoDetailRepository stockInfoDetailRepository, IOutStockLockInfoRepository outStockLockInfoRepository, ILocationInfoRepository locationInfoRepository, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal) |
| | | public IOutboundOrderDetailRepository Repository => BaseDal; |
| | | |
| | | public OutboundOrderDetailService(IOutboundOrderDetailRepository BaseDal, IStockInfoService stockInfoService, IOutStockLockInfoService outStockLockInfoService, IUnitOfWorkManage unitOfWorkManage, ILocationStatusChangeRecordSetvice locationStatusChangeRecordSetvice, IOutboundOrderService outboundOrderService, ILocationInfoService locationInfoService, IStockInfoDetailService stockInfoDetailService) : base(BaseDal) |
| | | { |
| | | _stockInfoService = stockInfoService; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _outStockLockInfoService = outStockLockInfoService; |
| | | _outboundOrderRepository = outboundOrderRepository; |
| | | _stockInfoDetailRepository = stockInfoDetailRepository; |
| | | _outStockLockInfoRepository = outStockLockInfoRepository; |
| | | _locationInfoRepository = locationInfoRepository; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _locationStatusChangeRecordSetvice = locationStatusChangeRecordSetvice; |
| | | _outboundOrderService = outboundOrderService; |
| | | _locationInfoService = locationInfoService; |
| | | _stockInfoDetailService = stockInfoDetailService; |
| | | } |
| | | // |
| | | public WebResponseContent LockOutboundStock(int orderDetailId) |
| | |
| | | return (true, "æå"); |
| | | } |
| | | |
| | | public (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(int orderDetailId, List<StockSelectViewDTO> stockSelectViews) |
| | | public (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(Dt_OutboundOrderDetail outboundOrderDetail, List<StockSelectViewDTO> stockSelectViews) |
| | | { |
| | | Dt_OutboundOrderDetail outboundOrderDetail = BaseDal.QueryFirst(x => x.Id == orderDetailId); |
| | | (bool, string) result = CheckSelectStockDeital(outboundOrderDetail, stockSelectViews); |
| | | if (!result.Item1) throw new Exception(result.Item2); |
| | | (bool, string) checkResult = CheckSelectStockDeital(outboundOrderDetail, stockSelectViews); |
| | | if (!checkResult.Item1) throw new Exception(checkResult.Item2); |
| | | |
| | | Dt_OutboundOrder outboundOrder = _outboundOrderRepository.QueryFirst(x => x.Id == outboundOrderDetail.OrderId); |
| | | Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetail.OrderId); |
| | | decimal originalNeedQuantity = outboundOrderDetail.OrderQuantity - outboundOrderDetail.LockQuantity; |
| | | |
| | | decimal needQuantity = originalNeedQuantity; |
| | | |
| | | List<Dt_StockInfo> outStocks = _stockInfoRepository.GetStockInfosByPalletCodes(stockSelectViews.Select(x => x.PalletCode).ToList()); |
| | | decimal assignQuantity = stockSelectViews.Sum(x => x.UseableQuantity); |
| | | List<Dt_StockInfo> outStocks = _stockInfoService.Repository.GetStockInfosByPalletCodes(stockSelectViews.Select(x => x.PalletCode).ToList()); |
| | | decimal assignQuantity = 0; |
| | | outStocks.ForEach(x => |
| | | { |
| | | x.Details.ForEach(v => |
| | | { |
| | | assignQuantity += v.StockQuantity - v.OutboundQuantity; |
| | | }); |
| | | }); |
| | | |
| | | outboundOrderDetail.LockQuantity += assignQuantity; |
| | | outStocks.ForEach(x => |
| | | { |
| | |
| | | |
| | | List<Dt_OutStockLockInfo> outStockLockInfos = _outStockLockInfoService.GetOutStockLockInfos(outboundOrder, outboundOrderDetail, outStocks); |
| | | |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoRepository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList()); |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList()); |
| | | |
| | | return (outStocks, outboundOrderDetail, outStockLockInfos, locationInfos); |
| | | } |
| | |
| | | { |
| | | try |
| | | { |
| | | (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = AssignStockOutbound(orderDetailId, stockSelectViews); |
| | | 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(); |
| | | WebResponseContent content = LockOutboundStockDataUpdate(result.Item1, result.Item2, result.Item3, result.Item4); |
| | | WebResponseContent content = LockOutboundStockDataUpdate(result.Item1, new List<Dt_OutboundOrderDetail> { result.Item2 }, result.Item3, result.Item4); |
| | | if (content.Status) |
| | | { |
| | | _unitOfWorkManage.CommitTran(); |
| | |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent LockOutboundStockDataUpdate(List<Dt_StockInfo> stockInfos, Dt_OutboundOrderDetail outboundOrderDetail, List<Dt_OutStockLockInfo> outStockLockInfos, List<Dt_LocationInfo> locationInfos, LocationStatusEnum locationStatus = LocationStatusEnum.Lock) |
| | | public WebResponseContent LockOutboundStock(int[] keys) |
| | | { |
| | | try |
| | | { |
| | | _stockInfoRepository.UpdateData(stockInfos); |
| | | List<StockSelectViewDTO> stockSelectViews = new List<StockSelectViewDTO>(); |
| | | List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>(); |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>(); |
| | | List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); |
| | | List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); |
| | | foreach (var item in keys) |
| | | { |
| | | Dt_OutboundOrderDetail outboundOrderDetail = BaseDal.QueryFirst(x => x.Id == item); |
| | | (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); |
| | | if (result.Item1.Count > 0) |
| | | { |
| | | stockInfos.AddRange(result.Item1); |
| | | outboundOrderDetails.Add(result.Item2); |
| | | outStockLockInfos.AddRange(result.Item3); |
| | | locationInfos.AddRange(result.Item4); |
| | | } |
| | | } |
| | | |
| | | _unitOfWorkManage.BeginTran(); |
| | | WebResponseContent content = LockOutboundStockDataUpdate(stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos); |
| | | if (content.Status) |
| | | { |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | else |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | } |
| | | return content; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | 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 |
| | | { |
| | | _stockInfoService.Repository.UpdateData(stockInfos); |
| | | List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>(); |
| | | foreach (var item in stockInfos) |
| | | { |
| | | stockInfoDetails.AddRange(item.Details); |
| | | } |
| | | _stockInfoDetailRepository.UpdateData(stockInfoDetails); |
| | | BaseDal.UpdateData(outboundOrderDetail); |
| | | _outStockLockInfoRepository.AddData(outStockLockInfos); |
| | | _stockInfoDetailService.Repository.UpdateData(stockInfoDetails); |
| | | BaseDal.UpdateData(outboundOrderDetails); |
| | | |
| | | _locationInfoRepository.UpdateLocationStatus(locationInfos, locationStatus); |
| | | List<Dt_OutStockLockInfo> addOutStockLockInfos = outStockLockInfos.Where(x => x.Id == 0).ToList(); |
| | | if (addOutStockLockInfos != null && addOutStockLockInfos.Any()) |
| | | { |
| | | _outStockLockInfoService.Repository.AddData(addOutStockLockInfos); |
| | | } |
| | | List<Dt_OutStockLockInfo> updateOutStockLockInfos = outStockLockInfos.Where(x => x.Id > 0).ToList(); |
| | | if (updateOutStockLockInfos != null && updateOutStockLockInfos.Any()) |
| | | { |
| | | _outStockLockInfoService.Repository.UpdateData(updateOutStockLockInfos); |
| | | } |
| | | |
| | | _locationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, locationStatus.ObjToInt(), StockChangeType.Outbound.ObjToInt(), "", tasks?.Select(x => x.TaskNum).ToList()); |
| | | _locationInfoService.Repository.UpdateLocationStatus(locationInfos, locationStatus); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | |
| | | (bool, string) result = CheckRevoke(outboundOrderDetail); |
| | | if (!result.Item1) return WebResponseContent.Instance.Error(result.Item2); |
| | | |
| | | List<Dt_OutStockLockInfo> outStockLockInfos = _outStockLockInfoService.GetByOrderDetailId(orderDetailId); |
| | | List<Dt_OutStockLockInfo> outStockLockInfos = _outStockLockInfoService.GetByOrderDetailId(orderDetailId, OutStockStatus.å·²åé
); |
| | | if (outStockLockInfos.Count > 0) |
| | | { |
| | | List<Dt_StockInfo> stocks = _stockInfoRepository.GetStockInfosByPalletCodes(outStockLockInfos.Select(x => x.PalletCode).ToList()); |
| | | List<Dt_StockInfo> stocks = _stockInfoService.Repository.GetStockInfosByPalletCodes(outStockLockInfos.Select(x => x.PalletCode).ToList()); |
| | | if (stocks.Count > 0) |
| | | { |
| | | stocks.ForEach(x => |
| | |
| | | x.Status = OutStockStatus.æ¤é.ObjToInt(); |
| | | }); |
| | | |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoRepository.GetLocationInfos(stocks.Select(x => x.LocationCode).ToList()); |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoService.Repository.GetLocationInfos(stocks.Select(x => x.LocationCode).ToList()); |
| | | |
| | | return LockOutboundStockDataUpdate(stocks, outboundOrderDetail, outStockLockInfos, locationInfos, LocationStatusEnum.InStock); |
| | | return LockOutboundStockDataUpdate(stocks, new List<Dt_OutboundOrderDetail> { outboundOrderDetail }, outStockLockInfos, locationInfos, LocationStatusEnum.InStock); |
| | | } |
| | | return WebResponseContent.Instance.Error("æªæ¾å°åºåä¿¡æ¯"); |
| | | } |