| | |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using Model.InterFaceModel; |
| | | using Model.ModelDto.BllQualityDto; |
| | | using Model.ModelVm; |
| | | using SqlSugar; |
| | |
| | | |
| | | return isquality; |
| | | } |
| | | /// <summary> |
| | | /// SAP下发库存调整单 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public string InsertQualitySap(SendQualityVm model) |
| | | { |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(model.orderNo) || model.adjustmentDList.Count <= 0) |
| | | { |
| | | throw new Exception("参数错误"); |
| | | } |
| | | var asnInfo = Db.Queryable<BllArrivalNotice>().First(w => w.IsDel == "0" && w.OrderCode == model.orderNo); |
| | | if (asnInfo == null) |
| | | { |
| | | throw new Exception($"未查询到{model.orderNo}对应的入库单信息"); |
| | | } |
| | | //开启事务 |
| | | Db.BeginTran(); |
| | | |
| | | foreach (var item in model.adjustmentDList) |
| | | { |
| | | var asnDetail = Db.Queryable<BllArrivalNoticeDetail>().First(w => w.IsDel == "0" && w.ASNNo == asnInfo.ASNNo && w.OrderDetailCode == item.lineNo && w.SkuNo == item.skuNo && w.LotNo == item.lotNo); |
| | | if (asnDetail == null) |
| | | { |
| | | throw new Exception($"未查询到{item.lineNo}对应的入库单明细信息"); |
| | | } |
| | | asnDetail.InspectStatus = item.IsQualified; |
| | | //更新入库单明细质检状态 |
| | | Db.Updateable(asnDetail).ExecuteCommand(); |
| | | |
| | | //获取物料信息 |
| | | var sku = Db.Queryable<SysMaterials>().First(a => a.IsDel == "0" && a.SkuNo == item.skuNo); |
| | | if (sku == null) |
| | | { |
| | | throw new Exception($"物料编码为{item.skuNo}的物料信息不存在,请核查!"); |
| | | } |
| | | |
| | | string toDayTime = DateTime.Now.ToString("yyyyMMdd"); |
| | | var maxInspectNo = Db.Queryable<BllQualityInspect>().Where(m => m.IsDel == "0" && m.InspectNo.Contains("SAP")).Max(m => m.InspectNo); |
| | | if (string.IsNullOrWhiteSpace(maxInspectNo)) |
| | | { |
| | | maxInspectNo = "SAP" + toDayTime + "0001"; |
| | | } |
| | | else |
| | | { |
| | | var lotStr = maxInspectNo.Substring(3, 8); |
| | | if (lotStr == toDayTime) |
| | | { |
| | | maxInspectNo = "SAP" + toDayTime + (int.Parse(maxInspectNo.Replace("SAP","").Substring(8, 4)) + 1).ToString().PadLeft(4, '0'); |
| | | } |
| | | else |
| | | { |
| | | maxInspectNo = "SAP" + toDayTime + "0001"; |
| | | } |
| | | } |
| | | var qualityModel = new BllQualityInspect |
| | | { |
| | | ASNNo = asnDetail.ASNNo, |
| | | InspectNo = maxInspectNo, |
| | | SkuNo = item.skuNo, |
| | | SkuName = item.skuName, |
| | | Standard = sku.Standard, |
| | | LotNo = item.lotNo, |
| | | IsQualified = item.IsQualified, |
| | | Origin = "SAP", |
| | | FailQty = 0, |
| | | PassQty = 0 |
| | | }; |
| | | |
| | | //查找库存信息 |
| | | var stockDetailList = Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.SkuNo == item.skuNo && w.LotNo == item.lotNo).ToList(); |
| | | foreach(var datailItem in stockDetailList) |
| | | { |
| | | List<DataBoxInfo> boxList = Db.Queryable<DataBoxInfo>().Where(a => a.IsDel == "0" && a.SkuNo == item.skuNo && a.LotNo == item.lotNo && a.PalletNo == datailItem.PalletNo).ToList(); |
| | | foreach (var boxItem in boxList) |
| | | { |
| | | if (item.IsQualified == "0")//不合格 |
| | | { |
| | | boxItem.InspectStatus = "2"; |
| | | } |
| | | else//合格 |
| | | { |
| | | boxItem.InspectStatus = "1"; |
| | | } |
| | | } |
| | | //更新箱码明细质检状态 |
| | | Db.Updateable(boxList).ExecuteCommand(); |
| | | |
| | | if (item.IsQualified == "0")//不合格 |
| | | { |
| | | datailItem.InspectStatus = "2"; |
| | | //不合格数量 |
| | | qualityModel.FailQty += datailItem.Qty; |
| | | } |
| | | else//合格 |
| | | { |
| | | datailItem.InspectStatus = "1"; |
| | | //合格数量 |
| | | qualityModel.PassQty += datailItem.Qty; |
| | | } |
| | | //更新库存明细质检状态 |
| | | Db.Updateable(datailItem).ExecuteCommand(); |
| | | } |
| | | //添加质检变更记录 |
| | | Db.Insertable(qualityModel).ExecuteCommand(); |
| | | } |
| | | //提交事务 |
| | | Db.CommitTran(); |
| | | |
| | | return "0"; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //回滚事务 |
| | | Db.RollbackTran(); |
| | | //抛出异常 |
| | | throw new Exception("接收SAP下发库存调整单异常:", ex); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | } |