| | |
| | | return content; |
| | | } |
| | | |
| | | //药水,低温仓组盘 |
| | | public WebResponseContent NEWMaterielGroup(SaveModel saveModel) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | |
| | | var orderNo = saveModel.MainData["orderNo"].ToString(); |
| | | var palletCode = saveModel.MainData["palletCode"].ToString(); |
| | | var warehouseId = saveModel.MainData["warehouseId"].ObjToInt(); |
| | | var Initiallife = saveModel.MainData["initiallife"].ObjToInt(); |
| | | List<string> serialNumbers = new List<string>(); |
| | | List<decimal> quantitys = new List<decimal>(); |
| | | foreach (var item in saveModel.DelKeys) |
| | | { |
| | | string json = JsonConvert.SerializeObject(item); |
| | | Dictionary<string, object> delKeyDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(json); |
| | | |
| | | |
| | | if (delKeyDict.TryGetValue("serialNumber", out object serialNumberObj)) |
| | | { |
| | | string serialNumber = serialNumberObj?.ToString(); |
| | | if (!string.IsNullOrEmpty(serialNumber)) |
| | | { |
| | | serialNumbers.Add(serialNumber); |
| | | } |
| | | else |
| | | { |
| | | return WebResponseContent.Instance.Error("serialNumber的值为空"); |
| | | } |
| | | } |
| | | if (delKeyDict.TryGetValue("quantity", out object quantityObj)) |
| | | { |
| | | if (quantityObj == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("物料数量的值为空"); |
| | | } |
| | | decimal quantity; |
| | | try |
| | | { |
| | | quantity = Convert.ToDecimal(quantityObj); |
| | | } |
| | | catch |
| | | { |
| | | return WebResponseContent.Instance.Error($"物料数量{quantityObj}无法转换为数字"); |
| | | } |
| | | if (quantity <= 0) |
| | | { |
| | | return WebResponseContent.Instance.Error("物料数量必须大于0"); |
| | | } |
| | | |
| | | quantitys.Add(quantity); |
| | | } |
| | | else |
| | | { |
| | | return WebResponseContent.Instance.Error("缺少物料数量字段"); |
| | | } |
| | | } |
| | | Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId); |
| | | if (warehouse == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到该仓库信息"); |
| | | } |
| | | |
| | | Dt_InboundOrder inboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderNo == orderNo && x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).First(); |
| | | if (inboundOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到入库单信息"); |
| | | } |
| | | if (inboundOrder.Details == null || inboundOrder.Details.Count <= 0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到入库单明细信息"); |
| | | } |
| | | List<MatSerNumAnalysisModel> models = CodeAnalysisHelper.CodeAnalysis<MatSerNumAnalysisModel>(AnalysisCodeEnum.MatSerNumAnalysis, serialNumbers); |
| | | //验证判断时间格式 |
| | | WebResponseContent IsValidContent = IsValidMCDates(models); |
| | | if (!IsValidContent.Status) |
| | | { |
| | | return content.Error(IsValidContent.Message); |
| | | } |
| | | |
| | | string materielCode = models.FirstOrDefault()?.MaterielCode ?? ""; |
| | | Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materielCode); |
| | | if (materielInfo == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到该物料的信息"); |
| | | } |
| | | |
| | | decimal 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() |
| | | { |
| | | BatchNo = inboundOrderDet.BatchNo, |
| | | PalletCode = palletCode, |
| | | PalletType = GetPalletType(warehouse, palletCode),//GetPalletType(warehouse, palletCode) |
| | | IsFull = true, |
| | | StockStatus = (int)StockStatusEmun.组盘暂存, |
| | | Creater = "WMS", |
| | | CreateDate = DateTime.Now, |
| | | MaterialType = (int)InventoryMaterialType.原材料, |
| | | Materialweight = 0, |
| | | Wlstatus = (int)InventoryMaterialStatus.合格, |
| | | Mgeneratetime = DateTime.Now, |
| | | WarehouseId = warehouse.WarehouseId, |
| | | Details = new List<Dt_StockInfoDetail>() |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | //if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt()) |
| | | //{ |
| | | return WebResponseContent.Instance.Error($"托盘号重复,该托盘已组过物料"); |
| | | //} |
| | | //beforeQuantity = stockInfo.Details.Sum(x => x.StockQuantity); |
| | | } |
| | | |
| | | if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ToString()) |
| | | { |
| | | stockInfo.Remark = Initiallife.ToString(); |
| | | string batchNo = models.FirstOrDefault()?.LotNo ?? ""; |
| | | //Dt_StockInfoDetail existDetail = _stockRepository.StockInfoDetailRepository.QueryFirst(x => x.BatchNo == batchNo); |
| | | //if (existDetail != null) |
| | | //{ |
| | | // return WebResponseContent.Instance.Error($"{batchNo}测试架已存在"); |
| | | //} |
| | | if (models.Count >= 2) |
| | | { |
| | | return WebResponseContent.Instance.Error($"组盘明细不唯一"); |
| | | } |
| | | //if (palletCode.Substring(0, 1) == "6") |
| | | //{ |
| | | // stockInfo.PalletType = PalletTypeEnum.MediumPallet.ObjToInt(); |
| | | //} |
| | | //else |
| | | //{ |
| | | // stockInfo.PalletType = PalletTypeEnum.LargestPallet.ObjToInt(); |
| | | //} |
| | | } |
| | | else if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ToString()) |
| | | { |
| | | if (models.Count >= 2) |
| | | { |
| | | return WebResponseContent.Instance.Error($"组盘明细不唯一"); |
| | | } |
| | | } |
| | | |
| | | List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>(); |
| | | foreach (var model in models) |
| | | { |
| | | |
| | | Dt_InboundOrderDetail notGroupDetail = new Dt_InboundOrderDetail(); |
| | | |
| | | notGroupDetail = inboundOrder.Details.Where(x => x.OrderDetailStatus <= OrderDetailStatusEnum.Inbounding.ObjToInt() && x.MaterielCode == model.MaterielCode && x.BatchNo == model.LotNo).FirstOrDefault(); |
| | | |
| | | if (notGroupDetail == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"该物料在该入库单中已全部组盘完成"); |
| | | } |
| | | Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail() |
| | | { |
| | | MaterielCode = notGroupDetail.MaterielCode, |
| | | MaterielName = notGroupDetail.MaterielName, |
| | | OrderNo = inboundOrder.OrderNo, |
| | | BatchNo = notGroupDetail.BatchNo, |
| | | LinId = notGroupDetail.LinId, |
| | | StockQuantity = (quantitys.FirstOrDefault()), |
| | | Status = (int)StockStatusEmun.组盘暂存, |
| | | Creater = "WMS", |
| | | CreateDate = DateTime.Now, |
| | | Id = notGroupDetail.LinId.ObjToInt(), |
| | | DeliveryNote = model.DeliveryNote, |
| | | SupplierBatch = notGroupDetail.SupplierBatch, |
| | | MaterieSpec = notGroupDetail.MaterieSpec, |
| | | OrinalLocation = notGroupDetail.OrinalLocation |
| | | }; |
| | | |
| | | if (stockInfo.Id > 0) |
| | | { |
| | | stockInfoDetail.StockId = stockInfo.Id; |
| | | } |
| | | stockInfo.Details.Add(stockInfoDetail); |
| | | |
| | | stockInfoDetails.Add(stockInfoDetail); |
| | | |
| | | decimal decimalReceiptQuantity = Convert.ToDecimal(notGroupDetail.ReceiptQuantity); |
| | | decimal decimalModelQuantity = Convert.ToDecimal((quantitys.FirstOrDefault())); |
| | | decimal decimalOrderQuantity = Convert.ToDecimal(notGroupDetail.OrderQuantity); |
| | | decimalReceiptQuantity += decimalModelQuantity; |
| | | // 检查是否超出订单数量 |
| | | if (decimalReceiptQuantity > decimalOrderQuantity) |
| | | { |
| | | return WebResponseContent.Instance.Error($"组盘数量溢出{decimalReceiptQuantity - decimalOrderQuantity}"); |
| | | } |
| | | // 转回float类型存储,但比较和计算都使用decimal完成 |
| | | notGroupDetail.ReceiptQuantity = Convert.ToDecimal(decimalReceiptQuantity); |
| | | if (notGroupDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt()) |
| | | { |
| | | notGroupDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt(); |
| | | } |
| | | } |
| | | |
| | | decimal totalQuantity = stockInfo.Details.Sum(x => x.StockQuantity); |
| | | |
| | | inboundOrder.OrderStatus = InOrderStatusEnum.入库中.ObjToInt(); |
| | | |
| | | _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(); |
| | | } |
| | | _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrder.Details); |
| | | _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder); |
| | | _unitOfWorkManage.CommitTran(); |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | finally |
| | | { |
| | | |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 成品组盘 |
| | | /// </summary> |