| | |
| | | using AutoMapper; |
| | | using MailKit.Search; |
| | | 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; |
| | | using WIDESEA_IOutboundService; |
| | |
| | | private readonly IStockInfoService _stockInfoService; |
| | | private readonly IStockInfoRepository _stockInfoRepository; |
| | | public IOutboundOrderRepository Repository => BaseDal; |
| | | private readonly IInvokeERPService _invokeERPService; |
| | | private readonly IOutStockLockInfoService _outStockLockInfoService; |
| | | |
| | | public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper,IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IStockInfoService stockInfoService, |
| | | IStockInfoRepository stockInfoRepository) : base(BaseDal) |
| | | IStockInfoRepository stockInfoRepository, IInvokeERPService invokeERPService, IOutStockLockInfoService outStockLockInfoService) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage=unitOfWorkManage; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _basicService = basicService; |
| | | _outboundOrderDetailRepository = outboundOrderDetailRepository; |
| | | _stockInfoService = stockInfoService; |
| | | _stockInfoRepository= stockInfoRepository; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _invokeERPService = invokeERPService; |
| | | _outStockLockInfoService = outStockLockInfoService; |
| | | } |
| | | |
| | | 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 |
| | | }; |
| | | //ERPä¸ä¼ æµè¯ä»é¢æåæ´æ°å¯¹åºåºåç¶æ |
| | | if (warehouse.WarehouseId == 1) |
| | | { |
| | | //è·ååºåºååºå |
| | | 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(); |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | if (stockInfo != null) |
| | | { |
| | | _stockInfoRepository.UpdateData(stockInfo); |
| | | } |
| | | _outboundOrderDetailRepository.AddData(outboundOrderDetail); |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | } |
| | | else |
| | |
| | | OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | OrderQuantity = model.Qty, |
| | | }; |
| | | |
| | | Dt_OutboundOrder outboundOrder = new Dt_OutboundOrder() |
| | | { |
| | | OrderNo=model.OrderNo, |
| | | UpperOrderNo = model.OrderNo, |
| | | OrderStatus = OutOrderStatusEnum.æªå¼å§.ObjToInt(), |
| | | OrderType = OutOrderTypeEnum.Issue.ObjToInt(), |
| | | CreateType = OrderCreateTypeEnum.UpperSystemPush.ObjToInt(), |
| | | WarehouseId = warehouse.WarehouseId, |
| | | DepartmentCode = model.DepartmentCode, |
| | | DepartmentName = model.DepartmentName, |
| | | Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail } |
| | | }; |
| | | Dt_StockInfo? stockInfo = null; |
| | | //ERPä¸ä¼ æµè¯ä»é¢æåæ´æ°å¯¹åºåºåç¶æ |
| | | if (warehouse.WarehouseId==1) |
| | | { |
| | | //è·ååºåºååºå |
| | | 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(); |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | if (stockInfo!=null) |
| | | { |
| | | _stockInfoRepository.UpdateData(stockInfo); |
| | | } |
| | | Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | } |
| | | else if (model.Way == 2) |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent ReleaseOutOrder(int id) |
| | | //䏿¥åºåºå®æ æµè¯æ¶ |
| | | public WebResponseContent TestOutUpload(int id) |
| | | { |
| | | try |
| | | { |
| | | Dt_OutboundOrder outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == id).Includes(x => x.Details).First(); |
| | | if (outboundOrder == null) |
| | | Dt_OutboundOrder outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x=>x.Id==id).Includes(x=>x.Details).First(); |
| | | Dt_Warehouse warehouse = _basicService.WarehouseService.Repository.QueryFirst(x => x.WarehouseId == outboundOrder.WarehouseId); |
| | | //æµè¯æ¶åºç»ERP䏿¥åºåºå®æ |
| | | ERPPickItemModel eRPOutPick = new ERPPickItemModel() |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥åºåºå"); |
| | | } |
| | | if(outboundOrder.Details == null || outboundOrder.Details.Count == 0) |
| | | Lotno = "20241227001", |
| | | Qty = "1", |
| | | Location = warehouse.WarehouseCode |
| | | }; |
| | | ERPPickModel pickModel = new ERPPickModel() |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°æç»ä¿¡æ¯"); |
| | | } |
| | | Rowindex = outboundOrder.Details[0].RowNo, |
| | | Material = outboundOrder.Details[0].MaterielCode, |
| | | Qty = (outboundOrder.Details[0].OrderQuantity.ObjToInt()).ToString(), |
| | | Dataitem=new List<ERPPickItemModel> { eRPOutPick } |
| | | }; |
| | | |
| | | ERPIssueItemModel issueItemModel = new ERPIssueItemModel() |
| | | { |
| | | Pickcode = outboundOrder.UpperOrderNo, |
| | | PickList = new List<ERPPickModel>() { pickModel } |
| | | }; |
| | | ERPIssueModel issueModel = new ERPIssueModel() |
| | | { |
| | | UniqueTag = id.ToString(), |
| | | Code = "FL20241227001",//æµè¯ |
| | | WarehouseCode = warehouse.WarehouseCode, |
| | | Docremark = "", |
| | | Deptno = outboundOrder.DepartmentCode, |
| | | Deptname = outboundOrder.DepartmentName, |
| | | Createtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | Createuser = "TC20082", |
| | | Issitem = new List<ERPIssueItemModel>() { issueItemModel }, |
| | | }; |
| | | string response = _invokeERPService.InvokeOutStandardsApi(issueModel); |
| | | ErpRequestContent requestContent = response.DeserializeObject<ErpRequestContent>(); |
| | | if (requestContent.res == 1) |
| | | { |
| | | |
| | | foreach (var item in outboundOrder.Details) |
| | | { |
| | | return WebResponseContent.Instance.OK(requestContent.Data); |
| | | } |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | else |
| | | { |
| | | return WebResponseContent.Instance.Error(requestContent.Data); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | 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).Includes(x => x.Details).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(int id,List<string> locationIds) |
| | | //{ |
| | | // try |
| | | // { |
| | | |
| | | // string response = _invokeERPService.InvokeOutStandardsApi(issueModel); |
| | | // 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) |
| | | //{ |
| | | // ERPPickItemModel |
| | | //} |
| | | } |
| | | } |