| | |
| | | { |
| | | public class InventoryServices : ServiceBase<Dt_Inventory, IRepository<Dt_Inventory>>, IInventoryServices |
| | | { |
| | | public InventoryServices(IRepository<Dt_Inventory> BaseDal) : base(BaseDal) |
| | | private readonly IDeliveryOrderServices _deliveryOrderServices; |
| | | public InventoryServices(IRepository<Dt_Inventory> BaseDal, IDeliveryOrderServices deliveryOrderServices) : base(BaseDal) |
| | | { |
| | | _deliveryOrderServices = deliveryOrderServices; |
| | | } |
| | | |
| | | |
| | |
| | | try |
| | | { |
| | | var url = "http://121.37.118.63/GYZ2/95fck/repositoryInfo"; |
| | | // åèµ·è¯·æ± |
| | | var result = HttpHelper.Post(url, new { goods_no,batch_num}.ToJsonString()); |
| | | var result = HttpHelper.Post(url, new { goods_no, batch_num }.ToJsonString()); |
| | | |
| | | // ååºåå |
| | | var response = JsonConvert.DeserializeObject<UpstreamResponse<InventoryInfo>>(result); |
| | | |
| | | if (response.resultCode!="0") |
| | | if (response.resultCode != "0") |
| | | { |
| | | // è°ç¨å¼å¸¸æ¥å£ |
| | | SendErrorToUpstream(8, "", response.resultMsg ?? "䏿¸¸æ¥å£è¿å失败", ""); |
| | | return responseContent.Error(response.resultMsg ?? "䏿¸¸æ¥å£è¿å失败"); |
| | | } |
| | | |
| | | if (response.data == null || !response.data.Any()) |
| | | { |
| | | return responseContent.OK("æ æ°åºåæ°æ®"); |
| | | } |
| | | |
| | | Db.Ado.BeginTran(); |
| | | foreach (var item in response.data) |
| | | { |
| | | var Inver = new Dt_Inventory |
| | | { |
| | | Goods_no = item.goods_no, |
| | | Batch_num = item.batch_num, |
| | | Exp_date=item.exp_date, |
| | | Business_qty = item.business_qty, |
| | | Actual_qty = item.actural_qty, |
| | | }; |
| | | AddData(Inver); |
| | | // ä½¿ç¨ FirstOrDefault é¿å
æ¾ä¸å°è®°å½æ¶æåºå¼å¸¸ |
| | | var Inver = Db.Queryable<Dt_Inventory_Batch>() |
| | | .First(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num); |
| | | |
| | | if (Inver != null) |
| | | { |
| | | Inver.ERPStockQuantity = item.business_qty; |
| | | Db.Updateable(Inver).ExecuteCommand(); |
| | | } |
| | | } |
| | | Db.Ado.CommitTran(); |
| | | return responseContent.OK("åºåä¿¡æ¯åæ¥å®æ"); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// wcsåä¼ ç»æè°ç¨æçæ¹æ³ |
| | | /// wcsåä¼ ç»æè°ç¨æçæ¹æ³ ä¸ç®¡æ¯å
¥åº åºåº çç¹é½ä¼è°ç¨è¿ä¸ªæ¥å£ |
| | | /// </summary> |
| | | /// <param name="request"></param> |
| | | /// <returns></returns> |
| | | public ApiResponse<Dt_Inventory> OrderFeedback(EdiOrderCallbackRequest request) |
| | | public ApiResponse<Dt_InventoryInfo> OrderFeedback(EdiOrderCallbackRequest request) |
| | | { |
| | | try |
| | | { |
| | | { |
| | | // 1ï¸â£ æ ¡éªè¯·æ± |
| | | if (request == null || request.details == null || !request.details.Any()) |
| | | { |
| | | return new ApiResponse<Dt_Inventory> { code = "500", msg = "请æ±åæ°æ æ" }; |
| | | return new ApiResponse<Dt_InventoryInfo> { code = "500", msg = "请æ±åæ°æ æ" }; |
| | | } |
| | | BaseDal.Db.Ado.BeginTran();//å¼å¯äºå¡ |
| | | |
| | | //æ¥æ¾å°å
¨é¨ç |
| | | |
| | | foreach (var detail in request.details) |
| | | { |
| | | // å
æ¥åºåæ¯å¦åå¨ï¼æç
§äº§åç¼å·åæ¹æ¬¡æ¥å¯»æ¾ï¼ |
| | | var entity = BaseDal.Db.Queryable<Dt_Inventory>() |
| | | .First(x => x.Goods_no == detail.productCode && x.Batch_num == detail.batchNo); |
| | | //å°éåä¸çæ°éè¿è¡ç´¯å |
| | | // å®å
¨è½¬æ¢ |
| | | var goods = Db.Queryable<Dt_MaterielInfo>().Where(x => x.MaterielCode == detail.productCode).First(); |
| | | |
| | | //æ£å¸¸åºå
¥åº |
| | | decimal orderQty = detail.orderDetails?.Sum(x => decimal.TryParse(x.quantity, out var q) ? q : 0) ?? 0; |
| | | //çç¹çäº |
| | | decimal diffQty = detail.stocktakingDetails?.Sum(x => Convert.ToDecimal(x.differenceQuantity)) ?? 0; |
| | | // 3ï¸ è®¡ç®å
¥åºæ°éï¼åæ£ï¼éå orderDetails ä¸çæ¯ä¸ª EdiOrderBoxDto 对象 |
| | | decimal orderQty = detail.orderDetails? |
| | | .Sum(x => decimal.TryParse(x.quantity, out var q) ? Math.Abs(q) : 0) |
| | | ?? 0; |
| | | |
| | | // 5ï¸â£ æ¥è¯¢åºå详æ
|
| | | var entity = BaseDal.Db.Queryable<Dt_InventoryInfo>() |
| | | .First(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo && x.LocationCode == "ç«åº"); |
| | | //æ¥è¯¢ç©æè¡¨ |
| | | var Goods = BaseDal.Db.Queryable<Dt_MaterielInfo>().First(x => x.MaterielCode == detail.productCode); |
| | | |
| | | if (entity == null) |
| | | { |
| | | // 妿ä¸åå¨ï¼æ°å»ºä¸æ¡ |
| | | entity = new Dt_Inventory |
| | | entity = new Dt_InventoryInfo |
| | | { |
| | | Goods_no = detail.productCode ?? detail.productName, |
| | | Reservoirarea = "é»è®¤åºåº", |
| | | Batch_num = detail.batchNo, |
| | | //ä¸å¡åºå |
| | | Business_qty = 0, |
| | | //å®é
åºå |
| | | Actual_qty = 0 |
| | | PalletCode = detail.orderDetails?.FirstOrDefault()?.palletCode ?? "", |
| | | WarehouseCode = "001", |
| | | LocationCode = "ç«åº", |
| | | StockStatus = 1, |
| | | MaterielCode = detail.productCode ?? detail.productName, |
| | | MaterielName = detail.productName ?? "", |
| | | MaterielSpec = detail.productSpecifications ?? "", |
| | | BatchNo = detail.batchNo, |
| | | StockQuantity = 0, |
| | | OutboundQuantity = 0, |
| | | SupplyQuantity = 0, |
| | | AvailableQuantity = 0, |
| | | InDate = DateTime.Now, |
| | | ProductionDate = detail.finishDate.ToString("yyyy-MM-dd"), |
| | | ShelfLife = 0, |
| | | ValidityPeriod = "", |
| | | Remark = "WCSåä¼ å建" |
| | | }; |
| | | } |
| | | |
| | | // 6ï¸â£ æ¥è¯¢åºåæ¹æ¬¡ä¿¡æ¯ |
| | | var batch = BaseDal.Db.Queryable<Dt_Inventory_Batch>() |
| | | .First(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo); |
| | | |
| | | if (batch == null) |
| | | { |
| | | batch = new Dt_Inventory_Batch |
| | | { |
| | | MaterielCode = detail.productCode ?? detail.productName, |
| | | MaterielName = detail.productName ?? "", |
| | | MaterielSpec = detail.productSpecifications ?? "", |
| | | BatchNo = detail.batchNo, |
| | | StockQuantity = 0, |
| | | OutboundQuantity = 0, |
| | | AvailableQuantity = 0, |
| | | SupplyQuantity = 0, |
| | | ERPStockQuantity = 0, |
| | | Status = false, |
| | | ProductionDate = detail.finishDate.ToString("yyyy-MM-dd"), |
| | | ValidityPeriod = DateTime.Now.AddYears(1).ToString("yyyy-MM-dd"), |
| | | Remark = "èªå¨å建" |
| | | }; |
| | | } |
| | | |
| | | // 7ï¸â£ æè®¢åç±»åæ§è¡ä¸åé»è¾ |
| | | switch (request.orderType) |
| | | { |
| | | case "1": // å
¥åº |
| | | entity.Business_qty += orderQty; |
| | | entity.Actual_qty += orderQty; |
| | | case "1": //å
¥åº |
| | | entity.StockQuantity = orderQty; //å®é
åºå |
| | | entity.AvailableQuantity = orderQty; |
| | | entity.InDate = DateTime.Now; |
| | | entity.Remark = "å
¥åºååä¼ "; |
| | | |
| | | |
| | | batch.StockQuantity = orderQty; |
| | | batch.AvailableQuantity = orderQty; |
| | | batch.Remark = "å
¥åºååä¼ "; |
| | | UpdateInboundOrderDetailStatus(detail.batchNo, detail.productCode); |
| | | break; |
| | | |
| | | case "2": // åºåº |
| | | entity.Business_qty -= orderQty; |
| | | entity.Actual_qty -= orderQty; |
| | | if (entity.Business_qty < 0) entity.Business_qty = 0; // å¯éï¼é²æ¢è´æ° |
| | | if (entity.Actual_qty < 0) entity.Actual_qty = 0; |
| | | case "2": // åºåº æ»100 åº20 |
| | | decimal actualOutQty = entity.StockQuantity - orderQty;// è®¡ç®æ¬æ¬¡å®é
åºåºæ°é 20 |
| | | entity.StockQuantity=orderQty; //å®é
åºåæ° 100 |
| | | entity.OutboundQuantity =Math.Max(0,entity.OutboundQuantity-actualOutQty); //å¾
åºåºæ°é |
| | | entity.AvailableQuantity = entity.StockQuantity - entity.OutboundQuantity;//å¯ç¨åºå |
| | | if (entity.StockQuantity < 0) entity.StockQuantity = 0; |
| | | entity.Remark = "åºåºååä¼ "; |
| | | |
| | | |
| | | batch.StockQuantity = orderQty; |
| | | batch.OutboundQuantity =Math.Max(0,batch.OutboundQuantity-actualOutQty);//å¾
åºåºæ°é |
| | | batch.AvailableQuantity = batch.StockQuantity - batch.OutboundQuantity; //å¯ç¨åºå |
| | | if (batch.StockQuantity < 0) batch.StockQuantity = 0; |
| | | batch.Remark = "åºåºååä¼ "; |
| | | UpdateOutboundOrderDetailStatus(detail.batchNo, detail.productCode); |
| | | //è°æ¨ä»»å¡ |
| | | _deliveryOrderServices.CreateAllocatInOut(goods); |
| | | break; |
| | | |
| | | case "3": // çç¹ |
| | | if (detail.stocktakingDetails != null && detail.stocktakingDetails.Any()) |
| | | decimal diff = detail.ea ?? 0; // 差弿° |
| | | int flag = detail.isLossOrProfit ?? 3; // 1=çäº, 2=çç, 3=çä¸ |
| | | if (flag == 1) // çäº |
| | | { |
| | | foreach (var stock in detail.stocktakingDetails) |
| | | { |
| | | //æ¯æ¬¡é½åªæ¿ä¸æ¡æç»ä¸çæ°é |
| | | decimal diff = Convert.ToDecimal(stock.differenceQuantity); |
| | | if (stock.IsProfit == "1") // çç |
| | | { |
| | | entity.Business_qty += diff;//妿ççäºå¤äºï¼å°±å°ä¸å¡æ°é+ï¼çäºåç¸å |
| | | entity.PalletCode = stock.palletCode; |
| | | } |
| | | else // çäº |
| | | { |
| | | entity.Business_qty -= diff; |
| | | entity.PalletCode = stock.palletCode; |
| | | } |
| | | } |
| | | //åºåæ°-差弿°=çäº |
| | | batch.SupplyQuantity +=( batch.StockQuantity - diff); |
| | | batch.Remark = "çç¹ååä¼ - çäº"; |
| | | } |
| | | else if (flag == 2) // çç |
| | | { |
| | | //åºåæ°+差弿°=çç |
| | | batch.SupplyQuantity +=(batch.StockQuantity + diff); |
| | | batch.Remark = "çç¹ååä¼ - çç"; |
| | | } |
| | | else // çä¸ |
| | | { |
| | | batch.Remark = "çç¹ååä¼ - çä¸"; |
| | | } |
| | | break; |
| | | } |
| | | |
| | | // ä¿åæ°æ® |
| | | if (entity.Id == 0) // æ°å»º |
| | | // 2ï¸â£ å¼å¯äºå¡ |
| | | BaseDal.Db.Ado.BeginTran(); |
| | | // 8ï¸â£ ä¿åæ°æ® |
| | | if (entity.Id == 0) |
| | | BaseDal.Db.Insertable(entity).ExecuteCommand(); |
| | | else // æ´æ° |
| | | else |
| | | BaseDal.Db.Updateable(entity).ExecuteCommand(); |
| | | |
| | | if (batch.Id == 0) |
| | | BaseDal.Db.Insertable(batch).ExecuteCommand(); |
| | | else |
| | | BaseDal.Db.Updateable(batch).ExecuteCommand(); |
| | | } |
| | | BaseDal.Db.Ado.CommitTran(); // æäº¤äºå¡ |
| | | return new ApiResponse<Dt_Inventory> { code = "0", msg = "æå" }; |
| | | |
| | | // 9ï¸â£ æäº¤äºå¡ |
| | | BaseDal.Db.Ado.CommitTran(); |
| | | |
| | | return new ApiResponse<Dt_InventoryInfo> |
| | | { |
| | | code = "0", |
| | | msg = "æå" |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | BaseDal.Db.Ado.RollbackTran();//åæ»äºå¡ |
| | | return new ApiResponse<Dt_Inventory> { code = "500", msg = ex.Message }; |
| | | // ð åæ»äºå¡ |
| | | BaseDal.Db.Ado.RollbackTran(); |
| | | |
| | | return new ApiResponse<Dt_InventoryInfo> |
| | | { |
| | | code = "500", |
| | | msg = $"å¤ç失败: {ex.Message}" |
| | | }; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ´æ°å
¥åºåè¯¦ç» |
| | | /// </summary> |
| | | /// <param name="batchNo">æ¹æ¬¡å·</param> |
| | | /// <param name="productCode">ç©æåç¼ç /param> |
| | | public void UpdateInboundOrderDetailStatus(string batchNo,string productCode) |
| | | { |
| | | try |
| | | { |
| | | //æ¥è¯¢è¯¦æ
|
| | | var detail = BaseDal.Db.Queryable<Dt_CabinOrderDetail>() |
| | | .First(x => x.Goods_no == productCode && x.Batch_num == batchNo && x.OrderDetailStatus == "å¼å§" && x.Status == 1); |
| | | //æ¥æ¾å°åæ ¹æ®ç©æç¶æï¼OrderDetailStatus==å¼å§ï¼ è¯¥ç¶æStatus=1ä¿®æ¹è¯¥æ¡è¯¦æ
çOrderDetailStatus==已宿 |
| | | detail.OrderDetailStatus = "已宿"; |
| | | BaseDal.Db.Updateable(detail).ExecuteCommand(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// //æ¥æ¾å°åæ ¹æ®ç©æç¶æï¼OrderDetailStatus==å¼å§ï¼ è¯¥ç¶æStatus=1ä¿®æ¹è¯¥æ¡è¯¦æ
çOrderDetailStatus==已宿 |
| | | /// </summary> |
| | | /// <param name="batchNo"></param> |
| | | /// <param name="productCode"></param> |
| | | public void UpdateOutboundOrderDetailStatus(string batchNo, string productCode) |
| | | { |
| | | try |
| | | { |
| | | //æ¥è¯¢è¯¦æ
|
| | | var detail = BaseDal.Db.Queryable<Dt_DeliveryOrderDetail>() |
| | | .First(x => x.Goods_no == productCode && x.Batch_num == batchNo && x.OotDetailStatus == "å¼å§" && x.Status == 1); |
| | | detail.OotDetailStatus = "已宿"; |
| | | BaseDal.Db.Updateable(detail).ExecuteCommand(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | /// <summary> |