| | |
| | | { |
| | | return 4; |
| | | } |
| | | else if (warehouse.WarehouseCode == WarehouseEnum.HA581.ObjToString()) |
| | | { |
| | | Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2)); |
| | | if (palletTypeInfo == null) |
| | | { |
| | | throw new Exception($"æçå·é误"); |
| | | } |
| | | return palletTypeInfo.PalletType; |
| | | } |
| | | return -1; |
| | | } |
| | | /// <summary> |
| | |
| | | } |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | |
| | | public WebResponseContent PPPKMaterielGroup(string palletCode, int Initiallife, int warehouseId, List<string> serNums) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId); |
| | | if (warehouse == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ä»åºä¿¡æ¯"); |
| | | } |
| | | |
| | | List<MatSerNumAnalysisModel> models = CodeAnalysisHelper.CodeAnalysis<MatSerNumAnalysisModel>(AnalysisCodeEnum.PPPKSerNumAnalysis, serNums); |
| | | |
| | | if (models.Select(x => x.MaterielCode).Distinct().Count() > 1) |
| | | { |
| | | return WebResponseContent.Instance.Error($"ç©æä¸å¯æ··æ¾"); |
| | | } |
| | | //éªè¯å¤ææ¶é´æ ¼å¼ |
| | | WebResponseContent IsValidContent = IsValidMCDates(models); |
| | | if (!IsValidContent.Status) |
| | | { |
| | | return content.Error(IsValidContent.Message); |
| | | } |
| | | string materielCode = models.FirstOrDefault()?.MaterielCode ?? ""; |
| | | |
| | | int materielWidth = 0; |
| | | |
| | | if (materielCode.Contains("-")) |
| | | { |
| | | var model = models.FirstOrDefault(); |
| | | if (model != null && !string.IsNullOrEmpty(model.MaterielCode)) |
| | | { |
| | | var codeParts = model.MaterielCode.Split("-"); |
| | | if (codeParts.Length >= 2) |
| | | { |
| | | if (int.TryParse(codeParts[1], out int widthValue)) |
| | | { |
| | | materielWidth = widthValue; |
| | | } |
| | | else |
| | | { |
| | | materielWidth = 0; |
| | | } |
| | | |
| | | materielCode = codeParts[0]; |
| | | } |
| | | } |
| | | } |
| | | Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materielCode); |
| | | if (materielInfo == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ç©æçä¿¡æ¯"); |
| | | } |
| | | |
| | | float beforeQuantity = 0; |
| | | |
| | | Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First(); |
| | | |
| | | if (stockInfo == null) |
| | | { |
| | | stockInfo = new Dt_StockInfo() |
| | | { |
| | | PalletCode = palletCode, |
| | | StockStatus = StockStatusEmun.æå¨ç»çæå.ObjToInt(), |
| | | WarehouseId = warehouse.WarehouseId, |
| | | PalletType = GetPalletType(warehouse, palletCode), |
| | | Details = new List<Dt_StockInfoDetail>() |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | if (stockInfo.StockStatus != StockStatusEmun.ç»çæå.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.æå¨ç»çæå.ObjToInt()) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æçå·éå¤"); |
| | | } |
| | | beforeQuantity = stockInfo.Details.Sum(x => x.StockQuantity); |
| | | } |
| | | if(materielWidth != 0&& materielWidth < 650 && stockInfo.PalletType > 1) |
| | | { |
| | | return WebResponseContent.Instance.Error("ä½äº650è£å宽çç©æè¯·ç¨å°æçæ¡ç éæ°ç»çï¼"); |
| | | } |
| | | else if(materielWidth != 0 && materielWidth >= 650 && stockInfo.PalletType < 2) |
| | | { |
| | | return WebResponseContent.Instance.Error("650è£å宽以ä¸çç©æè¯·ç¨å¤§æçæ¡ç éæ°ç»çï¼"); |
| | | } |
| | | List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>(); |
| | | List<int> detailKeys = new List<int>(); |
| | | foreach (var model in models) |
| | | { |
| | | Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail() |
| | | { |
| | | BatchNo = model.LotNo, |
| | | MaterielCode = model.MaterielCode, |
| | | MaterielName = materielInfo.MaterielName, |
| | | MaterielSpec = materielInfo.MaterielSpec, |
| | | OrderNo = "", |
| | | SerialNumber = model.SerialNumber, |
| | | StockQuantity = model.MaterielCode.Contains("-")? model.MaterielLength.ObjToInt():model.Quantity, |
| | | OutboundQuantity = 0, |
| | | Unit = materielInfo.MaterielUnit, |
| | | Status = StockStatusEmun.ç»çæå.ObjToInt(), |
| | | ProductionDate = model.ProductionDate, |
| | | EffectiveDate = model.EffectiveDate, |
| | | InboundOrderRowNo = 0, |
| | | }; |
| | | |
| | | if (stockInfo.Id > 0) |
| | | { |
| | | stockInfoDetail.StockId = stockInfo.Id; |
| | | } |
| | | stockInfo.Details.Add(stockInfoDetail); |
| | | |
| | | stockInfoDetails.Add(stockInfoDetail); |
| | | } |
| | | |
| | | float totalQuantity = stockInfo.Details.Sum(x => x.StockQuantity); |
| | | |
| | | _unitOfWorkManage.BeginTran(); |
| | | if (stockInfo.Id == 0) |
| | | { |
| | | _stockRepository.StockInfoRepository.Db.InsertNav(stockInfo).Include(x => x.Details).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | _stockRepository.StockInfoRepository.Db.UpdateNav(stockInfo).Include(x => x.Details, new UpdateNavOptions() { OneToManyInsertOrUpdate = true }).ExecuteCommand(); |
| | | } |
| | | _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfoDetails, beforeQuantity, totalQuantity, StockChangeTypeEnum.MaterielGroup); |
| | | _unitOfWorkManage.CommitTran(); |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |