| | |
| | | using AutoMapper; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Serialization; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common.OrderEnum; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Common.WareHouseEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | |
| | | using WIDESEA_DTO.ERP; |
| | | using WIDESEA_DTO.Inbound; |
| | | using WIDESEA_DTO.Outbound; |
| | | using WIDESEA_External.ERPService; |
| | | using WIDESEA_External.Model; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_IOutboundRepository; |
| | |
| | | private readonly IStockInfoService _stockInfoService; |
| | | private readonly IStockInfoRepository _stockInfoRepository; |
| | | public IOutboundOrderRepository Repository => BaseDal; |
| | | private readonly IInvokeERPService _invokeERPService; |
| | | |
| | | public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper,IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IStockInfoService stockInfoService, |
| | | IStockInfoRepository stockInfoRepository) : base(BaseDal) |
| | | IStockInfoRepository stockInfoRepository, IInvokeERPService invokeERPService) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage=unitOfWorkManage; |
| | | _basicService = basicService; |
| | | _outboundOrderDetailRepository = outboundOrderDetailRepository; |
| | | _stockInfoService = stockInfoService; |
| | | _stockInfoRepository= stockInfoRepository; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _invokeERPService = invokeERPService; |
| | | } |
| | | |
| | | public WebResponseContent ReceiveOutOrder(ErpOutOrderDTO model) |
| | |
| | | } |
| | | else |
| | | { |
| | | Dt_StockInfo? stockInfo = null; |
| | | Dt_OutboundOrderDetail outboundOrderDetail = new Dt_OutboundOrderDetail() |
| | | { |
| | | RowNo = Convert.ToInt32(model.RowNo), |
| | |
| | | OrderQuantity = model.Qty, |
| | | OrderId = oldOutboundOrder.Id |
| | | }; |
| | | List<Dt_StockInfo>? stockInfos = new List<Dt_StockInfo>(); |
| | | //ERPä¸ä¼ æµè¯ä»é¢æåæ´æ°å¯¹åºåºåç¶æ |
| | | if (warehouse.WarehouseId == 1) |
| | | if (warehouse.WarehouseCode == WarehouseEnum.HA64.ToString()) |
| | | { |
| | | //è·ååºåºååºå |
| | | stockInfo = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).Where(x => x.Details.Any(x => x.MaterielCode == model.MCode && x.BatchNo == model.MLot && x.InboundOrderRowNo == Convert.ToInt32(model.RowNo))).First(); |
| | | stockInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | WebResponseContent responseContent = TestOutStocksUpdate(warehouse, model); |
| | | if (!responseContent.Status) |
| | | { |
| | | return responseContent; |
| | | } |
| | | stockInfos = responseContent.Data as List<Dt_StockInfo>; |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | if (stockInfo != null) |
| | | if (stockInfos.Count>0) |
| | | { |
| | | _stockInfoRepository.UpdateData(stockInfo); |
| | | _stockInfoRepository.UpdateData(stockInfos); |
| | | //æµè¯æ¶åºç»ERP䏿¥åºåºå®æ |
| | | if (!TestOutBack(stockInfos, warehouse, model).Status) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error($"æµè¯æ¶åºåºä¸æ¥å¤±è´¥"); |
| | | } |
| | | } |
| | | _outboundOrderDetailRepository.AddData(outboundOrderDetail); |
| | | _unitOfWorkManage.CommitTran(); |
| | |
| | | WarehouseId = warehouse.WarehouseId, |
| | | Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail } |
| | | }; |
| | | Dt_StockInfo? stockInfo = null; |
| | | //ERPä¸ä¼ æµè¯ä»é¢æåæ´æ°å¯¹åºåºåç¶æ |
| | | if (warehouse.WarehouseId==1) |
| | | List<Dt_StockInfo>? stockInfos = new List<Dt_StockInfo>(); |
| | | //ERPä¸ä¼ æµè¯ä»é¢æåæ´æ°å¯¹åºåºåç¶æ |
| | | if (warehouse.WarehouseCode == WarehouseEnum.HA64.ToString()) |
| | | { |
| | | //è·ååºåºååºå |
| | | stockInfo = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).Where(x => x.Details.Any(x => x.MaterielCode == model.MCode && x.BatchNo == model.MLot && x.InboundOrderRowNo == Convert.ToInt32(model.RowNo))).First(); |
| | | stockInfo.StockStatus=StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | WebResponseContent responseContent = TestOutStocksUpdate(warehouse, model); |
| | | if (!responseContent.Status) |
| | | { |
| | | return responseContent; |
| | | } |
| | | stockInfos = responseContent.Data as List<Dt_StockInfo>; |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | if (stockInfo!=null) |
| | | if (stockInfos.Count > 0) |
| | | { |
| | | _stockInfoRepository.UpdateData(stockInfo); |
| | | _stockInfoRepository.UpdateData(stockInfos); |
| | | //æµè¯æ¶åºç»ERP䏿¥åºåºå®æ |
| | | if (!TestOutBack(stockInfos, warehouse, model).Status) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error($"æµè¯æ¶åºåºä¸æ¥å¤±è´¥"); |
| | | } |
| | | } |
| | | Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | } |
| | | } |
| | | else if (model.Way == 2) |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ¹åºåºååºåç¶æ |
| | | /// </summary> |
| | | /// <param name="warehouse"></param> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent TestOutStocksUpdate(Dt_Warehouse warehouse, ErpOutOrderDTO model) |
| | | { |
| | | try |
| | | { |
| | | //è·ååºåºååºå |
| | | List<Dt_StockInfo> stockInfos = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).OrderBy(x => x.CreateDate).Includes(x => x.Details).Where(x => x.Details.Any(x => x.MaterielCode == model.MCode)).Take((int)(model.Qty)).ToList(); |
| | | if (model.Qty > stockInfos.Count) |
| | | { |
| | | return WebResponseContent.Instance.Error($"ç©æ:{model.MCode}åºåä¸è¶³"); |
| | | } |
| | | //æ´æ¹ç¶æ |
| | | stockInfos.ForEach(x => |
| | | { |
| | | x.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | }); |
| | | return WebResponseContent.Instance.OK("æå", stockInfos); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | ///æ¨éæµè¯æ¶åºåº |
| | | public WebResponseContent TestOutBack(List<Dt_StockInfo> stockInfos,Dt_Warehouse warehouse, ErpOutOrderDTO model) |
| | | { |
| | | try |
| | | { |
| | | //æµè¯æ¶åºç»ERP䏿¥åºåºå®æ |
| | | List<ERPOutPickDetail> pickDetails = stockInfos.Select(x => new ERPOutPickDetail() |
| | | { |
| | | Lotno = x.Details[0].BatchNo, |
| | | Qty = x.Details[0].StockQuantity |
| | | }).ToList(); |
| | | ERPOutPick outPick = new ERPOutPick() |
| | | { |
| | | Rowindex = model.RowNo, |
| | | Material = model.MCode, |
| | | Qty = model.Qty, |
| | | Dataitem = pickDetails |
| | | }; |
| | | ERPOutboundModel inboundModel = new ERPOutboundModel() |
| | | { |
| | | Way = 1, |
| | | UniqueTag = model.OrderNo, |
| | | Code = model.OrderNo, |
| | | WarehouseCode = warehouse.WarehouseCode, |
| | | Docremark = "", |
| | | Deptno = model.DepartmentCode, |
| | | DeptName = model.DepartmentName, |
| | | Createtime = DateTime.Now, |
| | | Createuser = "WMS", |
| | | Picklist = new List<ERPOutPick>() { outPick }, |
| | | }; |
| | | string response = _invokeERPService.InvokeOutboundOrderApi(inboundModel); |
| | | ErpRequestContent requestContent=response.DeserializeObject<ErpRequestContent>(); |
| | | if (requestContent.res==1) |
| | | { |
| | | |
| | | return WebResponseContent.Instance.OK(requestContent.Data); |
| | | } |
| | | else |
| | | { |
| | | return WebResponseContent.Instance.Error(requestContent.Data); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | //public WebResponseContent FeedbackOutbondIssue(List<Dt_OutStockLockInfo> outStockLockInfos) |
| | | //{ |