| | |
| | | using AutoMapper; |
| | | using MailKit.Search; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Serialization; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | |
| | | using System.Text; |
| | | 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_Core.CodeConfigEnum; |
| | | using WIDESEA_Core.DB; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_Core.Seed; |
| | | using WIDESEA_Core.Utilities; |
| | | using WIDESEA_DTO.Basic; |
| | | 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; |
| | | using WIDESEA_IStockRepository; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | | |
| | |
| | | public class OutboundOrderService : ServiceBase<Dt_OutboundOrder, IOutboundOrderRepository>, IOutboundOrderService |
| | | { |
| | | private readonly IMapper _mapper; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IBasicService _basicService; |
| | | private readonly IOutboundOrderDetailRepository _outboundOrderDetailRepository; |
| | | private readonly IStockInfoService _stockInfoService; |
| | | |
| | | 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, IBasicService basicService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IStockInfoService stockInfoService) : base(BaseDal) |
| | | 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; |
| | | _stockService = stockService; |
| | | _invokeERPService = invokeERPService; |
| | | _outStockLockInfoService = outStockLockInfoService; |
| | | _outboundOrderRepository = outboundOrderRepository; |
| | | } |
| | | public override WebResponseContent AddData(SaveModel saveModel) |
| | | { |
| | | if (saveModel.MainData.TryGetValue(nameof(Dt_OutboundOrder.UpperOrderNo).FirstLetterToLower(), out object? upperOrderNo) && upperOrderNo != null && !string.IsNullOrEmpty(upperOrderNo.ToString())) |
| | | { |
| | | Dt_OutboundOrder outboundOrder = BaseDal.QueryFirst(x => x.UpperOrderNo == upperOrderNo.ToString() && x.WarehouseId == Convert.ToInt32(saveModel.MainData[nameof(Dt_OutboundOrder.WarehouseId).FirstLetterToLower()])); |
| | | if (outboundOrder != null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"{upperOrderNo}颿åå·å·²åå¨"); |
| | | } |
| | | } |
| | | saveModel.DetailData[0].Add("orderDetailStatus", OrderDetailStatusEnum.New.ObjToInt()); |
| | | return base.AddData(saveModel); |
| | | } |
| | | public WebResponseContent GetOutboundOrders(SaveModel saveModel) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | int pageNo = saveModel.MainData["pageNo"].ObjToInt(); |
| | | string? orderNo = saveModel.MainData["orderNo"].ToString(); |
| | | int warehouseId = saveModel.MainData["warehouseId"].ObjToInt(); |
| | | List<Dt_OutboundOrder> dt_ReceiveOrders = new List<Dt_OutboundOrder>(); |
| | | if (string.IsNullOrEmpty(orderNo)) |
| | | { |
| | | dt_ReceiveOrders = Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderStatus < OutLockStockStatusEnum.åºåºå®æ.ObjToInt() && x.WarehouseId == warehouseId).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5); |
| | | } |
| | | else |
| | | { |
| | | dt_ReceiveOrders = Db.Queryable<Dt_OutboundOrder>().Where(x => (x.OrderNo.Contains(orderNo)) && x.OrderStatus < OutLockStockStatusEnum.åºåºå®æ.ObjToInt() && x.WarehouseId == warehouseId).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5); |
| | | } |
| | | |
| | | content.OK(data: dt_ReceiveOrders); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | 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(); |
| | | else |
| | | 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 |
| | | if (outboundOrder.OrderStatus == OutOrderStatusEnum.åºåºå®æ.ObjToInt()) |
| | | _invokeERPService.InvokeOutStandardsApi(GetERPIssueModel(outboundOrder, warehouse.WarehouseCode)); |
| | | #endregion |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | public ERPIssueModel GetERPIssueModel(Dt_OutboundOrder outboundOrder, string WarehouseCode) |
| | | { |
| | | ERPIssueModel issueModel = new ERPIssueModel(); |
| | | try |
| | | { |
| | | List<Dt_OutStockLockInfo> stockLockInfos = _outStockLockInfoService.OutStockLockInfos(outboundOrder.OrderNo); |
| | | List<ERPPickModel> eRPPickModels = new List<ERPPickModel>(); |
| | | foreach (var item in stockLockInfos) |
| | | { |
| | | ERPPickItemModel pickItemModel = new ERPPickItemModel() |
| | | { |
| | | Lotno = item.BatchNo, |
| | | Qty = item.AssignQuantity.ObjToInt().ToString(), |
| | | Location = WarehouseCode |
| | | }; |
| | | //è·ååºåºåæç» |
| | | Dt_OutboundOrderDetail outboundOrderDetail = outboundOrder.Details.FirstOrDefault(x => x.Id == item.OrderDetailId); |
| | | ERPPickModel pickModel = new ERPPickModel() |
| | | { |
| | | Rowindex = outboundOrderDetail.RowNo, |
| | | Material = outboundOrderDetail.MaterielCode, |
| | | Qty = pickItemModel.Qty, |
| | | Dataitem = new List<ERPPickItemModel> { pickItemModel } |
| | | }; |
| | | eRPPickModels.Add(pickModel); |
| | | } |
| | | ERPIssueItemModel issueItemModel = new ERPIssueItemModel() |
| | | { |
| | | Pickcode = outboundOrder.UpperOrderNo, |
| | | PickList = eRPPickModels |
| | | }; |
| | | string Createuser = ""; |
| | | if (!string.IsNullOrEmpty(App.User.UserName)) Createuser = App.User.UserName; |
| | | else Createuser = stockLockInfos.FirstOrDefault().Creater; |
| | | issueModel = new ERPIssueModel() |
| | | { |
| | | UniqueTag = outboundOrder.Id.ToString(), |
| | | Code = CreateCodeByRule(nameof(RuleCodeEnum.FLCodeRule)), |
| | | WarehouseCode = WarehouseCode, |
| | | Docremark = "", |
| | | Deptno = outboundOrder.DepartmentCode, |
| | | Deptname = outboundOrder.DepartmentName, |
| | | Createtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | Createuser = string.IsNullOrEmpty(Createuser) ? Createuser : "admin", |
| | | Issitem = new List<ERPIssueItemModel>() { issueItemModel }, |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | return issueModel; |
| | | } |
| | | public WebResponseContent ReceiveOutOrder(ErpOutOrderDTO model) |
| | | { |
| | | try |
| | |
| | | OrderQuantity = model.Qty, |
| | | OrderId = oldOutboundOrder.Id |
| | | }; |
| | | |
| | | _outboundOrderDetailRepository.AddData(outboundOrderDetail); |
| | | } |
| | | } |
| | |
| | | MaterielName = materielInfo.MaterielName, |
| | | OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | OrderQuantity = model.Qty, |
| | | Unit = materielInfo.MaterielUnit |
| | | }; |
| | | |
| | | Dt_OutboundOrder outboundOrder = new Dt_OutboundOrder() |
| | | { |
| | | UpperOrderNo = model.OrderNo, |
| | |
| | | OrderType = OutOrderTypeEnum.Issue.ObjToInt(), |
| | | CreateType = OrderCreateTypeEnum.UpperSystemPush.ObjToInt(), |
| | | WarehouseId = warehouse.WarehouseId, |
| | | Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail } |
| | | }; |
| | | DepartmentCode = model.DepartmentCode, |
| | | DepartmentName = model.DepartmentName, |
| | | Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail }, |
| | | Remark = model.Node |
| | | |
| | | }; |
| | | Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | } |
| | | } |
| | |
| | | MaterielName = materielInfo.MaterielName, |
| | | OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | OrderQuantity = model.Qty, |
| | | Unit = model.Unit, |
| | | }; |
| | | |
| | | _outboundOrderDetailRepository.UpdateData(outboundOrderDetail); |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent ReleaseOutOrder(int id) |
| | | //䏿¥åºåºå®æ |
| | | public WebResponseContent TestOutUpload(int id, List<Dt_OutStockLockInfo>? outStockLockInfos) |
| | | { |
| | | try |
| | | { |
| | | 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); |
| | | ERPIssueModel issueModel = new ERPIssueModel(); |
| | | List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>(); |
| | | List<Dt_OutStockLockInfo> _OutStockLockInfos = new List<Dt_OutStockLockInfo>(); |
| | | int overCount = outboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count(); |
| | | if (outboundOrder.Details.Count == overCount) |
| | | { |
| | | outboundOrder.OrderStatus = OutOrderStatusEnum.åºåºå®æ.ObjToInt(); |
| | | _outboundOrderRepository.UpdateData(outboundOrder); |
| | | } |
| | | if (outboundOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥åºåºå"); |
| | | return WebResponseContent.Instance.Error("åºåºåä¸åå¨"); |
| | | } |
| | | if(outboundOrder.Details == null || outboundOrder.Details.Count == 0) |
| | | if (outboundOrder.CreateType == OrderCreateTypeEnum.CreateInSystem.ObjToInt()) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°æç»ä¿¡æ¯"); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | //æµè¯æ¶åºç»ERP䏿¥åºåºå®æ |
| | | if (warehouse.WarehouseCode == WarehouseEnum.HA64.ToString()) |
| | | { |
| | | List<ERPPickModel> eRPPicks = new List<ERPPickModel>(); |
| | | foreach (var item in outboundOrder.Details) |
| | | { |
| | | if (item.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()) continue; |
| | | stockInfos = TestOutStocksUpdate(warehouse, item).Data as List<Dt_StockInfo> ?? null; |
| | | if (stockInfos == null) continue; |
| | | List<ERPPickItemModel> eRPOutPick = new List<ERPPickItemModel>(); |
| | | for (int i = 0; i < stockInfos.Count; i++) |
| | | { |
| | | ERPPickItemModel pickItemModel = new ERPPickItemModel() |
| | | { |
| | | Lotno = stockInfos[i].Details[0].BatchNo, |
| | | Qty = stockInfos[i].Details[0].StockQuantity.ObjToInt().ToString(), |
| | | Location = warehouse.WarehouseCode |
| | | }; |
| | | eRPOutPick.Add(pickItemModel); |
| | | } |
| | | |
| | | ERPPickModel pickModel = new ERPPickModel() |
| | | { |
| | | Rowindex = item.RowNo, |
| | | Material = item.MaterielCode, |
| | | Qty = (item.OrderQuantity.ObjToInt()).ToString(), |
| | | Dataitem = eRPOutPick |
| | | }; |
| | | eRPPicks.Add(pickModel); |
| | | } |
| | | ERPIssueItemModel issueItemModel = new ERPIssueItemModel() |
| | | { |
| | | Pickcode = outboundOrder.UpperOrderNo, |
| | | PickList = eRPPicks |
| | | }; |
| | | issueModel = new ERPIssueModel() |
| | | { |
| | | UniqueTag = id.ToString(), |
| | | Code = CreateCodeByRule(nameof(RuleCodeEnum.FLCodeRule)),//æµè¯ |
| | | WarehouseCode = warehouse.WarehouseCode, |
| | | Docremark = "", |
| | | Deptno = outboundOrder.DepartmentCode, |
| | | Deptname = outboundOrder.DepartmentName, |
| | | Createtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | Createuser = outboundOrder.Creater, |
| | | Issitem = new List<ERPIssueItemModel>() { issueItemModel }, |
| | | }; |
| | | _invokeERPService.InvokeOutStandardsApi(issueModel); |
| | | } |
| | | else |
| | | { |
| | | #region MyRegion |
| | | foreach (var item in outStockLockInfos) |
| | | { |
| | | if (item.OrderQuantity == item.AssignQuantity) |
| | | { |
| | | item.Status = OutLockStockStatusEnum.åºåºå®æ.ObjToInt(); |
| | | } |
| | | _OutStockLockInfos.Add(item); |
| | | } |
| | | #endregion |
| | | |
| | | #region MyRegion |
| | | //List<ERPPickModel> eRPPickModels = new List<ERPPickModel>(); |
| | | |
| | | ////è·ååºåºè¯¦æ
å |
| | | //foreach (var item in outStockLockInfos) |
| | | //{ |
| | | // ERPPickItemModel pickItemModel = new ERPPickItemModel() |
| | | // { |
| | | // Lotno = item.BatchNo, |
| | | // Qty = item.AssignQuantity.ObjToInt().ToString(), |
| | | // Location = warehouse.WarehouseCode |
| | | // }; |
| | | // //è·ååºåºåæç» |
| | | // Dt_OutboundOrderDetail outboundOrderDetail = outboundOrder.Details.FirstOrDefault(x => x.Id == item.OrderDetailId); |
| | | // ERPPickModel pickModel = new ERPPickModel() |
| | | // { |
| | | // Rowindex = outboundOrderDetail.RowNo, |
| | | // Material = outboundOrderDetail.MaterielCode, |
| | | // Qty = pickItemModel.Qty, |
| | | // Dataitem = new List<ERPPickItemModel> { pickItemModel } |
| | | // }; |
| | | // if (item.OrderQuantity == item.AssignQuantity) |
| | | // { |
| | | // item.Status = OutLockStockStatusEnum.åºåºå®æ.ObjToInt(); |
| | | // } |
| | | // eRPPickModels.Add(pickModel); |
| | | // _OutStockLockInfos.Add(item); |
| | | //} |
| | | //ERPIssueItemModel issueItemModel = new ERPIssueItemModel() |
| | | //{ |
| | | // Pickcode = outboundOrder.UpperOrderNo, |
| | | // PickList = eRPPickModels |
| | | //}; |
| | | //issueModel = new ERPIssueModel() |
| | | //{ |
| | | // UniqueTag = id.ToString(), |
| | | // Code = CreateCodeByRule(nameof(RuleCodeEnum.FLCodeRule)), |
| | | // WarehouseCode = warehouse.WarehouseCode, |
| | | // Docremark = "", |
| | | // Deptno = outboundOrder.DepartmentCode, |
| | | // Deptname = outboundOrder.DepartmentName, |
| | | // Createtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | // Createuser = outStockLockInfos.FirstOrDefault().Creater, |
| | | // Issitem = new List<ERPIssueItemModel>() { issueItemModel }, |
| | | //}; |
| | | #endregion |
| | | } |
| | | |
| | | foreach (var item in outboundOrder.Details) |
| | | if (stockInfos.Count > 0) |
| | | { |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfos); |
| | | } |
| | | |
| | | else |
| | | { |
| | | _outStockLockInfoService.Repository.UpdateData(_OutStockLockInfos); |
| | | } |
| | | //åºåºå®æä¸æ¥ERP æµè¯æ³¨é |
| | | if (outboundOrder.OrderStatus == OutOrderStatusEnum.åºåºå®æ.ObjToInt()) |
| | | { |
| | | issueModel = GetERPIssueModel(outboundOrder, warehouse.WarehouseCode); |
| | | _invokeERPService.InvokeOutStandardsApi(issueModel); |
| | | } |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | static object lock_code = new object(); |
| | | public string CreateCodeByRule(string ruleCode) |
| | | { |
| | | lock (lock_code) |
| | | { |
| | | |
| | | string code = string.Empty; |
| | | DateTime dateTime = DateTime.Now; |
| | | DateTime now = DateTime.Now; |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(ruleCode)) |
| | | throw new ArgumentNullException(nameof(ruleCode)); |
| | | SqlSugarClient sugarClient = new SqlSugarClient(new ConnectionConfig |
| | | { |
| | | IsAutoCloseConnection = false, |
| | | DbType = DbType.SqlServer, |
| | | ConnectionString = DBContext.ConnectionString |
| | | }); |
| | | Dt_CodeRuleConfig codeRuleConfig = sugarClient.Queryable<Dt_CodeRuleConfig>().Where(x => x.RuleCode == ruleCode).First(); |
| | | if (codeRuleConfig == null) |
| | | throw new ArgumentNullException(nameof(codeRuleConfig)); |
| | | if (codeRuleConfig.ModifyDate != null) |
| | | { |
| | | dateTime = Convert.ToDateTime(codeRuleConfig.ModifyDate); |
| | | } |
| | | else |
| | | { |
| | | dateTime = Convert.ToDateTime(codeRuleConfig.CreateDate); |
| | | } |
| | | |
| | | if (now.Year == dateTime.Year && now.Month == dateTime.Month && now.Day == dateTime.Day) |
| | | { |
| | | now = dateTime; |
| | | codeRuleConfig.CurrentVal = Convert.ToInt32(codeRuleConfig.CurrentVal) + 1; |
| | | } |
| | | else |
| | | { |
| | | codeRuleConfig.CurrentVal = 1; |
| | | } |
| | | codeRuleConfig.ModifyDate = DateTime.Now; |
| | | code = codeRuleConfig.Format; |
| | | code = code.Replace($"[{CodeFormatTypeEnum.YYYY}]", now.Year.ToString().PadLeft(4, '0')); |
| | | code = code.Replace($"[{CodeFormatTypeEnum.MM}]", now.Month.ToString().PadLeft(2, '0')); |
| | | code = code.Replace($"[{CodeFormatTypeEnum.DD}]", now.Day.ToString().PadLeft(2, '0')); |
| | | code = code.Replace($"[{CodeFormatTypeEnum.ST}]", codeRuleConfig.StartStr?.ToString() ?? ""); |
| | | code = code.Replace($"[{CodeFormatTypeEnum.NUM}]", codeRuleConfig.CurrentVal.ToString().PadLeft(codeRuleConfig.Length, '0')); |
| | | Dictionary<string, object> keyValuePairs = new Dictionary<string, object>() { { nameof(codeRuleConfig.CurrentVal), codeRuleConfig.CurrentVal }, { nameof(codeRuleConfig.Id), codeRuleConfig.Id }, { nameof(codeRuleConfig.ModifyDate), DateTime.Now } }; |
| | | sugarClient.Updateable(keyValuePairs).AS(MainDb.CodeRuleConfig).WhereColumns(nameof(codeRuleConfig.Id)).ExecuteCommand(); |
| | | sugarClient.Updateable(codeRuleConfig); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | } |
| | | return code; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ´æ¹åºåºååºåç¶æ |
| | | /// </summary> |
| | | /// <param name="warehouse"></param> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent TestOutStocksUpdate(Dt_Warehouse warehouse, Dt_OutboundOrderDetail outboundOrderDetails) |
| | | { |
| | | try |
| | | { |
| | | //è·ååºåºååºå |
| | | List<Dt_StockInfo> stockInfos = BaseDal.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).Where(x => x.Details.Any(j => j.MaterielCode == outboundOrderDetails.MaterielCode)).Take((int)outboundOrderDetails.OrderQuantity).ToList(); |
| | | if (stockInfos.Count <= 0) |
| | | { |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | //æ´æ¹ç¶æ |
| | | stockInfos.ForEach(x => |
| | | { |
| | | x.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | }); |
| | | return WebResponseContent.Instance.OK("æå", stockInfos); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ ¹æ®åºåºåæ¨éERPç³»ç» |
| | | /// </summary> |
| | | /// <param name="outId"></param> |
| | | /// <param name="WarehouseCode"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent PushERPOutBound(int outId, string WarehouseCode) |
| | | { |
| | | WebResponseContent content=new WebResponseContent(); |
| | | try |
| | | { |
| | | //è·ååºåºå |
| | | Dt_OutboundOrder outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == outId).Includes(x => x.Details).First(); |
| | | if (outboundOrder == null) |
| | | { |
| | | return content.Error("åºåºåä¸åå¨"); |
| | | } |
| | | if (outboundOrder.Details.Count!=(outboundOrder.Details.Where(x=>x.OrderDetailStatus==OrderDetailStatusEnum.Over.ObjToInt()).ToList().Count)||outboundOrder.OrderStatus!=OutOrderStatusEnum.åºåºå®æ.ObjToInt()) |
| | | { |
| | | return content.Error("该åºåºåæªå®æ"); |
| | | } |
| | | ERPIssueModel issueModel = GetERPIssueModel(outboundOrder, WarehouseCode); |
| | | string response=_invokeERPService.InvokeOutStandardsApi(issueModel); |
| | | return content.OK(response); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |