|  |  |  | 
|---|
|  |  |  | using WIDESEA_IBasicService; | 
|---|
|  |  |  | using WIDESEA_Common.LocationEnum; | 
|---|
|  |  |  | using WIDESEA_IRecordService; | 
|---|
|  |  |  | using WIDESEA_Common.StockEnum; | 
|---|
|  |  |  | using WIDESEA_Common.TaskEnum; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | namespace WIDESEA_OutboundService | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | float originalNeedQuantity = mesOutboundOrder.OrderQuantity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float needQuantity = originalNeedQuantity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //è·ååºå | 
|---|
|  |  |  | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(mesOutboundOrder.MaterialCode, "", mesOutboundOrder.WarehouseId); | 
|---|
|  |  |  | if (!stockInfos.Any()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new Exception($"æªæ¾å°å¯åé
åºå"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, mesOutboundOrder.MaterialCode, needQuantity, out float residueQuantity); | 
|---|
|  |  |  | mesOutboundOrder.LockQuantity += needQuantity - residueQuantity; | 
|---|
|  |  |  | if (residueQuantity>0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new Exception($"åºåä¸è¶³"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | autoAssignStocks.OrderBy(x => x.Details.FirstOrDefault()?.StockQuantity).ToList(); | 
|---|
|  |  |  | outStocks.AddRange(autoAssignStocks); | 
|---|
|  |  |  | float assignQuantity = needQuantity - residueQuantity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float orderQuantity = mesOutboundOrder.OrderQuantity; | 
|---|
|  |  |  | for (int j = 0; j < autoAssignStocks.Count; j++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | float detailAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == mesOutboundOrder.MaterialCode).Sum(x => x.AssignQuantity);//åºåºè®¢åæç»å·²åé
æ°é | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | stockInfos.ForEach(x => { | 
|---|
|  |  |  | x.StockStatus = StockStatusEmun.åºåºéå®.ObjToInt(); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | _stockService.StockInfoService.Repository.UpdateData(stockInfos); | 
|---|
|  |  |  | List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>(); | 
|---|
|  |  |  | foreach (var item in stockInfos) | 
|---|
|  |  |  | 
|---|
|  |  |  | return WebResponseContent.Instance.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public WebResponseContent AddMesOrder(SubstrateOutModel substrateOutModel) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA57.ToString()); | 
|---|
|  |  |  | if (warehouse == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"ä»åºåºç¡ä¿¡æ¯æªé
ç½®"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == substrateOutModel.MaterialCode); | 
|---|
|  |  |  | if (materielInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ç©æä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int orderType = 0; | 
|---|
|  |  |  | if(substrateOutModel.Line == "1011") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | orderType = MesOutboundOrderTypeEnum.HandSubstrateOutPick.ObjToInt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | orderType = MesOutboundOrderTypeEnum.HandSubstrateOut.ObjToInt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_MesOutboundOrder mesOutboundOrder = new Dt_MesOutboundOrder() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | CreateType = OrderCreateTypeEnum.CreateInSystem.ObjToInt(), | 
|---|
|  |  |  | Line = substrateOutModel.Line, | 
|---|
|  |  |  | MaterialCode = substrateOutModel.MaterialCode, | 
|---|
|  |  |  | MaterialName = materielInfo.MaterielName, | 
|---|
|  |  |  | OrderQuantity = substrateOutModel.RequiredQuantity, | 
|---|
|  |  |  | TaskNo = DateTime.Now.ToString("yyyyMMddHHmmss"), | 
|---|
|  |  |  | Unit = substrateOutModel.Unit, | 
|---|
|  |  |  | OrderType = orderType, | 
|---|
|  |  |  | OrderStatus = OutOrderStatusEnum.æªå¼å§.ObjToInt(), | 
|---|
|  |  |  | WarehouseId = warehouse.WarehouseId | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AddData(mesOutboundOrder); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return WebResponseContent.Instance.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|