|  |  |  | 
|---|
|  |  |  | using Microsoft.AspNetCore.Mvc.RazorPages; | 
|---|
|  |  |  | using Newtonsoft.Json; | 
|---|
|  |  |  | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; | 
|---|
|  |  |  | using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; | 
|---|
|  |  |  | using Org.BouncyCastle.Asn1.Ocsp; | 
|---|
|  |  |  | using SqlSugar; | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | using System.Collections; | 
|---|
|  |  |  | using System.Collections.Generic; | 
|---|
|  |  |  | using System.Dynamic; | 
|---|
|  |  |  | using System.Globalization; | 
|---|
|  |  |  | using System.Linq; | 
|---|
|  |  |  | using System.Linq.Expressions; | 
|---|
|  |  |  | using System.Reflection; | 
|---|
|  |  |  | using System.Reflection.Metadata; | 
|---|
|  |  |  | using System.Text; | 
|---|
|  |  |  | using System.Threading.Tasks; | 
|---|
|  |  |  | 
|---|
|  |  |  | _invokeERPService = invokeERPService; | 
|---|
|  |  |  | _warehouseService = warehouseService; | 
|---|
|  |  |  | _palletTypeInfoRepository = palletTypeInfoRepository; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | public override object GetDetailPage(PageDataOptions pageData) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Type t = typeof(Dt_InboundOrder); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (pageData.Value == null) return new PageGridData<object>(total: 0, null); | 
|---|
|  |  |  | string keyName = t.GetKeyName(); | 
|---|
|  |  |  | ////çææ¥è¯¢æ¡ä»¶ | 
|---|
|  |  |  | //Expression<Func<TEntity, bool>> whereExpression = keyName.CreateExpression<TEntity>(pageData.Value, LinqExpressionType.Equal); | 
|---|
|  |  |  | int totalCount = 0; | 
|---|
|  |  |  | PropertyInfo propertyInfo = t.GetProperties().FirstOrDefault(x => x.GetCustomAttribute<Navigate>() != null); | 
|---|
|  |  |  | if (propertyInfo != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Type detailType = propertyInfo.PropertyType.GetGenericArguments()[0]; | 
|---|
|  |  |  | Navigate navigate = propertyInfo.GetCustomAttribute<Navigate>(); | 
|---|
|  |  |  | List<Dt_InboundOrderDetail> list = BaseDal.Db.Queryable<Dt_InboundOrderDetail>().Where(navigate.GetName(), "=", pageData.Value).ToPageList(pageData.Page, pageData.Rows, ref totalCount); | 
|---|
|  |  |  | decimal sum = 0; | 
|---|
|  |  |  | list.ForEach(x => | 
|---|
|  |  |  | { | 
|---|
|  |  |  | sum += Convert.ToDecimal(x.OrderQuantity); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | PageGridData<Dt_InboundOrderDetail> pageGridData = new PageGridData<Dt_InboundOrderDetail>() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Total= totalCount, | 
|---|
|  |  |  | Rows=list, | 
|---|
|  |  |  | Summary=new | 
|---|
|  |  |  | { | 
|---|
|  |  |  | OrderQuantity = Math.Round(sum, 3), | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | return pageGridData; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new PageGridData<object>(total: 0, null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// å
¶ä»å
¥åºåæ¥æ¶(è°æå
¥ä»,客ä¾åæ¶,ç©æéå®éè´§) | 
|---|
|  |  |  | 
|---|
|  |  |  | List<Dt_InboundOrder> dt_ReceiveOrders = new List<Dt_InboundOrder>(); | 
|---|
|  |  |  | if (string.IsNullOrEmpty(orderNo)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | dt_ReceiveOrders = Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderStatus < InOrderStatusEnum.å
¥åºå®æ.ObjToInt() && x.WarehouseId == warehouseId).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5); | 
|---|
|  |  |  | dt_ReceiveOrders = Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderStatus < InOrderStatusEnum.å
¥åºå®æ.ObjToInt() && x.WarehouseId == warehouseId).Includes(x=>x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 10); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | dt_ReceiveOrders = Db.Queryable<Dt_InboundOrder>().Where(x => (x.InboundOrderNo.Contains(orderNo)) && x.OrderStatus < InOrderStatusEnum.å
¥åºå®æ.ObjToInt() && x.WarehouseId == warehouseId).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5); | 
|---|
|  |  |  | dt_ReceiveOrders = Db.Queryable<Dt_InboundOrder>().Where(x => (x.InboundOrderNo.Contains(orderNo)) && x.OrderStatus < InOrderStatusEnum.å
¥åºå®æ.ObjToInt() && x.WarehouseId == warehouseId).Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 10); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | content.OK(data: dt_ReceiveOrders); | 
|---|
|  |  |  | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°å
¥åºåæç»ä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<MatSerNumAnalysisModel> models = CodeAnalysisHelper.CodeAnalysis<MatSerNumAnalysisModel>(AnalysisCodeEnum.MatSerNumAnalysis, serNums); | 
|---|
|  |  |  | //éªè¯å¤ææ¶é´æ ¼å¼ | 
|---|
|  |  |  | WebResponseContent IsValidContent = IsValidMCDates(models); | 
|---|
|  |  |  | if (!IsValidContent.Status) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error(IsValidContent.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //é¤éè´å
¥åºå以å¤å
¶ä»å
¥åºåç»çæ°æ®å¤ç | 
|---|
|  |  |  | if (inboundOrder.OrderType != InOrderTypeEnum.Purchase.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<string> purchaseOrderNos = receiveOrder.Details.Select(x => x.PurchaseOrderNo).ToList(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (models.Select(x => x.MaterielCode).Distinct().Count() > 1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"ç©æä¸å¯æ··æ¾"); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | stockInfoDetails.Add(stockInfoDetail); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | notGroupDetail.ReceiptQuantity += model.Quantity; | 
|---|
|  |  |  | decimal decimalReceiptQuantity = Convert.ToDecimal(notGroupDetail.ReceiptQuantity); | 
|---|
|  |  |  | decimal decimalModelQuantity = Convert.ToDecimal(model.Quantity); | 
|---|
|  |  |  | decimal decimalOrderQuantity = Convert.ToDecimal(notGroupDetail.OrderQuantity); | 
|---|
|  |  |  | decimalReceiptQuantity += decimalModelQuantity; | 
|---|
|  |  |  | // æ£æ¥æ¯å¦è¶
åºè®¢åæ°é | 
|---|
|  |  |  | if (decimalReceiptQuantity > decimalOrderQuantity) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"ç»çæ°é溢åº{decimalReceiptQuantity - decimalOrderQuantity}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // è½¬åfloatç±»ååå¨ï¼ä½æ¯è¾å计ç®é½ä½¿ç¨decimal宿 | 
|---|
|  |  |  | notGroupDetail.ReceiptQuantity = Convert.ToSingle(decimalReceiptQuantity); | 
|---|
|  |  |  | if (notGroupDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | notGroupDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | public WebResponseContent MaterielPPorGM(string materielBoxCode = "") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string SerNum = ""; | 
|---|
|  |  |  | if (materielBoxCode.LastIndexOf("SC:")<0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SerNum = materielBoxCode; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SerNum = materielBoxCode.Substring(0, materielBoxCode.LastIndexOf("SC:") - 1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | MatSerNumAnalysisModel model = CodeAnalysisHelper.CodeAnalysis<MatSerNumAnalysisModel>(AnalysisCodeEnum.MatSerNumAnalysis, SerNum); | 
|---|
|  |  |  | //éªè¯å¤ææ¶é´æ ¼å¼ | 
|---|
|  |  |  | WebResponseContent IsValidContent = IsValidMCDates(new List<MatSerNumAnalysisModel>() { model }); | 
|---|
|  |  |  | if (!IsValidContent.Status) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error(IsValidContent.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | string result = ""; | 
|---|
|  |  |  | if (materielBoxCode.LastIndexOf("SC:") > 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | result = materielBoxCode.Substring(materielBoxCode.LastIndexOf("SC:") + 3); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //è·åå
¥åºåæç» | 
|---|
|  |  |  | Dt_InboundOrderDetail inboundOrderDetail = _inboundRepository.InboundOrderDetailRepository.QueryFirst(x=>x.BatchNo== model.LotNo && x.MaterielCode== model.MaterielCode); | 
|---|
|  |  |  | if (inboundOrderDetail == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return InOtherGMOrPP(model, result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_InboundOrder inboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>().First(x => x.Id == inboundOrderDetail.OrderId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (inboundOrder == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°å
¥åºåä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == inboundOrder.WarehouseId); | 
|---|
|  |  |  | //é¤éè´å
¥åºå以å¤å
¶ä»å
¥åºåç»çæ°æ®å¤ç | 
|---|
|  |  |  | if (inboundOrder.OrderType != InOrderTypeEnum.Purchase.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return OtherInGroup(inboundOrder, model.LotNo, 0, warehouse, new List<MatSerNumAnalysisModel>() { model }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_ReceiveOrder receiveOrder = _inboundRepository.ReceiveOrderRepository.Db.Queryable<Dt_ReceiveOrder>().Where(x => x.ReceiveOrderNo == inboundOrder.UpperOrderNo).Includes(x => x.Details).First(); | 
|---|
|  |  |  | if (receiveOrder == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°å¯¹åºçæ¶è´§å"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (receiveOrder.Details == null || receiveOrder.Details.Count <= 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°å¯¹åºçæ¶è´§åæç»"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<string> purchaseOrderNos = receiveOrder.Details.Select(x => x.PurchaseOrderNo).ToList(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | string materielCode = model?.MaterielCode ?? ""; | 
|---|
|  |  |  | 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 == model.LotNo).Includes(x => x.Details).First(); | 
|---|
|  |  |  | if (stockInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | stockInfo = new Dt_StockInfo() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | PalletCode = model.LotNo, | 
|---|
|  |  |  | StockStatus = StockStatusEmun.ç»çæå.ObjToInt(), | 
|---|
|  |  |  | WarehouseId = inboundOrder.WarehouseId, | 
|---|
|  |  |  | PalletType = GetPalletTypeGMOrPP(warehouse, result.IsNullOrEmpty() ? "" : result.Split("*")[0]), | 
|---|
|  |  |  | StockLength = result.IsNullOrEmpty() ? 0 : result.Split("*")[0].ObjToInt(), | 
|---|
|  |  |  | Details = new List<Dt_StockInfoDetail>() | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (stockInfo.StockStatus != StockStatusEmun.ç»çæå.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æçå·éå¤"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stockInfo.PalletType==-1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æçç±»åä¸åå¨"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>(); | 
|---|
|  |  |  | if (purchaseOrderNos.FirstOrDefault(x => x == model.PurchaseOrderNo) == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªå¨æ¶è´§æç»ä¸æ¾å°è¯¥éè´å"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (inboundOrderDetail.OrderDetailStatus > OrderDetailStatusEnum.Inbounding.ObjToInt() || inboundOrderDetail.OrderQuantity == inboundOrderDetail.ReceiptQuantity) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"è¯¥ç©æå¨è¯¥å
¥åºåä¸å·²å
¨é¨ç»ç宿"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | BatchNo = model.LotNo, | 
|---|
|  |  |  | MaterielCode = materielInfo.MaterielCode, | 
|---|
|  |  |  | MaterielName = materielInfo.MaterielName, | 
|---|
|  |  |  | MaterielSpec = materielInfo.MaterielSpec, | 
|---|
|  |  |  | OrderNo = inboundOrder.InboundOrderNo, | 
|---|
|  |  |  | SerialNumber = model.SerialNumber, | 
|---|
|  |  |  | StockQuantity = model.Quantity, | 
|---|
|  |  |  | OutboundQuantity = 0, | 
|---|
|  |  |  | Unit = materielInfo.MaterielUnit, | 
|---|
|  |  |  | Status = StockStatusEmun.ç»çæå.ObjToInt(), | 
|---|
|  |  |  | ProductionDate = model.ProductionDate, | 
|---|
|  |  |  | EffectiveDate = model.EffectiveDate, | 
|---|
|  |  |  | InboundOrderRowNo = inboundOrderDetail.RowNo, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | stockInfo.Details.Add(stockInfoDetail); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | stockInfoDetails.Add(stockInfoDetail); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | inboundOrderDetail.ReceiptQuantity += model.Quantity; | 
|---|
|  |  |  | if (inboundOrderDetail.ReceiptQuantity > inboundOrderDetail.OrderQuantity) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"ç»çæ°é溢åº{inboundOrderDetail.ReceiptQuantity - inboundOrderDetail.OrderQuantity}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | float totalQuantity = stockInfo.Details.Sum(x => x.StockQuantity); | 
|---|
|  |  |  | if (inboundOrder.OrderStatus == InOrderStatusEnum.æªå¼å§.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | inboundOrder.OrderStatus = InOrderStatusEnum.å
¥åºä¸.ObjToInt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetail); | 
|---|
|  |  |  | _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder); | 
|---|
|  |  |  | _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfoDetails, beforeQuantity, totalQuantity, StockChangeTypeEnum.MaterielGroup); | 
|---|
|  |  |  | content.OK(data: stockInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | content.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | public WebResponseContent InOtherGMOrPP(MatSerNumAnalysisModel model,string request = "") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string materielCode = model?.MaterielCode ?? ""; | 
|---|
|  |  |  | Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materielCode); | 
|---|
|  |  |  | if (materielInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ç©æçä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | float beforeQuantity = 0; | 
|---|
|  |  |  | Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == materielInfo.WarehouseId); | 
|---|
|  |  |  | Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == model.LotNo).Includes(x => x.Details).First(); | 
|---|
|  |  |  | if (stockInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | stockInfo = new Dt_StockInfo() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | PalletCode = model.LotNo, | 
|---|
|  |  |  | StockStatus = StockStatusEmun.ç»çæå.ObjToInt(), | 
|---|
|  |  |  | WarehouseId = warehouse.WarehouseId, | 
|---|
|  |  |  | PalletType = GetPalletTypeGMOrPP(warehouse, request.IsNullOrEmpty() ?"":request.Split("*")[0]), | 
|---|
|  |  |  | StockLength = request.IsNullOrEmpty()?0:request.Split("*")[0].ObjToInt(), | 
|---|
|  |  |  | Details = new List<Dt_StockInfoDetail>() | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (stockInfo.StockStatus != StockStatusEmun.ç»çæå.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æçå·éå¤"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stockInfo.PalletType == -1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æçç±»åä¸åå¨"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>(); | 
|---|
|  |  |  | Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | BatchNo = model.LotNo, | 
|---|
|  |  |  | MaterielCode = materielInfo.MaterielCode, | 
|---|
|  |  |  | MaterielName = materielInfo.MaterielName, | 
|---|
|  |  |  | MaterielSpec = materielInfo.MaterielSpec, | 
|---|
|  |  |  | OrderNo = "", | 
|---|
|  |  |  | SerialNumber = model.SerialNumber, | 
|---|
|  |  |  | StockQuantity = model.Quantity, | 
|---|
|  |  |  | OutboundQuantity = 0, | 
|---|
|  |  |  | Unit = materielInfo.MaterielUnit, | 
|---|
|  |  |  | Status = StockStatusEmun.ç»çæå.ObjToInt(), | 
|---|
|  |  |  | ProductionDate = model.ProductionDate, | 
|---|
|  |  |  | EffectiveDate = model.EffectiveDate, | 
|---|
|  |  |  | InboundOrderRowNo = 0, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | stockInfo.Details.Add(stockInfoDetail); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | stockInfoDetails.Add(stockInfoDetail); | 
|---|
|  |  |  | float totalQuantity = stockInfo.Details.Sum(x => x.StockQuantity); | 
|---|
|  |  |  | _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfoDetails, beforeQuantity, totalQuantity, StockChangeTypeEnum.MaterielGroup); | 
|---|
|  |  |  | return WebResponseContent.Instance.OK(data: stockInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | public int GetPalletTypeGMOrPP(Dt_Warehouse warehouse, string boxWidth) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (warehouse.WarehouseCode == WarehouseEnum.HA152.ToString()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (boxWidth.ObjToInt() <= 690 && boxWidth.ObjToInt()>=520) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return 15; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (boxWidth.ObjToInt() > 690 && boxWidth.ObjToInt() <= 1400) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return 16; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (warehouse.WarehouseCode == WarehouseEnum.HA58.ToString()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.WarehouseId == warehouse.WarehouseId); | 
|---|
|  |  |  | return palletTypeInfo.PalletType; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return -1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | public WebResponseContent OtherInGroup(Dt_InboundOrder inboundOrder,string? palletCode,int Initiallife,Dt_Warehouse warehouse,List<MatSerNumAnalysisModel> models) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error($"ç©æä¸å¯æ··æ¾"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //éªè¯å¤ææ¶é´æ ¼å¼ | 
|---|
|  |  |  | 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($"ç©æä¸å¯æ··æ¾"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //éªè¯å¤ææ¶é´æ ¼å¼ | 
|---|
|  |  |  | 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) | 
|---|
|  |  |  | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<ERPProItemsItem> proItemsItems = new List<ERPProItemsItem>(); | 
|---|
|  |  |  | Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x=>x.WarehouseId==mesProInOrder.WarehouseId); | 
|---|
|  |  |  | string batchNoRemark = ""; | 
|---|
|  |  |  | foreach (var item in mesProInOrder.Details) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | ERPProItemsItem proItemsItem = new ERPProItemsItem() | 
|---|
|  |  |  | 
|---|
|  |  |  | PartNum = item.ProductCode, | 
|---|
|  |  |  | Rev=item.ProductVersion, | 
|---|
|  |  |  | DateCode=item.DateCode, | 
|---|
|  |  |  | BatchNumber= item.BagNo, | 
|---|
|  |  |  | BatchNumber= item.ProductCode, | 
|---|
|  |  |  | XLocation=item.XSite, | 
|---|
|  |  |  | Xqty=item.XQty, | 
|---|
|  |  |  | QtySet=item.SETQty, | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | batchNoRemark += item.BagNo + ","; | 
|---|
|  |  |  | proItemsItems.Add(proItemsItem); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ERPProInboundModel proInboundModel = new ERPProInboundModel() | 
|---|
|  |  |  | 
|---|
|  |  |  | CreatorCode = "GSWMS", | 
|---|
|  |  |  | CompanyCode = "HATC", | 
|---|
|  |  |  | FactoryCode = "HA02", | 
|---|
|  |  |  | WarehouseCode = "HA71", | 
|---|
|  |  |  | LocationCode = "HA71", | 
|---|
|  |  |  | WarehouseCode = warehouse.WarehouseCode, | 
|---|
|  |  |  | LocationCode = warehouse.WarehouseCode, | 
|---|
|  |  |  | StockDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), | 
|---|
|  |  |  | StockFormType= "Production", | 
|---|
|  |  |  | StockFormItems= proItemsItems | 
|---|
|  |  |  | StockFormItems= proItemsItems, | 
|---|
|  |  |  | Remark=batchNoRemark | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | _invokeERPService.InvokeProInApi(proInboundModel); | 
|---|
|  |  |  | string response = _invokeERPService.InvokeProInApi(proInboundModel); | 
|---|
|  |  |  | ErpRequestContent requestContent = response.DeserializeObject<ErpRequestContent>(); | 
|---|
|  |  |  | if (requestContent.res != 1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error($"{requestContent.Data}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | content.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return palletTypeInfo.PalletType; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (warehouse.WarehouseCode == WarehouseEnum.HA58.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> | 
|---|
|  |  |  | /// å¤ææ£ç¡®æ¶é´æ ¼å¼ | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | public WebResponseContent IsValidMCDates(List<MatSerNumAnalysisModel> analysisModels) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string[] effDates = analysisModels.Select(x => x.EffectiveDate).Distinct().ToArray(); | 
|---|
|  |  |  | string[] ProDates = analysisModels.Select(x => x.ProductionDate).Distinct().ToArray(); | 
|---|
|  |  |  | foreach (string effDate in effDates) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string format = "yyyy-MM-dd"; // ç®æ æ ¼å¼ | 
|---|
|  |  |  | DateTime parsedDate; | 
|---|
|  |  |  | // è§£æå¹¶éªè¯æ ¼å¼ | 
|---|
|  |  |  | bool isValid = DateTime.TryParseExact( | 
|---|
|  |  |  | effDate, | 
|---|
|  |  |  | format, | 
|---|
|  |  |  | CultureInfo.InvariantCulture, | 
|---|
|  |  |  | DateTimeStyles.None, | 
|---|
|  |  |  | out parsedDate | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!isValid) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error("æ ¼å¼æ æææ¥æä¸åæ³"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | foreach (string ProDate in ProDates) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string format = "yyyy-MM-dd"; // ç®æ æ ¼å¼ | 
|---|
|  |  |  | DateTime parsedDate; | 
|---|
|  |  |  | // è§£æå¹¶éªè¯æ ¼å¼ | 
|---|
|  |  |  | bool isValid = DateTime.TryParseExact( | 
|---|
|  |  |  | ProDate, | 
|---|
|  |  |  | format, | 
|---|
|  |  |  | CultureInfo.InvariantCulture, | 
|---|
|  |  |  | DateTimeStyles.None, | 
|---|
|  |  |  | out parsedDate | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!isValid) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error("æ ¼å¼æ æææ¥æä¸åæ³"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return WebResponseContent.Instance.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|