| | |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.CodeConfigEnum; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_Core.Utilities; |
| | | using WIDESEA_DTO.Basic; |
| | | using WIDESEA_DTO.ERP; |
| | | using WIDESEA_DTO.Inbound; |
| | | using WIDESEA_DTO.Outbound; |
| | |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IBasicService _basicService; |
| | | private readonly IOutboundOrderDetailRepository _outboundOrderDetailRepository; |
| | | private readonly IStockInfoService _stockInfoService; |
| | | private readonly IStockInfoRepository _stockInfoRepository; |
| | | private readonly IStockService _stockService; |
| | | public IOutboundOrderRepository Repository => BaseDal; |
| | | private readonly IInvokeERPService _invokeERPService; |
| | | private readonly IOutStockLockInfoService _outStockLockInfoService; |
| | | private readonly IOutboundOrderRepository _outboundOrderRepository; |
| | | |
| | | public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IStockInfoService stockInfoService, |
| | | IStockInfoRepository stockInfoRepository, IInvokeERPService invokeERPService, IOutStockLockInfoService outStockLockInfoService, |
| | | public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IStockService stockService, IInvokeERPService invokeERPService, IOutStockLockInfoService outStockLockInfoService, |
| | | IOutboundOrderRepository outboundOrderRepository) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _basicService = basicService; |
| | | _outboundOrderDetailRepository = outboundOrderDetailRepository; |
| | | _stockInfoService = stockInfoService; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _stockService = stockService; |
| | | _invokeERPService = invokeERPService; |
| | | _outStockLockInfoService = outStockLockInfoService; |
| | | _outboundOrderRepository = outboundOrderRepository; |
| | |
| | | saveModel.DetailData[0].Add("orderDetailStatus", OrderDetailStatusEnum.New.ObjToInt()); |
| | | return base.AddData(saveModel); |
| | | } |
| | | /// <summary> |
| | | /// è·ååºåºåä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="saveModel"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent GetOutboundOrders(SaveModel saveModel) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public WebResponseContent outpinku(SaveModel saveModel) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var orderNo = saveModel.MainData["orderNo"].ToString(); |
| | | var warehouseId = saveModel.MainData["warehouseId"].ObjToInt(); |
| | | var serNum = saveModel.MainData["sn"].ToString(); |
| | | Dt_Warehouse warehouse = _basicService.WarehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId); |
| | | if (warehouse == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ä»åºä¿¡æ¯"); |
| | | } |
| | | |
| | | Dt_OutboundOrder outboundOrder = BaseDal.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == orderNo && x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).First(); |
| | | if (outboundOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°åºåºåä¿¡æ¯"); |
| | | } |
| | | if (outboundOrder.Details == null || outboundOrder.Details.Count <= 0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°åºåºåæç»ä¿¡æ¯"); |
| | | } |
| | | |
| | | MatSerNumAnalysisModel model = CodeAnalysisHelper.CodeAnalysis<MatSerNumAnalysisModel>(AnalysisCodeEnum.MatSerNumAnalysis, serNum); |
| | | Dt_MaterielInfo materielInfo = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == model.MaterielCode); |
| | | if (materielInfo == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ç©æçä¿¡æ¯"); |
| | | } |
| | | if (materielInfo.WarehouseId != outboundOrder.WarehouseId) |
| | | { |
| | | return WebResponseContent.Instance.Error($"è¯¥ç©æä¸å±äºæ¬ä»"); |
| | | } |
| | | |
| | | Dt_OutboundOrderDetail outboundOrderDetail = outboundOrder.Details.FirstOrDefault(x => x.MaterielCode == model.MaterielCode); |
| | | if (outboundOrderDetail == null) return WebResponseContent.Instance.Error($"è¯¥ç©æä¸å±äºæ¬åºåºå"); |
| | | if (outboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()) |
| | | return WebResponseContent.Instance.Error($"æ¬åºåºåå½åç©æå·²åºåºå®æ"); |
| | | |
| | | if (outboundOrderDetail.OrderQuantity - outboundOrderDetail.OverOutQuantity < model.Quantity) |
| | | return WebResponseContent.Instance.Error($"åºåºæ°éè¶
åºåºåºå"); |
| | | |
| | | Dt_StockInfoDetail stockInfoDetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.MaterielCode == model.MaterielCode && x.BatchNo == model.LotNo); |
| | | |
| | | if (stockInfoDetail == null) return WebResponseContent.Instance.Error($"æªæ¾å°åºå"); |
| | | if (stockInfoDetail.StockQuantity < model.Quantity) return WebResponseContent.Instance.Error($"åºåä¸è¶³"); |
| | | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.Id == stockInfoDetail.StockId); |
| | | if (stockInfo == null) return WebResponseContent.Instance.Error($"æªæ¾å°åºå主表"); |
| | | if (stockInfo.LocationCode != "å¹³åºä½") return WebResponseContent.Instance.Error($"åºåä¸å±äºå¹³åºä½"); |
| | | |
| | | Dt_OutStockLockInfo outStockLockInfo = new Dt_OutStockLockInfo() |
| | | { |
| | | PalletCode = stockInfo.PalletCode, |
| | | AssignQuantity = model.Quantity, |
| | | MaterielCode = model.MaterielCode, |
| | | BatchNo = model.LotNo, |
| | | LocationCode = stockInfo.LocationCode, |
| | | MaterielName = materielInfo.MaterielName, |
| | | OrderDetailId = outboundOrderDetail.Id, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | OrderType = outboundOrder.OrderType, |
| | | OriginalQuantity = stockInfoDetail.StockQuantity, |
| | | Status = OutLockStockStatusEnum.åºåºå®æ.ObjToInt(), |
| | | StockId = stockInfo.Id, |
| | | TaskNum = 0, |
| | | OrderQuantity = outboundOrderDetail.OrderQuantity, |
| | | Unit = outboundOrderDetail.Unit |
| | | }; |
| | | |
| | | #region ä¿®æ¹åºåºå |
| | | outboundOrderDetail.OverOutQuantity += outStockLockInfo.AssignQuantity; |
| | | if (outboundOrderDetail.OrderQuantity > outboundOrderDetail.OverOutQuantity) |
| | | outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt(); |
| | | else |
| | | outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt(); |
| | | int overCount = outboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count(); |
| | | if (outboundOrder.Details.Count == overCount) outboundOrder.OrderStatus = OutOrderStatusEnum.åºåºå®æ.ObjToInt(); |
| | | #endregion |
| | | |
| | | #region ä¿®æ¹åºå |
| | | stockInfoDetail.StockQuantity -= stockInfoDetail.StockQuantity - outStockLockInfo.AssignQuantity; |
| | | #endregion |
| | | |
| | | |
| | | _unitOfWorkManage.BeginTran(); |
| | | _outStockLockInfoService.Repository.AddData(outStockLockInfo); |
| | | BaseDal.UpdateData(outboundOrder); |
| | | _outboundOrderDetailRepository.UpdateData(outboundOrderDetail); |
| | | if (stockInfoDetail.StockQuantity > 0) |
| | | { |
| | | _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail); |
| | | } |
| | | else |
| | | { |
| | | _stockService.StockInfoDetailService.Repository.DeleteData(stockInfoDetail); |
| | | if (stockInfo.Details.Count <= 1) _stockService.StockInfoService.Repository.DeleteData(stockInfo); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | #region åºåºå®æä¸æ¥ERP |
| | | ERPPickItemModel pickItemModel = new ERPPickItemModel() |
| | | { |
| | | Lotno = model.LotNo, |
| | | Qty = model.Quantity.ToString(), |
| | | Location = warehouse.WarehouseCode |
| | | }; |
| | | ERPPickModel pickModel = new ERPPickModel() |
| | | { |
| | | Rowindex = outboundOrderDetail.RowNo, |
| | | Material = outboundOrderDetail.MaterielCode, |
| | | Qty = pickItemModel.Qty, |
| | | Dataitem = new List<ERPPickItemModel> { pickItemModel } |
| | | }; |
| | | List<ERPPickModel> eRPPickModels = new List<ERPPickModel>() { pickModel }; |
| | | ERPIssueItemModel issueItemModel = new ERPIssueItemModel() |
| | | { |
| | | Pickcode = outboundOrder.UpperOrderNo, |
| | | PickList = eRPPickModels |
| | | }; |
| | | ERPIssueModel issueModel = new ERPIssueModel() |
| | | { |
| | | UniqueTag = outboundOrderDetail.OrderId.ToString(), |
| | | Code = outboundOrder.OrderNo, |
| | | WarehouseCode = warehouse.WarehouseCode, |
| | | Docremark = "", |
| | | Deptno = outboundOrder.DepartmentCode, |
| | | Deptname = outboundOrder.DepartmentName, |
| | | Createtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | Createuser = App.User.UserName, |
| | | Issitem = new List<ERPIssueItemModel>() { issueItemModel }, |
| | | }; |
| | | _invokeERPService.InvokeOutStandardsApi(issueModel); |
| | | #endregion |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public WebResponseContent ReceiveOutOrder(ErpOutOrderDTO model) |
| | | { |
| | | try |
| | |
| | | |
| | | if (stockInfos.Count > 0) |
| | | { |
| | | _stockInfoRepository.UpdateData(stockInfos); |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfos); |
| | | } |
| | | else |
| | | { |
| | |
| | | try |
| | | { |
| | | //è·ååºåºååºå |
| | | List<Dt_StockInfo> stockInfos = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).ToList(); |
| | | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.Repository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).ToList(); |
| | | if (stockInfos.Count <= 0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"åºåä¸è¶³"); |