| | |
| | | using AutoMapper; |
| | | using SqlSugar; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common.CommonEnum; |
| | | using WIDESEA_Common.OrderEnum; |
| | | using WIDESEA_Common.StockEnum; |
| | |
| | | private readonly IRepository<Dt_Task> _taskRepository; |
| | | |
| | | private IStockService _stockService; |
| | | |
| | | private readonly IMaterialUnitService _materialUnitService; |
| | | private readonly IInboundOrderDetailService _inboundOrderDetailService; |
| | | private readonly IRepository<Dt_InboundOrderDetail> _inboundOrderDetailRepository; |
| | | public IRepository<Dt_InboundOrder> Repository => BaseDal; |
| | | |
| | | public InboundOrderService(IRepository<Dt_InboundOrder> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_Task> taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService) : base(BaseDal) |
| | | public InboundOrderService(IRepository<Dt_InboundOrder> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_Task> taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IMaterialUnitService materialUnitService) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | |
| | | _taskRepository = taskRepository; |
| | | _stockService = stockService; |
| | | _inboundOrderDetailService = inboundOrderDetailService; |
| | | _materialUnitService = materialUnitService; |
| | | } |
| | | |
| | | public WebResponseContent ReceiveInboundOrder(List<Dt_InboundOrder> models, int operateType) |
| | | public async Task<WebResponseContent> ReceiveInboundOrder(List<Dt_InboundOrder> models, int operateType) |
| | | { |
| | | try |
| | | { |
| | | return operateType switch |
| | | { |
| | | 1 => AddInboundOrder(models), |
| | | 2 => UpdateInboundOrder(models), |
| | | 1 =>await AddInboundOrder(models), |
| | | 2 => await UpdateInboundOrder(models), |
| | | 3 => DeleteInboundOrder(models), |
| | | |
| | | _ => WebResponseContent.Instance.OK(), |
| | |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent AddInboundOrder(List<Dt_InboundOrder> models) |
| | | public async Task<WebResponseContent> AddInboundOrder(List<Dt_InboundOrder> models) |
| | | { |
| | | try |
| | | { |
| | |
| | | |
| | | foreach (var model in models) |
| | | { |
| | | foreach (var item in model.Details) |
| | | { |
| | | var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync(item.MaterielCode, item.BarcodeQty); |
| | | item.Unit= purchaseToStockResult.Unit; |
| | | item.OrderQuantity=purchaseToStockResult.Quantity; |
| | | } |
| | | |
| | | model.InboundOrderNo = CreateCodeByRule(nameof(RuleCodeEnum.InboundOrderRule)); |
| | | Db.InsertNav(model).Include(x => x.Details).ExecuteCommand(); |
| | | } |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | public WebResponseContent UpdateInboundOrder(List<Dt_InboundOrder> models) |
| | | public async Task<WebResponseContent> UpdateInboundOrder(List<Dt_InboundOrder> models) |
| | | { |
| | | try |
| | | { |
| | |
| | | BarcodeQty = item.BarcodeQty, |
| | | OrderQuantity = item.OrderQuantity |
| | | }; |
| | | var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync(item.MaterielCode, item.BarcodeQty); |
| | | inboundOrderDetail.Unit = purchaseToStockResult.Unit; |
| | | inboundOrderDetail.OrderQuantity = purchaseToStockResult.Quantity; |
| | | |
| | | inboundOrderDetails.Add(inboundOrderDetail); |
| | | } |
| | | else |
| | |
| | | |
| | | var dbinboundOrderDetails = _inboundOrderDetailService.GetByBarcode(materielGroupDTO.Barcodes); |
| | | |
| | | if (dbinboundOrderDetails != null && !dbinboundOrderDetails.Any()) { |
| | | if (dbinboundOrderDetails != null && !dbinboundOrderDetails.Any()) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"忮䏿²¡æè¯¥{materielGroupDTO.Barcodes}æ¡ç æ°æ®ã"); |
| | | } |
| | | |
| | |
| | | Barcode = item.Barcode, |
| | | MaterielCode = item.MaterielCode, |
| | | BatchNo = item.BatchNo, |
| | | Unit = item.BarcodeUnit, |
| | | Unit = item.Unit, |
| | | InboundOrderRowNo = item.lineNo, |
| | | SupplyCode = item.SupplyCode, |
| | | WarehouseCode = item.WarehouseCode, |
| | | StockQuantity = item.BarcodeQty, |
| | | StockQuantity = item.OrderQuantity, |
| | | Status = 0, |
| | | OrderNo = inboundOrder.InboundOrderNo, |
| | | BusinessType=inboundOrder.BusinessType, |
| | | BusinessType = inboundOrder.BusinessType, |
| | | }); |
| | | |
| | | item.ReceiptQuantity = item.BarcodeQty; |
| | |
| | | stockInfo.PalletCode = materielGroupDTO.PalletCode; |
| | | stockInfo.StockStatus = StockStatusEmun.ç»çæå.ObjToInt(); |
| | | } |
| | | |
| | | stockInfo.PalletType = (int)PalletTypeEnum.None; |
| | | |
| | | List<int> updateDetailIds = dbinboundOrderDetails.Select(x => x.Id).ToList(); |
| | | if (inboundOrder.OrderStatus == InOrderStatusEnum.æªå¼å§.ObjToInt()) |
| | |
| | | (bool, string, object?) result2 = ModelValidate.ValidateModelData(materielGroupDTO); |
| | | if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2); |
| | | |
| | | |
| | | |
| | | Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(materielGroupDTO.PalletCode); |
| | | if (stockInfo != null && !string.IsNullOrEmpty(stockInfo.LocationCode) && stockInfo.StockStatus != StockStatusEmun.ç»çæå.ObjToInt()) |
| | | { |
| | |
| | | stockInfo.StockStatus = StockStatusEmun.ç»çæå.ObjToInt(); |
| | | } |
| | | |
| | | _unitOfWorkManage.BeginTran(); |
| | | _unitOfWorkManage.BeginTran(); |
| | | |
| | | _stockService.StockInfoService.AddMaterielGroup(stockInfo); |
| | | _unitOfWorkManage.CommitTran(); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |