| | |
| | | using HslCommunication; |
| | | using MailKit.Search; |
| | | using Microsoft.Data.SqlClient; |
| | | using Microsoft.IdentityModel.Tokens; |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml.Style; |
| | | using Org.BouncyCastle.Asn1.X509; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | |
| | | using WIDESEA_Common; |
| | | using WIDESEA_Common.LocationEnum; |
| | | using WIDESEA_Common.OrderEnum; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Common.TaskEnum; |
| | | using WIDESEA_Common.WareHouseEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.Outbound; |
| | | using WIDESEA_DTO.SquareCabin; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_ISquareCabinServices; |
| | |
| | | |
| | | namespace WIDESEA_SquareCabinServices |
| | | { |
| | | public class DeliveryOrderServices : ServiceBase<Dt_DeliveryOrder, IRepository<Dt_DeliveryOrder>>, IDeliveryOrderServices |
| | | public partial class DeliveryOrderServices : ServiceBase<Dt_DeliveryOrder, IRepository<Dt_DeliveryOrder>>, IDeliveryOrderServices |
| | | { |
| | | static string SearchDate = ""; |
| | | private readonly IBasicService _basicService; |
| | | private readonly ICabinOrderServices _cabinOrderServices; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IInventory_BatchServices _inventory_BatchServices; |
| | | private readonly ILocationInfoService _locationInfoService; |
| | | private readonly IInventoryInfoService _inventoryInfoService; |
| | | private readonly IDeliveryOrderDetailServices _deliveryOrderDetailServices; |
| | | private readonly ISupplyTaskService _supplyTaskService; |
| | | private readonly ISupplyTaskHtyService _supplyTaskHtyService; |
| | | private readonly ITacticsService _tacticsService; |
| | | private readonly IMaterielInfoService _materielInfoService; |
| | | private readonly IMessageInfoService _messageInfoService; |
| | | public IRepository<Dt_DeliveryOrder> Repository => BaseDal; |
| | | public DeliveryOrderServices(IRepository<Dt_DeliveryOrder> BaseDal, IBasicService basicService, IUnitOfWorkManage unitOfWorkManage, IInventory_BatchServices inventory_BatchServices, IInventoryInfoService inventoryInfoService, IDeliveryOrderDetailServices deliveryOrderDetailServices, ISupplyTaskService supplyTaskService) : base(BaseDal) |
| | | public DeliveryOrderServices(IRepository<Dt_DeliveryOrder> BaseDal, IUnitOfWorkManage unitOfWorkManage, IInventory_BatchServices inventory_BatchServices, IInventoryInfoService inventoryInfoService, IDeliveryOrderDetailServices deliveryOrderDetailServices, ISupplyTaskService supplyTaskService, ICabinOrderServices cabinOrderServices, ITacticsService tacticsService, ISupplyTaskHtyService supplyTaskHtyService, IMessageInfoService messageInfoService, IMaterielInfoService materielInfoService, ILocationInfoService locationInfoService) : base(BaseDal) |
| | | { |
| | | _basicService = basicService; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _deliveryOrderDetailServices = deliveryOrderDetailServices; |
| | | _supplyTaskService = supplyTaskService; |
| | | _inventory_BatchServices = inventory_BatchServices; |
| | | _inventoryInfoService = inventoryInfoService; |
| | | _cabinOrderServices = cabinOrderServices; |
| | | _tacticsService = tacticsService; |
| | | _supplyTaskHtyService = supplyTaskHtyService; |
| | | _messageInfoService = messageInfoService; |
| | | _materielInfoService = materielInfoService; |
| | | _locationInfoService = locationInfoService; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·å䏿¸¸åºåºå 0æå1失败 |
| | | /// </summary> |
| | | /// <param name="searchDate"></param> |
| | | /// <returns></returns> |
| | | //public WebResponseContent GetUpstreamOutOrder() |
| | | //{ |
| | | // var responseContent = new WebResponseContent(); |
| | | // try |
| | | // { |
| | | // // 请æ±å°å |
| | | // var url = "http://121.37.118.63:80/GYZ2/95fck/outOrder"; |
| | | |
| | | // //if (string.IsNullOrEmpty(SearchDate)) SearchDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | // //// 请æ±åæ° |
| | | // var requestData = new |
| | | // { |
| | | // //searchDate = SearchDate |
| | | // searchDate = "2022-10-10 20:45:16" // æ£ç¡®çæ ¼å¼ |
| | | // }; |
| | | // //SearchDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss"); |
| | | // // åèµ·è¯·æ± |
| | | // var result = HttpHelper.Post(url, requestData.ToJsonString()); |
| | | |
| | | // // ååºåå |
| | | // var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstramOutOrderInfo>>(result); |
| | | |
| | | // if (response.resultCode != "0") |
| | | // { |
| | | // SendErrorToUpstream(3, "", response.resultMsg ?? "䏿¸¸æ¥å£è¿å失败", ""); |
| | | // return responseContent.Error(response.resultMsg ?? "䏿¸¸æ¥å£è¿å失败"); |
| | | // } |
| | | |
| | | // if (response.data == null || !response.data.Any()) |
| | | // { |
| | | // return responseContent.OK("æ æ°åºåºåæ°æ®"); |
| | | // } |
| | | // // è·åææå·²åå¨çåºåºåå· |
| | | // var existingOutOrderNos = BaseDal.Db.Queryable<Dt_DeliveryOrder>() |
| | | // .Select(x => x.Out_no) |
| | | // .ToList(); |
| | | |
| | | // // è¿æ»¤æå·²åå¨çåºåºå |
| | | // var newOutOrders = response.data |
| | | // .Where(outorder => !existingOutOrderNos.Contains(outorder.order_no))//order_noåºåºåå· |
| | | // .ToList(); |
| | | |
| | | // if (!newOutOrders.Any()) |
| | | // { |
| | | // return responseContent.OK("ææåºåºåå·²åå¨ï¼æ éæ°å¢"); |
| | | // } |
| | | // Db.Ado.BeginTran(); |
| | | // try |
| | | // { |
| | | // List<Dt_DeliveryOrder> _DeliveryOrders = new List<Dt_DeliveryOrder>(); |
| | | // ////åå¨åºåºåå· |
| | | // //List<string> orderNos = new List<string>(); |
| | | |
| | | // foreach (var outorder in newOutOrders) |
| | | // { |
| | | // var entityOrder = new Dt_DeliveryOrder |
| | | // { |
| | | // Out_no = outorder.order_no, |
| | | // Out_type = outorder.order_type, |
| | | // Client_no = outorder.client_no, |
| | | // Client_name = outorder.client_name, |
| | | // Account_time = outorder.account_time, |
| | | // Warehouse_no=outorder.warehouse_no, |
| | | // OutStatus = "æªå®æ", |
| | | // //Details = outorder.details.Select(d => new Dt_DeliveryOrderDetail |
| | | // //{ |
| | | // // // InsertNav ä¼èªå¨è®¾ç½®å
³èåæ®µ DeliveryOrderId |
| | | // // Goods_no = d.goods_no, |
| | | // // Order_qty = d.order_qty, |
| | | // // Batch_num = d.batch_num, |
| | | // // Exp_date = d.exp_date, |
| | | // // OotDetailStatus = "æ°å»º", |
| | | // // Status = outorder.warehouse_no == "001" ? 0 : 2, //妿æ¯001æ¿é£ä¹å°ç¶æè®¾ç½®ä¸º0ï¼2为人工å¤ç |
| | | // //}).ToList() |
| | | // }; |
| | | // #region æ ¹æ®åºåºå详æ
æ¥æ¾ç©æåç§°ãæ¹æ¬¡çåºåä¿¡æ¯(Dt_InventoryInfo)ï¼æ ¹æ®å
å
¥å
åº,CreateDate |
| | | // //æ ¹æ®ç©æåç§°æ¥æ¾ç©æä¿¡æ¯ |
| | | // foreach (var item in outorder.details) |
| | | // { |
| | | // // å°ä¸æ¸¸åºåºæ°éè½¬ä¸ºæ£æ° |
| | | // item.order_qty = Math.Abs(item.order_qty); |
| | | // var medication = BaseDal.Db.Queryable<Dt_MedicineGoods>() |
| | | // .Where(m => m.Goods_no == item.goods_no) |
| | | // .First(); |
| | | |
| | | |
| | | // } |
| | | |
| | | // //æ ¹æ®ç®±è§å¤ææ¯å¦ææ£ä»¶ï¼è®¡ç®åºæ£ä»¶æ°éåæ´ä»¶æ° |
| | | |
| | | // //æ ¹æ®å
¥åºæ¶é´åç»ï¼ææ£ä»¶å°±ä¼å
åé
ç«åºæ°éï¼æ´ä»¶ä¼å
åé
å¹³åºæ°é |
| | | |
| | | |
| | | // #endregion |
| | | // _DeliveryOrders.Add(entityOrder); |
| | | |
| | | // }; |
| | | |
| | | // // ä½¿ç¨ InsertNav 䏿¬¡æ§æå
¥ä¸»è¡¨ååè¡¨æ°æ® |
| | | // BaseDal.Db.InsertNav(_DeliveryOrders).Include(x => x.Details).ExecuteCommand(); |
| | | |
| | | // // è¿éå¯ä»¥æ·»å ä¸åå° WCS çé»è¾ |
| | | // // var result = EdiOut(); // åç»ä¸æ¸¸ |
| | | |
| | | // Db.Ado.CommitTran(); |
| | | // return responseContent.OK("忥åºåºåæå"); |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // Db.Ado.RollbackTran(); |
| | | // SendErrorToUpstream(3, "", ex.Message, ""); |
| | | // return responseContent.Error("åæ¥å¤±è´¥: " + ex.Message); |
| | | // } |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // // å
¨å±å¼å¸¸æ¶ï¼ä¹æ¨éå¼å¸¸ç»ä¸æ¸¸ |
| | | // SendErrorToUpstream(3, "", ex.Message, ""); |
| | | // return responseContent.Error("åæ¥å¤±è´¥: " + ex.Message); |
| | | // } |
| | | //} |
| | | |
| | | |
| | | |
| | | public WebResponseContent GetUpstreamOutOrder() |
| | | public override WebResponseContent UpdateData(SaveModel saveModel) |
| | | { |
| | | var responseContent = new WebResponseContent(); |
| | | try |
| | | { |
| | | var url = "http://121.37.118.63:80/GYZ2/95fck/outOrder"; |
| | | |
| | | var requestData = new |
| | | int id = saveModel.MainData["id"].ObjToInt(); |
| | | var warehouse_no = saveModel.MainData["warehouse_no"].ToString(); |
| | | var out_no = saveModel.MainData["out_no"].ToString(); |
| | | //OutboundOrderAddDTO outboundOrder = saveModel.MainData.DicToModel<OutboundOrderAddDTO>(); |
| | | //Dt_DeliveryOrder deliveryOrder = BaseDal.QueryFirst(x => x.Id == id); |
| | | List<DeliveryOrderDetailAddDTO> orderDetailAddDTOs = saveModel.DetailData.DicToIEnumerable<DeliveryOrderDetailAddDTO>(); |
| | | orderDetailAddDTOs = orderDetailAddDTOs.Where(x => x.id == 0).ToList(); |
| | | if (orderDetailAddDTOs.Count < 1) return WebResponseContent.Instance.OK(); |
| | | if (orderDetailAddDTOs.Where(x => string.IsNullOrEmpty(x.locationCode)).Any()) return WebResponseContent.Instance.Error("è´§ä½å·ä¸ºå¿
å¡«åæ®µ!"); |
| | | if (orderDetailAddDTOs.Where(x => string.IsNullOrEmpty(x.exp_date)).Any()) return WebResponseContent.Instance.Error("ææä¸ºå¿
å¡«åæ®µ!"); |
| | | var LocationCodes = orderDetailAddDTOs.Select(x => x.locationCode); |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoService.Repository.QueryData(x => x.WarehouseCode == warehouse_no && LocationCodes.Contains(x.LocationCode)); |
| | | var diff = LocationCodes.Except(locationInfos.Select(x => x.LocationCode)).ToArray(); |
| | | if (diff.Length > 0) return WebResponseContent.Instance.Error($"è´§ä½ç¼å·ã{string.Join(", ", diff)}ãä¸å±äºå½ååºæ¿"); |
| | | var array1 = orderDetailAddDTOs.Select(x => x.goods_no); |
| | | var MaterielInfos = _materielInfoService.Repository.QueryData(x => array1.Contains(x.MaterielCode)); |
| | | var array2 = MaterielInfos.Select(x => x.MaterielCode); |
| | | diff = array1.Except(array2).ToArray(); |
| | | if (diff.Length > 0) return WebResponseContent.Instance.Error($"请维æ¤ç©æç¼å·ã{string.Join(", ", diff)}ãçç©æä¿¡æ¯"); |
| | | if (warehouse_no == WarehouseEnum.ç«åº.ObjToInt().ToString("000")) |
| | | { |
| | | searchDate = "2022-10-10 20:45:16" |
| | | }; |
| | | |
| | | var result = HttpHelper.Post(url, requestData.ToJsonString()); |
| | | var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstramOutOrderInfo>>(result); |
| | | |
| | | if (response.resultCode != "0") |
| | | { |
| | | SendErrorToUpstream(3, "", response.resultMsg ?? "䏿¸¸æ¥å£è¿å失败", ""); |
| | | return responseContent.Error(response.resultMsg ?? "䏿¸¸æ¥å£è¿å失败"); |
| | | } |
| | | |
| | | if (response.data == null || !response.data.Any()) |
| | | { |
| | | return responseContent.OK("æ æ°åºåºåæ°æ®"); |
| | | } |
| | | |
| | | // å·²åå¨åºåºåå· |
| | | var existingOutOrderNos = BaseDal.Db.Queryable<Dt_DeliveryOrder>() |
| | | .Select(x => x.Out_no) |
| | | .ToList(); |
| | | |
| | | // æ°åºåºå |
| | | var newOutOrders = response.data |
| | | .Where(outorder => !existingOutOrderNos.Contains(outorder.order_no)) |
| | | .ToList(); |
| | | |
| | | if (!newOutOrders.Any()) |
| | | { |
| | | return responseContent.OK("ææåºåºåå·²åå¨ï¼æ éæ°å¢"); |
| | | } |
| | | |
| | | Db.Ado.BeginTran(); |
| | | try |
| | | { |
| | | List<Dt_DeliveryOrder> _DeliveryOrders = new List<Dt_DeliveryOrder>(); |
| | | |
| | | foreach (var outorder in newOutOrders) |
| | | var MaterielInfos1 = MaterielInfos.Where(x => x.MaterielSourceType == MaterielSourceTypeEnum.PurchasePart).ToList(); |
| | | if (MaterielInfos1.Count > 0) |
| | | { |
| | | var entityOrder = new Dt_DeliveryOrder |
| | | { |
| | | Out_no = outorder.order_no, |
| | | Out_type = outorder.order_type, |
| | | Client_no = outorder.client_no, |
| | | Client_name = outorder.client_name, |
| | | Account_time = outorder.account_time, |
| | | Warehouse_no = outorder.warehouse_no, |
| | | OutStatus = "æªå®æ", |
| | | Details = new List<Dt_DeliveryOrderDetail>() |
| | | }; |
| | | |
| | | // éååºåºæç» |
| | | foreach (var item in outorder.details) |
| | | { |
| | | // 1ï¸â£ è½¬ä¸ºæ£æ°ï¼ä¸æ¸¸å¯è½ä¼ è´æ°ï¼ |
| | | item.order_qty = Math.Abs(item.order_qty); |
| | | decimal orderQty = (decimal)item.order_qty; |
| | | |
| | | // 2ï¸â£ æ¥ç©æåºç¡ä¿¡æ¯ï¼è·åç®±è§ï¼ |
| | | var medication = BaseDal.Db.Queryable<Dt_MedicineGoods>() |
| | | .Where(m => m.Goods_no == item.goods_no) |
| | | .First(); |
| | | |
| | | if (medication == null) |
| | | { |
| | | SendErrorToUpstream(3, "", $"æ¾ä¸å°ç©æä¿¡æ¯ï¼{item.goods_no}", ""); |
| | | continue; |
| | | } |
| | | |
| | | decimal boxQty = medication.BoxQty <= 0 ? 1 : medication.BoxQty; |
| | | |
| | | // 3ï¸â£ è®¡ç®æ´ä»¶ä¸æ£ä»¶æ°é |
| | | var fullBoxes = (int)(orderQty / boxQty); // æ´ä»¶ç®±æ° |
| | | var partialQty = orderQty % boxQty; // æ£ä»¶æ°é |
| | | |
| | | // è¥ä¸æ¸¸ç»äºæ¹æ¬¡å·ï¼åä¼å
å¹é
|
| | | string requestedBatch = string.IsNullOrEmpty(item.batch_num) ? null : item.batch_num; |
| | | |
| | | // helper: æ¥è¯¢åºå彿°ï¼æå
¥åºæ¶é´ååºï¼ |
| | | Func<int, List<Dt_InventoryInfo>> queryInventoryByStockStatus = (stockStatus) => |
| | | { |
| | | var q = BaseDal.Db.Queryable<Dt_InventoryInfo>() |
| | | .Where(i => i.MaterielCode == item.goods_no && |
| | | (i.StockQuantity - i.OutboundQuantity) > 0 && |
| | | i.StockStatus == stockStatus); |
| | | |
| | | if (!string.IsNullOrEmpty(requestedBatch)) |
| | | q = q.Where(i => i.BatchNo == requestedBatch); |
| | | |
| | | return q.OrderBy(i => i.InDate).ToList(); |
| | | }; |
| | | |
| | | // 4ï¸â£åé
æ£ä»¶ï¼ä¼å
ç«åº Status=1ï¼ |
| | | decimal remainingPartial = partialQty; |
| | | if (remainingPartial > 0) |
| | | { |
| | | var invList_ly = queryInventoryByStockStatus(1); |
| | | foreach (var inv in invList_ly) |
| | | { |
| | | if (remainingPartial <= 0) break; |
| | | |
| | | decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity); |
| | | if (available <= 0) continue; |
| | | |
| | | decimal use = Math.Min(available, remainingPartial); |
| | | |
| | | var detail = new Dt_DeliveryOrderDetail |
| | | { |
| | | Goods_no = item.goods_no, |
| | | Order_qty = use, |
| | | Batch_num = inv.BatchNo, |
| | | Exp_date = inv.ValidityPeriod, |
| | | OotDetailStatus = "æ°å»º", |
| | | Status = 0, //ç«åº |
| | | Reservoirarea = inv.LocationCode |
| | | }; |
| | | entityOrder.Details.Add(detail); |
| | | |
| | | inv.OutboundQuantity += (float)use; |
| | | BaseDal.Db.Updateable(inv).ExecuteCommand(); |
| | | |
| | | remainingPartial -= use; |
| | | } |
| | | |
| | | // ç«åºä¸å¤ â å¹³åºè¡¥ (Status=2) |
| | | if (remainingPartial > 0) |
| | | { |
| | | var invList_pk = queryInventoryByStockStatus(2); |
| | | foreach (var inv in invList_pk) |
| | | { |
| | | if (remainingPartial <= 0) break; |
| | | |
| | | decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity); |
| | | if (available <= 0) continue; |
| | | |
| | | decimal use = Math.Min(available, remainingPartial); |
| | | |
| | | var detail = new Dt_DeliveryOrderDetail |
| | | { |
| | | Goods_no = item.goods_no, |
| | | Order_qty = use, |
| | | Batch_num = inv.BatchNo, |
| | | Exp_date = inv.ValidityPeriod, |
| | | OotDetailStatus = "æ°å»º", |
| | | Status = 2, //å¹³åº |
| | | Reservoirarea = inv.LocationCode |
| | | }; |
| | | entityOrder.Details.Add(detail); |
| | | |
| | | inv.OutboundQuantity += (float)use; |
| | | BaseDal.Db.Updateable(inv).ExecuteCommand(); |
| | | |
| | | remainingPartial -= use; |
| | | } |
| | | } |
| | | |
| | | if (remainingPartial > 0) |
| | | { |
| | | SendErrorToUpstream(3, "", $"åºåºå[{outorder.order_no}]ç©æ[{item.goods_no}]æ£ä»¶åºåä¸è¶³ï¼æªåé
ï¼{remainingPartial}", ""); |
| | | } |
| | | } |
| | | |
| | | //åé
æ´ä»¶ï¼ä¼å
å¹³åº Status=2ï¼ |
| | | int remainingFullBoxes = fullBoxes; |
| | | if (remainingFullBoxes > 0) |
| | | { |
| | | var invList_pk = queryInventoryByStockStatus(2); |
| | | foreach (var inv in invList_pk) |
| | | { |
| | | if (remainingFullBoxes <= 0) break; |
| | | |
| | | decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity); |
| | | if (available < boxQty) continue; |
| | | |
| | | int canProvideBoxes = (int)(available / boxQty); |
| | | if (canProvideBoxes <= 0) continue; |
| | | |
| | | int useBoxes = Math.Min(canProvideBoxes, remainingFullBoxes); |
| | | decimal useQty = useBoxes * boxQty; |
| | | |
| | | var detail = new Dt_DeliveryOrderDetail |
| | | { |
| | | Goods_no = item.goods_no, |
| | | Order_qty = useQty, |
| | | Batch_num = inv.BatchNo, |
| | | Exp_date = inv.ValidityPeriod, |
| | | OotDetailStatus = "æ°å»º", |
| | | Status = 2, //å¹³åº |
| | | Reservoirarea = inv.LocationCode |
| | | }; |
| | | entityOrder.Details.Add(detail); |
| | | |
| | | inv.OutboundQuantity += (float)useQty; |
| | | BaseDal.Db.Updateable(inv).ExecuteCommand(); |
| | | |
| | | remainingFullBoxes -= useBoxes; |
| | | } |
| | | |
| | | // å¹³åºä¸å¤ â ç«åºè¡¥ (Status=1) |
| | | if (remainingFullBoxes > 0) |
| | | { |
| | | var invList_ly = queryInventoryByStockStatus(1); |
| | | foreach (var inv in invList_ly) |
| | | { |
| | | if (remainingFullBoxes <= 0) break; |
| | | |
| | | decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity); |
| | | if (available < boxQty) continue; |
| | | |
| | | int canProvideBoxes = (int)(available / boxQty); |
| | | if (canProvideBoxes <= 0) continue; |
| | | |
| | | int useBoxes = Math.Min(canProvideBoxes, remainingFullBoxes); |
| | | decimal useQty = useBoxes * boxQty; |
| | | |
| | | var detail = new Dt_DeliveryOrderDetail |
| | | { |
| | | Goods_no = item.goods_no, |
| | | Order_qty = useQty, |
| | | Batch_num = inv.BatchNo, |
| | | Exp_date = inv.ValidityPeriod, |
| | | OotDetailStatus = "æ°å»º", |
| | | Status = 0, //ç«åºï¼è¡¥æ´ç®±ï¼ |
| | | Reservoirarea = inv.LocationCode |
| | | }; |
| | | entityOrder.Details.Add(detail); |
| | | |
| | | inv.OutboundQuantity += (float)useQty; |
| | | BaseDal.Db.Updateable(inv).ExecuteCommand(); |
| | | |
| | | remainingFullBoxes -= useBoxes; |
| | | } |
| | | } |
| | | |
| | | if (remainingFullBoxes > 0) |
| | | { |
| | | decimal unfilledQty = remainingFullBoxes * boxQty; |
| | | SendErrorToUpstream(3, "", $"åºåºå[{outorder.order_no}]ç©æ[{item.goods_no}]æ´ç®±åºåä¸è¶³ï¼æªåé
æ°éï¼{unfilledQty}", ""); |
| | | } |
| | | } |
| | | } |
| | | |
| | | _DeliveryOrders.Add(entityOrder); |
| | | return WebResponseContent.Instance.Error($"ç©æç¼å·ã{string.Join(", ", MaterielInfos1.Select(x => x.MaterielCode))}ãçç©æå±æ§å类为大件ï¼ä¸å¯å
¥ç«åº"); |
| | | } |
| | | |
| | | // æå
¥ä¸»è¡¨+æç» |
| | | BaseDal.Db.InsertNav(_DeliveryOrders) |
| | | .Include(x => x.Details) |
| | | .ExecuteCommand(); |
| | | |
| | | Db.Ado.CommitTran(); |
| | | return responseContent.OK("忥åºåºåæå"); |
| | | } |
| | | catch (Exception ex) |
| | | var InventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.WarehouseCode == warehouse_no && array2.ToList().Contains(x.MaterielCode)); |
| | | var Batchs = _inventory_BatchServices.Repository.QueryData(x => array2.Contains(x.MaterielCode)); |
| | | List<Dt_DeliveryOrderDetail> deliveryOrderDetails = new List<Dt_DeliveryOrderDetail>(); |
| | | List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>(); |
| | | List<Dt_InventoryInfo> inventoryInfos = new List<Dt_InventoryInfo>(); |
| | | List<Dt_Inventory_Batch> inventory_Batches = new List<Dt_Inventory_Batch>(); |
| | | foreach (var item in orderDetailAddDTOs) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | SendErrorToUpstream(3, "", ex.Message, ""); |
| | | return responseContent.Error("åæ¥å¤±è´¥: " + ex.Message); |
| | | if (InventoryInfos.Where(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num).Any()) |
| | | return WebResponseContent.Instance.Error($"ç©æç¼å·ã{item.goods_no}ãç©ææ¹æ¬¡ã{item.batch_num}ãå·²åå¨åºå"); |
| | | #region æ·»å çç¹å详æ
|
| | | Dt_DeliveryOrderDetail dt_DeliveryOrde = new Dt_DeliveryOrderDetail() |
| | | { |
| | | DeliveryOrderId = id, |
| | | Reservoirarea = warehouse_no, |
| | | Status = 2, |
| | | Order_qty = 0, |
| | | Order_Outqty = item.order_Outqty, |
| | | Goods_no = item.goods_no, |
| | | OotDetailStatus = "æ°å»º", |
| | | Batch_num = item.batch_num, |
| | | Creater = App.User.UserName, |
| | | CreateDate = DateTime.Now, |
| | | }; |
| | | deliveryOrderDetails.Add(dt_DeliveryOrde); |
| | | #endregion |
| | | |
| | | #region æ·»å åºåãæ¹æ¬¡ä¿¡æ¯ãçç¹ä»»å¡ |
| | | var MaterielInfo = MaterielInfos.First(x => x.MaterielCode == item.goods_no); |
| | | Dt_InventoryInfo inventoryInfo = new Dt_InventoryInfo() |
| | | { |
| | | BatchNo = item.batch_num, |
| | | MaterielCode = MaterielInfo.MaterielCode, |
| | | AvailableQuantity = 0, |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName, |
| | | InDate = DateTime.Now, |
| | | LocationCode = item.locationCode, |
| | | MaterielName = MaterielInfo.MaterielName, |
| | | MaterielSpec = MaterielInfo.MaterielSpec, |
| | | OutboundQuantity = 0, |
| | | StockQuantity = 0, |
| | | StockStatus = StockStatusEmun.çç¹éå®.ObjToInt(), |
| | | SupplyQuantity = 0, |
| | | WarehouseCode = warehouse_no, |
| | | ValidityPeriod = item.exp_date |
| | | }; |
| | | inventoryInfos.Add(inventoryInfo); |
| | | Dt_Inventory_Batch? inventory_Batch = Batchs.FirstOrDefault(x => x.BatchNo == item.batch_num && x.MaterielCode == item.goods_no); |
| | | if (inventory_Batch == null) |
| | | { |
| | | inventory_Batch = new Dt_Inventory_Batch() |
| | | { |
| | | BatchNo = inventoryInfo.BatchNo, |
| | | CreateDate = inventoryInfo.CreateDate, |
| | | Creater = inventoryInfo.Creater, |
| | | MaterielCode = inventoryInfo.MaterielCode, |
| | | ERPStockQuantity = 0, |
| | | MaterielName = inventoryInfo.MaterielName, |
| | | MaterielSpec = inventoryInfo.MaterielSpec, |
| | | OutboundQuantity = inventoryInfo.OutboundQuantity, |
| | | ProductionDate = inventoryInfo.ProductionDate, |
| | | Status = false, |
| | | StockQuantity = inventoryInfo.StockQuantity, |
| | | AvailableQuantity = inventoryInfo.AvailableQuantity, |
| | | ValidityPeriod = inventoryInfo.ValidityPeriod.ObjToDate(), |
| | | SupplyQuantity = inventoryInfo.SupplyQuantity, |
| | | }; |
| | | inventory_Batches.Add(inventory_Batch); |
| | | } |
| | | Dt_SupplyTask supplyTask = new Dt_SupplyTask() |
| | | { |
| | | WarehouseCode = warehouse_no, |
| | | TaskStatus = SupplyStatusEnum.NewCheck.ObjToInt(), |
| | | BatchNo = inventoryInfo.BatchNo, |
| | | MaterielName = inventoryInfo.MaterielName, |
| | | MaterielCode = inventoryInfo.MaterielCode, |
| | | MaterielSpec = inventoryInfo.MaterielSpec, |
| | | TaskType = TaskTypeEnum.OutInventory.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName, |
| | | LocationCode = inventoryInfo.LocationCode, |
| | | OrderNo = out_no, |
| | | StockQuantity = inventoryInfo.StockQuantity, |
| | | SupplyQuantity = 0, |
| | | Remark = "çç¹" |
| | | }; |
| | | supplyTasks.Add(supplyTask); |
| | | #endregion |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | _deliveryOrderDetailServices.AddData(deliveryOrderDetails); |
| | | _inventoryInfoService.AddData(inventoryInfos); |
| | | if (inventory_Batches.Count > 0) _inventory_BatchServices.AddData(inventory_Batches); |
| | | _supplyTaskService.AddData(supplyTasks); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return WebResponseContent.Instance.OK("çç¹è¯¦æ
æ·»å æå,请éè¿ERP平账ï¼"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | SendErrorToUpstream(3, "", ex.Message, ""); |
| | | return responseContent.Error("åæ¥å¤±è´¥: " + ex.Message); |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #region å建åºåºå |
| | | /// <summary> |
| | | /// è¿æ»¤æ²¡æå¯¹ååè¿è¡ç»´æ¤çåºåºåè¿è¡è¿æ»¤ |
| | | /// å建åºåºå |
| | | /// </summary> |
| | | /// <param name="outorder"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent GetUpstreamOutOrder2() |
| | | public WebResponseContent CreateOutboundOrder(UpstramOutOrderInfo outorder) |
| | | { |
| | | var responseContent = new WebResponseContent(); |
| | | WebResponseContent webResponseContent = new WebResponseContent(); |
| | | try |
| | | { |
| | | var url = "http://121.37.118.63:80/GYZ2/95fck/outOrder"; |
| | | |
| | | var requestData = new |
| | | Dt_Tactics tactics = _tacticsService.Repository.QueryFirst(x => x.TacticeName == "åºåºçç¥"); |
| | | #region ç¹æ®åºæ¿åºåº |
| | | string WareCodeMJ = WarehouseEnum.麻精åº.ObjToInt().ToString("000"); |
| | | string WareCodeLD = WarehouseEnum.å·å»åº.ObjToInt().ToString("000"); |
| | | if (outorder.warehouse_no == WareCodeMJ || outorder.warehouse_no == WareCodeLD) |
| | | { |
| | | searchDate = "2022-10-10 20:45:16" |
| | | }; |
| | | |
| | | var result = HttpHelper.Post(url, requestData.ToJsonString()); |
| | | var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstramOutOrderInfo>>(result); |
| | | |
| | | if (response.resultCode != "0") |
| | | { |
| | | SendErrorToUpstream(3, "", response.resultMsg ?? "䏿¸¸æ¥å£è¿å失败", ""); |
| | | return responseContent.Error(response.resultMsg ?? "䏿¸¸æ¥å£è¿å失败"); |
| | | } |
| | | |
| | | if (response.data == null || !response.data.Any()) |
| | | { |
| | | return responseContent.OK("æ æ°åºåºåæ°æ®"); |
| | | } |
| | | |
| | | // å·²åå¨åºåºåå· |
| | | var existingOutOrderNos = BaseDal.Db.Queryable<Dt_DeliveryOrder>() |
| | | .Select(x => x.Out_no) |
| | | .ToList(); |
| | | |
| | | // æ°åºåºå |
| | | var newOutOrders = response.data |
| | | .Where(outorder => !existingOutOrderNos.Contains(outorder.order_no)) |
| | | .ToList(); |
| | | |
| | | if (!newOutOrders.Any()) |
| | | { |
| | | return responseContent.OK("ææåºåºåå·²åå¨ï¼æ éæ°å¢"); |
| | | } |
| | | |
| | | Db.Ado.BeginTran(); |
| | | try |
| | | { |
| | | List<Dt_DeliveryOrder> _DeliveryOrders = new List<Dt_DeliveryOrder>(); |
| | | List<string> orderNos = new(); |
| | | |
| | | foreach (var outorder in newOutOrders) |
| | | #region æ·»å åºåºå |
| | | var entityOrder = new Dt_DeliveryOrder |
| | | { |
| | | |
| | | bool skipOrder = false; // æ è®°æ¯å¦è·³è¿è¯¥å
¥åºå |
| | | var entityOrder = new Dt_DeliveryOrder |
| | | Out_no = outorder.order_no, |
| | | Out_type = outorder.order_type, |
| | | Client_no = outorder.client_no, |
| | | Client_name = outorder.client_name, |
| | | Account_time = outorder.account_time, |
| | | Warehouse_no = outorder.warehouse_no, |
| | | OutStatus = "æ°å»º", |
| | | Details = outorder.details.Select(d => new Dt_DeliveryOrderDetail |
| | | { |
| | | Out_no = outorder.order_no, |
| | | Out_type = outorder.order_type, |
| | | Client_no = outorder.client_no, |
| | | Client_name = outorder.client_name, |
| | | Account_time = outorder.account_time, |
| | | Warehouse_no = outorder.warehouse_no, |
| | | OutStatus = "æªå®æ", |
| | | Details = new List<Dt_DeliveryOrderDetail>() |
| | | }; |
| | | |
| | | // éååºåºæç» |
| | | foreach (var item in outorder.details) |
| | | Reservoirarea = outorder.warehouse_no, |
| | | Goods_no = d.goods_no, |
| | | Order_qty = Math.Abs(d.order_qty), // åºåºæ°éè½¬ä¸ºæ£æ° |
| | | Batch_num = d.batch_num, |
| | | Exp_date = d.exp_date, |
| | | OotDetailStatus = "æ°å»º", |
| | | Status = 2, // padå¹³åºï¼æ é忥 |
| | | }).ToList() |
| | | }; |
| | | #endregion |
| | | #region å¤çåºåãåºåæ¹æ¬¡ãæ·»å åºåºä»»å¡ |
| | | List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>(); |
| | | List<Dt_Inventory_Batch> batchesUp = new List<Dt_Inventory_Batch>(); |
| | | List<Dt_InventoryInfo> inventoryInfosUp = new List<Dt_InventoryInfo>(); |
| | | var inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => entityOrder.Details.Select(e => e.Goods_no).Contains(x.MaterielCode)); |
| | | var InventoryInfos = _inventoryInfoService.Repository.QueryData(x => entityOrder.Details.Select(e => e.Goods_no).Contains(x.MaterielCode) && x.StockStatus == StockStatusEmun.å
¥åºå®æ.ObjToInt() && x.AvailableQuantity > 0 && x.WarehouseCode == outorder.warehouse_no); |
| | | foreach (var item in entityOrder.Details) |
| | | { |
| | | Dt_Inventory_Batch? inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == item.Goods_no && x.BatchNo == item.Batch_num).FirstOrDefault(); |
| | | if (inventory_Batch == null) throw new Exception($"æªæ¾å°åºåºåå·ã{entityOrder.Out_no}ãä¸ç©æç¼å·ã{item.Goods_no}ãç©ææ¹æ¬¡ã{item.Batch_num}ãçåºåæ¹æ¬¡ä¿¡æ¯"); |
| | | if (inventory_Batch.AvailableQuantity < item.Order_qty) throw new Exception($"åºåºåå·ã{entityOrder.Out_no}ãä¸ç©æç¼å·ã{item.Goods_no}ãç©ææ¹æ¬¡ã{item.Batch_num}ãçåºåæ¹æ¬¡ä¿¡æ¯å¯ç¨æ°éä¸è¶³"); |
| | | inventory_Batch.AvailableQuantity -= item.Order_qty; |
| | | inventory_Batch.OutboundQuantity += item.Order_qty; |
| | | List<Dt_InventoryInfo> dt_InventoryInfos = InventoryInfos.Where(x => x.MaterielCode == item.Goods_no && x.BatchNo == item.Batch_num).ToList(); |
| | | if (dt_InventoryInfos.Count < 1) throw new Exception($"åºåºåå·ã{entityOrder.Out_no}ãä¸ç©æç¼å·ã{item.Goods_no}ãç©ææ¹æ¬¡ã{item.Batch_num}ãçå¯ç¨åºåä¸è¶³"); |
| | | #region æåºåºçç¥æ¥æ¾åºå |
| | | if (tactics.SelectTactice == TacticsEnum.ComeOutonFirstTime.ObjToInt()) |
| | | dt_InventoryInfos = dt_InventoryInfos.OrderBy(x => x.ValidityPeriod).ToList(); |
| | | else |
| | | dt_InventoryInfos = dt_InventoryInfos.OrderBy(x => x.InDate).ToList(); |
| | | #endregion |
| | | var Order_qty = item.Order_qty;//åºåºåæ°é |
| | | foreach (var InventoryInfo in dt_InventoryInfos) |
| | | { |
| | | // 1ï¸â£ è½¬ä¸ºæ£æ°ï¼ä¸æ¸¸å¯è½ä¼ è´æ°ï¼ |
| | | item.order_qty = Math.Abs(item.order_qty); |
| | | decimal orderQty = (decimal)item.order_qty; |
| | | |
| | | // 2ï¸â£ æ¥ç©æåºç¡ä¿¡æ¯ï¼è·åç®±è§ï¼ |
| | | var medication = BaseDal.Db.Queryable<Dt_MedicineGoods>() |
| | | .Where(m => m.Goods_no == item.goods_no) |
| | | .First(); |
| | | |
| | | |
| | | // è¥ç©æä¸å卿 MaterielSourceType 为空ï¼åè·³è¿æ´ä¸ªåºåºå |
| | | if (medication == null || !Enum.IsDefined(typeof(MaterielSourceTypeEnum), medication.MaterielSourceType)) |
| | | if (Order_qty <= 0) break; |
| | | if (InventoryInfo.AvailableQuantity <= Order_qty) |
| | | { |
| | | skipOrder = true; |
| | | break; |
| | | Order_qty -= InventoryInfo.AvailableQuantity; |
| | | InventoryInfo.OutboundQuantity += InventoryInfo.AvailableQuantity; |
| | | Dt_SupplyTask supplyTask = new Dt_SupplyTask() |
| | | { |
| | | WarehouseCode = InventoryInfo.WarehouseCode, |
| | | BatchNo = InventoryInfo.BatchNo, |
| | | MaterielName = InventoryInfo.MaterielName, |
| | | MaterielCode = InventoryInfo.MaterielCode, |
| | | MaterielSpec = InventoryInfo.MaterielSpec, |
| | | TaskStatus = SupplyStatusEnum.NewOut.ObjToInt(), |
| | | TaskType = outorder.order_type == "1" ? TaskTypeEnum.Out.ObjToInt() : TaskTypeEnum.InReturn.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName ?? "System", |
| | | LocationCode = InventoryInfo.LocationCode, |
| | | OrderNo = entityOrder.Out_no, |
| | | StockQuantity = InventoryInfo.AvailableQuantity, |
| | | SupplyQuantity = 0, |
| | | Remark = "åºåº" |
| | | }; |
| | | supplyTasks.Add(supplyTask); |
| | | InventoryInfo.AvailableQuantity = 0; |
| | | } |
| | | |
| | | if (medication == null) |
| | | else |
| | | { |
| | | SendErrorToUpstream(3, "", $"æ¾ä¸å°ç©æä¿¡æ¯ï¼{item.goods_no}", ""); |
| | | continue; |
| | | InventoryInfo.AvailableQuantity -= Order_qty; |
| | | InventoryInfo.OutboundQuantity += Order_qty; |
| | | Dt_SupplyTask supplyTask = new Dt_SupplyTask() |
| | | { |
| | | WarehouseCode = InventoryInfo.WarehouseCode, |
| | | BatchNo = InventoryInfo.BatchNo, |
| | | MaterielName = InventoryInfo.MaterielName, |
| | | MaterielCode = InventoryInfo.MaterielCode, |
| | | MaterielSpec = InventoryInfo.MaterielSpec, |
| | | TaskStatus = SupplyStatusEnum.NewOut.ObjToInt(), |
| | | TaskType = outorder.order_type == "1" ? TaskTypeEnum.Out.ObjToInt() : TaskTypeEnum.InReturn.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName ?? "System", |
| | | LocationCode = InventoryInfo.LocationCode, |
| | | OrderNo = entityOrder.Out_no, |
| | | StockQuantity = Order_qty, |
| | | SupplyQuantity = 0, |
| | | Remark = "åºåº" |
| | | }; |
| | | supplyTasks.Add(supplyTask); |
| | | Order_qty = 0; |
| | | } |
| | | |
| | | decimal boxQty = medication.BoxQty <= 0 ? 1 : medication.BoxQty; |
| | | |
| | | // 3ï¸â£ è®¡ç®æ´ä»¶ä¸æ£ä»¶æ°é |
| | | var fullBoxes = (int)(orderQty / boxQty); // æ´ä»¶ç®±æ° |
| | | var partialQty = orderQty % boxQty; // æ£ä»¶æ°é |
| | | |
| | | // è¥ä¸æ¸¸ç»äºæ¹æ¬¡å·ï¼åä¼å
å¹é
|
| | | string requestedBatch = string.IsNullOrEmpty(item.batch_num) ? null : item.batch_num; |
| | | |
| | | // helper: æ¥è¯¢åºå彿°ï¼æå
¥åºæ¶é´ååºï¼ |
| | | // å®ä¹ä¸ä¸ªå§æåéï¼è¾å
¥intåæ°ï¼è¿åList<Dt_InventoryInfo> |
| | | Func<int, List<Dt_InventoryInfo>> queryInventoryByStockStatus = (stockStatus) => |
| | | { |
| | | // 1. å建åºç¡æ¥è¯¢ |
| | | var q = BaseDal.Db.Queryable<Dt_InventoryInfo>() |
| | | .Where(i => i.MaterielCode == item.goods_no && // ç©æç¼å·å¹é
|
| | | (i.StockQuantity - i.OutboundQuantity) > 0 && // å¯ç¨åºå>0 |
| | | i.StockStatus == stockStatus); // åºåç¶æå¹é
|
| | | |
| | | // 2. æ¡ä»¶çéï¼å¦æææ¹æ¬¡å·è¦æ±ï¼ |
| | | if (!string.IsNullOrEmpty(requestedBatch)) |
| | | q = q.Where(i => i.BatchNo == requestedBatch); |
| | | |
| | | // 3. æ§è¡æ¥è¯¢å¹¶è¿åç»æ |
| | | return q.OrderBy(i => i.InDate).ToList(); // æå
¥åºæ¶é´æåº |
| | | }; |
| | | // 4ï¸â£åé
æ£ä»¶ï¼ä¼å
ç«åº Status=0ï¼ |
| | | decimal remainingPartial = partialQty; |
| | | if (remainingPartial > 0) |
| | | { |
| | | var invList_ly = queryInventoryByStockStatus(0); |
| | | foreach (var inv in invList_ly) |
| | | { |
| | | if (remainingPartial <= 0) break; |
| | | |
| | | decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity); |
| | | if (available <= 0) continue; |
| | | |
| | | decimal use = Math.Min(available, remainingPartial); |
| | | |
| | | var detail = new Dt_DeliveryOrderDetail |
| | | { |
| | | Goods_no = item.goods_no, |
| | | Order_qty = use, |
| | | Batch_num = inv.BatchNo, |
| | | Exp_date = inv.ValidityPeriod, |
| | | OotDetailStatus = "æ°å»º", |
| | | Status = 0, //ç«åº |
| | | Reservoirarea = inv.LocationCode |
| | | }; |
| | | entityOrder.Details.Add(detail); |
| | | |
| | | inv.OutboundQuantity += (float)use; |
| | | BaseDal.Db.Updateable(inv).ExecuteCommand(); |
| | | |
| | | remainingPartial -= use; |
| | | } |
| | | |
| | | // ç«åºä¸å¤ â å¹³åºè¡¥ (Status=2) |
| | | if (remainingPartial > 0) |
| | | { |
| | | var invList_pk = queryInventoryByStockStatus(2); |
| | | foreach (var inv in invList_pk) |
| | | { |
| | | if (remainingPartial <= 0) break; |
| | | |
| | | decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity); |
| | | if (available <= 0) continue; |
| | | |
| | | decimal use = Math.Min(available, remainingPartial); |
| | | |
| | | var detail = new Dt_DeliveryOrderDetail |
| | | { |
| | | Goods_no = item.goods_no, |
| | | Order_qty = use, |
| | | Batch_num = inv.BatchNo, |
| | | Exp_date = inv.ValidityPeriod, |
| | | OotDetailStatus = "æ°å»º", |
| | | Status = 2, //å¹³åº |
| | | Reservoirarea = inv.LocationCode |
| | | }; |
| | | entityOrder.Details.Add(detail); |
| | | |
| | | inv.OutboundQuantity += (float)use; |
| | | BaseDal.Db.Updateable(inv).ExecuteCommand(); |
| | | |
| | | remainingPartial -= use; |
| | | } |
| | | } |
| | | |
| | | if (remainingPartial > 0) |
| | | { |
| | | SendErrorToUpstream(3, "", $"åºåºå[{outorder.order_no}]ç©æ[{item.goods_no}]æ£ä»¶åºåä¸è¶³ï¼æªåé
ï¼{remainingPartial}", ""); |
| | | } |
| | | } |
| | | |
| | | //åé
æ´ä»¶ï¼ä¼å
å¹³åº Status=2ï¼ |
| | | int remainingFullBoxes = fullBoxes; |
| | | if (remainingFullBoxes > 0) |
| | | { |
| | | var invList_pk = queryInventoryByStockStatus(2); |
| | | foreach (var inv in invList_pk) |
| | | { |
| | | if (remainingFullBoxes <= 0) break; |
| | | |
| | | decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity); |
| | | if (available < boxQty) continue; |
| | | |
| | | int canProvideBoxes = (int)(available / boxQty); |
| | | if (canProvideBoxes <= 0) continue; |
| | | |
| | | int useBoxes = Math.Min(canProvideBoxes, remainingFullBoxes); |
| | | decimal useQty = useBoxes * boxQty; |
| | | |
| | | var detail = new Dt_DeliveryOrderDetail |
| | | { |
| | | Goods_no = item.goods_no, |
| | | Order_qty = useQty, |
| | | Batch_num = inv.BatchNo, |
| | | Exp_date = inv.ValidityPeriod, |
| | | OotDetailStatus = "æ°å»º", |
| | | Status = 2, //å¹³åº |
| | | Reservoirarea = inv.LocationCode |
| | | }; |
| | | entityOrder.Details.Add(detail); |
| | | |
| | | inv.OutboundQuantity += (float)useQty; |
| | | BaseDal.Db.Updateable(inv).ExecuteCommand(); |
| | | |
| | | remainingFullBoxes -= useBoxes; |
| | | } |
| | | |
| | | // å¹³åºä¸å¤ â ç«åºè¡¥ (Status=1) |
| | | if (remainingFullBoxes > 0) |
| | | { |
| | | var invList_ly = queryInventoryByStockStatus(1); |
| | | foreach (var inv in invList_ly) |
| | | { |
| | | if (remainingFullBoxes <= 0) break; |
| | | |
| | | decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity); |
| | | if (available < boxQty) continue; |
| | | |
| | | int canProvideBoxes = (int)(available / boxQty); |
| | | if (canProvideBoxes <= 0) continue; |
| | | |
| | | int useBoxes = Math.Min(canProvideBoxes, remainingFullBoxes); |
| | | decimal useQty = useBoxes * boxQty; |
| | | |
| | | var detail = new Dt_DeliveryOrderDetail |
| | | { |
| | | Goods_no = item.goods_no, |
| | | Order_qty = useQty, |
| | | Batch_num = inv.BatchNo, |
| | | Exp_date = inv.ValidityPeriod, |
| | | OotDetailStatus = "æ°å»º", |
| | | Status = 0, //ç«åºï¼è¡¥æ´ç®±ï¼ |
| | | Reservoirarea = inv.LocationCode |
| | | }; |
| | | entityOrder.Details.Add(detail); |
| | | |
| | | inv.OutboundQuantity += (float)useQty; |
| | | BaseDal.Db.Updateable(inv).ExecuteCommand(); |
| | | |
| | | remainingFullBoxes -= useBoxes; |
| | | } |
| | | } |
| | | // âå¦æè·³è¿è¯¥åï¼åç´æ¥continueï¼ä¸ä¿å |
| | | if (skipOrder) |
| | | { |
| | | Console.WriteLine($"è·³è¿å
¥åºå {outorder.order_no}ï¼å 为å卿ªå®ä¹ç©æå±æ§çååã"); |
| | | continue; |
| | | } |
| | | |
| | | if (remainingFullBoxes > 0) |
| | | { |
| | | decimal unfilledQty = remainingFullBoxes * boxQty; |
| | | SendErrorToUpstream(3, "", $"åºåºå[{outorder.order_no}]ç©æ[{item.goods_no}]æ´ç®±åºåä¸è¶³ï¼æªåé
æ°éï¼{unfilledQty}", ""); |
| | | } |
| | | |
| | | } |
| | | inventoryInfosUp.Add(InventoryInfo); |
| | | } |
| | | |
| | | _DeliveryOrders.Add(entityOrder); |
| | | batchesUp.Add(inventory_Batch); |
| | | } |
| | | |
| | | // æå
¥ä¸»è¡¨+æç» |
| | | BaseDal.Db.InsertNav(_DeliveryOrders) |
| | | .Include(x => x.Details) |
| | | .ExecuteCommand(); |
| | | |
| | | Db.Ado.CommitTran(); |
| | | return responseContent.OK("忥åºåºåæå"); |
| | | _unitOfWorkManage.BeginTran(); |
| | | _supplyTaskService.AddData(supplyTasks); |
| | | _inventory_BatchServices.UpdateData(batchesUp); |
| | | _inventoryInfoService.UpdateData(inventoryInfosUp); |
| | | BaseDal.Db.InsertNav(entityOrder).Include(x => x.Details).ExecuteCommand(); |
| | | _unitOfWorkManage.CommitTran(); |
| | | #endregion |
| | | } |
| | | catch (Exception ex) |
| | | #endregion |
| | | else |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | SendErrorToUpstream(3, "", ex.Message, ""); |
| | | return responseContent.Error("åæ¥å¤±è´¥: " + ex.Message); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | SendErrorToUpstream(3, "", ex.Message, ""); |
| | | return responseContent.Error("åæ¥å¤±è´¥: " + ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åºåºåæ¨éç» WCS |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent EdiOut() |
| | | { |
| | | var responseContent = new WebResponseContent(); |
| | | try |
| | | { |
| | | // 1. æ¥è¯¢ç¬¦åæ¡ä»¶ç订åï¼è¡¨å¤´=æ°å»º && å
嫿ææç»ï¼ |
| | | var outOrders = BaseDal.Db.CopyNew().Queryable<Dt_DeliveryOrder>() |
| | | .Where(o => o.OutStatus == "æ°å»º") |
| | | .Includes(o => o.Details, d => d.MedicineGoods) |
| | | .ToList(); |
| | | |
| | | // 2. åè¿æ»¤æä¸ç¬¦åæ¡ä»¶çæç»ï¼åªä¿ç Status=0 ï¼ |
| | | foreach (var order in outOrders) |
| | | { |
| | | order.Details = order.Details.Where(d => d.Status == 0).ToList(); |
| | | } |
| | | |
| | | if (outOrders == null || !outOrders.Any()) |
| | | { |
| | | Console.WriteLine("没æç¬¦åæ¡ä»¶ç订åéè¦æ¨é"); |
| | | return responseContent.Error("没æç¬¦åæ¡ä»¶ç订åéè¦æ¨é"); |
| | | } |
| | | |
| | | foreach (var order in outOrders) |
| | | { |
| | | try |
| | | string WareCodeDJ = WarehouseEnum.大件åº.ObjToInt().ToString("000"); |
| | | string WareCodeLK = WarehouseEnum.ç«åº.ObjToInt().ToString("000"); |
| | | #region å建大件åºãç«åºåºåºå¤´è¡¨ |
| | | var entityOrder = new Dt_DeliveryOrder |
| | | { |
| | | string materialCode = "YY";//é»è®¤å¼ |
| | | //è·åå½å订åç第ä¸ä¸ªæç»é¡¹ |
| | | var firstDetail = order.Details.FirstOrDefault(); |
| | | if (firstDetail?.MedicineGoods != null && !string.IsNullOrEmpty(firstDetail.MedicineGoods.MaterialCode)) |
| | | Out_no = outorder.order_no, |
| | | Out_type = outorder.order_type, |
| | | OutStatus = "æ°å»º", |
| | | Client_name = outorder.client_name, |
| | | Account_time = outorder.account_time, |
| | | Client_no = outorder.client_no, |
| | | Warehouse_no = WareCodeDJ, |
| | | Details = new List<Dt_DeliveryOrderDetail>() |
| | | }; |
| | | var entityOrderLK = new Dt_DeliveryOrder |
| | | { |
| | | Out_no = outorder.order_no, |
| | | Out_type = outorder.order_type, |
| | | OutStatus = "æ°å»º", |
| | | Client_name = outorder.client_name, |
| | | Account_time = outorder.account_time, |
| | | Client_no = outorder.client_no, |
| | | Warehouse_no = WareCodeLK, |
| | | Details = new List<Dt_DeliveryOrderDetail>() |
| | | }; |
| | | #endregion |
| | | #region æ¥æ¾åºå |
| | | List<Dt_Inventory_Batch> batchesUp = new List<Dt_Inventory_Batch>(); |
| | | List<Dt_InventoryInfo> inventoryInfosUp = new List<Dt_InventoryInfo>(); |
| | | List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>(); |
| | | List<Dt_MaterielInfo> materielInfos = _materielInfoService.Repository.QueryData(x => outorder.details.Select(e => e.goods_no).Contains(x.MaterielCode)); |
| | | var inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => outorder.details.Select(e => e.goods_no).Contains(x.MaterielCode)); |
| | | var InventoryInfos = _inventoryInfoService.Repository.QueryData(x => outorder.details.Select(e => e.goods_no).Contains(x.MaterielCode) && x.StockStatus == StockStatusEmun.å
¥åºå®æ.ObjToInt() && x.AvailableQuantity > 0 && (x.WarehouseCode == WareCodeDJ || x.WarehouseCode == WareCodeLK)); |
| | | foreach (var detail in outorder.details) |
| | | { |
| | | #region æ¥è¯¢åºåæ¹æ¬¡ååºå |
| | | Dt_Inventory_Batch? inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == detail.goods_no && x.BatchNo == detail.batch_num).FirstOrDefault(); |
| | | if (inventory_Batch == null) throw new Exception($"æªæ¾å°åºåºåå·ã{outorder.order_no}ãä¸ç©æç¼å·ã{detail.goods_no}ãç©ææ¹æ¬¡ã{detail.batch_num}ãçåºåæ¹æ¬¡ä¿¡æ¯"); |
| | | if (inventory_Batch.AvailableQuantity < detail.order_qty) throw new Exception($"åºåºåå·ã{outorder.order_no}ãä¸ç©æç¼å·ã{detail.goods_no}ãç©ææ¹æ¬¡ã{detail.batch_num}ãçåºåæ¹æ¬¡ä¿¡æ¯å¯ç¨æ°éä¸è¶³"); |
| | | inventory_Batch.AvailableQuantity -= detail.order_qty; |
| | | inventory_Batch.OutboundQuantity += detail.order_qty; |
| | | List<Dt_InventoryInfo> dt_InventoryInfos = InventoryInfos.Where(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo).ToList(); |
| | | if (dt_InventoryInfos.Count < 1) throw new Exception($"åºåºåå·ã{outorder.order_no}ãä¸ç©æç¼å·ã{detail.goods_no}ãç©ææ¹æ¬¡ã{detail.batch_num}ãçå¯ç¨åºåä¸è¶³"); |
| | | #endregion |
| | | #region æåºåºçç¥æ¥æ¾åºå |
| | | if (tactics.SelectTactice == TacticsEnum.ComeOutonFirstTime.ObjToInt()) |
| | | dt_InventoryInfos = dt_InventoryInfos.OrderBy(x => x.ValidityPeriod).ToList(); |
| | | else |
| | | dt_InventoryInfos = dt_InventoryInfos.OrderBy(x => x.InDate).ToList(); |
| | | #endregion |
| | | var Order_qty = Math.Abs(detail.order_qty);//åºåºåæ°é |
| | | #region æ ¹æ®ç©æç¼ç æ¥è¯¢ç©æä¿¡æ¯ |
| | | Dt_MaterielInfo? materielInfo = materielInfos.Where(x => x.MaterielCode == detail.goods_no).FirstOrDefault(); |
| | | if (materielInfo == null) throw new Exception($"æªæ¾å°è¯åç¼ç ã{detail.goods_no}ãçä¿¡æ¯"); |
| | | if (!Enum.IsDefined(typeof(MaterielSourceTypeEnum), materielInfo.MaterielSourceType)) |
| | | throw new Exception($"请设置è¯åç¼å·ã{detail.goods_no}ãç屿§åç±»"); |
| | | #endregion |
| | | #region 大件 |
| | | if (materielInfo.MaterielSourceType == MaterielSourceTypeEnum.PurchasePart)//å¦æç©ææ¯å¤§ä»¶ |
| | | { |
| | | //妿æ¡ä»¶æ»¡è¶³ï¼å°ç©æä»£ç 设置为第ä¸ä¸ªæç»é¡¹å¯¹åºçè¯åç©æä»£ç |
| | | materialCode = firstDetail.MedicineGoods.MaterialCode; |
| | | } |
| | | // 3. ç»è£
DTO |
| | | var ediDto = new TowcsDto.ToediOutInfo |
| | | { |
| | | customerCode = "905", |
| | | materialCode = materialCode, |
| | | externalOrderNo = order.Out_no, |
| | | outOrderType = order.Out_type == "1" ? "10" : order.Out_type == "2" ? "20" : "30", |
| | | priority = 1, |
| | | Is_cancel = 0, |
| | | details = order.Details.Select(d => new TowcsDto.ToeOutdiInDetail |
| | | #region æ·»å åºåºè¯¦æ
|
| | | Dt_DeliveryOrderDetail orderDetail = new Dt_DeliveryOrderDetail() |
| | | { |
| | | batchNo = d.Batch_num, |
| | | productCode = d.Goods_no, |
| | | productName = d.MedicineGoods?.Goods_spm, |
| | | productSpecifications = d.MedicineGoods?.Model, |
| | | quantity = (int)d.Order_qty, |
| | | //stocktakingDetails = order.Out_type == "3" |
| | | // ? new List<ToOutediInStock> |
| | | // { |
| | | // new ToOutediInStock { palletCode = "FC00001", quantity = d.Order_qty.ToString() } |
| | | // } |
| | | // : null |
| | | }).ToList() |
| | | }; |
| | | Reservoirarea = entityOrder.Warehouse_no, |
| | | Goods_no = detail.goods_no, |
| | | Order_qty = detail.order_qty, |
| | | Batch_num = detail.batch_num, |
| | | Exp_date = detail.exp_date, |
| | | OotDetailStatus = "æ°å»º", |
| | | Order_Outqty = 0, |
| | | Status = 2 |
| | | }; |
| | | entityOrder.Details.Add(orderDetail); |
| | | #endregion |
| | | |
| | | // 4. è°ç¨æ¥å£ |
| | | var url = "http://172.16.1.2:9357/file-admin/api/out/ediOut"; |
| | | var result = HttpHelper.Post(url, ediDto.ToJsonString()); |
| | | var resp = JsonConvert.DeserializeObject<TowcsDto.TowcsResponse<object>>(result); |
| | | |
| | | if (resp != null && resp.code == "0") |
| | | { |
| | | // æ´æ°è¡¨å¤´ç¶æ |
| | | BaseDal.Db.Updateable<Dt_DeliveryOrder>() |
| | | .SetColumns(o => new Dt_DeliveryOrder { OutStatus = "å¼å§" }) |
| | | .Where(o => o.Id == order.Id) |
| | | .ExecuteCommand(); |
| | | |
| | | // æ´æ°æç»ç¶æ |
| | | BaseDal.Db.Updateable<Dt_DeliveryOrderDetail>() |
| | | .SetColumns(d => new Dt_DeliveryOrderDetail { Status = 1, OotDetailStatus = "已宿" }) |
| | | .Where(d => d.DeliveryOrderId == order.Id && d.Status == 0) |
| | | .ExecuteCommand(); |
| | | |
| | | Console.WriteLine($"订å {order.Out_no} æ¨éæå"); |
| | | #region 计ç®åºåãæ·»å åºåºä»»å¡ |
| | | foreach (var InventoryInfo in dt_InventoryInfos) |
| | | { |
| | | if (Order_qty <= 0) break; |
| | | if (InventoryInfo.AvailableQuantity < Order_qty) |
| | | { |
| | | Order_qty -= InventoryInfo.AvailableQuantity; |
| | | InventoryInfo.OutboundQuantity += InventoryInfo.AvailableQuantity; |
| | | Dt_SupplyTask supplyTask = new Dt_SupplyTask() |
| | | { |
| | | WarehouseCode = InventoryInfo.WarehouseCode, |
| | | BatchNo = InventoryInfo.BatchNo, |
| | | MaterielName = InventoryInfo.MaterielName, |
| | | MaterielCode = InventoryInfo.MaterielCode, |
| | | MaterielSpec = InventoryInfo.MaterielSpec, |
| | | TaskStatus = SupplyStatusEnum.NewOut.ObjToInt(), |
| | | TaskType = outorder.order_type == "1" ? TaskTypeEnum.Out.ObjToInt() : TaskTypeEnum.InReturn.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName ?? "System", |
| | | LocationCode = InventoryInfo.LocationCode, |
| | | OrderNo = entityOrder.Out_no, |
| | | StockQuantity = InventoryInfo.AvailableQuantity, |
| | | SupplyQuantity = 0, |
| | | Remark = "åºåº" |
| | | }; |
| | | supplyTasks.Add(supplyTask); |
| | | InventoryInfo.AvailableQuantity = 0; |
| | | } |
| | | else |
| | | { |
| | | InventoryInfo.AvailableQuantity -= Order_qty; |
| | | InventoryInfo.OutboundQuantity += Order_qty; |
| | | Dt_SupplyTask supplyTask = new Dt_SupplyTask() |
| | | { |
| | | WarehouseCode = InventoryInfo.WarehouseCode, |
| | | BatchNo = InventoryInfo.BatchNo, |
| | | MaterielName = InventoryInfo.MaterielName, |
| | | MaterielCode = InventoryInfo.MaterielCode, |
| | | MaterielSpec = InventoryInfo.MaterielSpec, |
| | | TaskStatus = SupplyStatusEnum.NewOut.ObjToInt(), |
| | | TaskType = outorder.order_type == "1" ? TaskTypeEnum.Out.ObjToInt() : TaskTypeEnum.InReturn.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName ?? "System", |
| | | LocationCode = InventoryInfo.LocationCode, |
| | | OrderNo = entityOrder.Out_no, |
| | | StockQuantity = Order_qty, |
| | | SupplyQuantity = 0, |
| | | Remark = "åºåº" |
| | | }; |
| | | supplyTasks.Add(supplyTask); |
| | | Order_qty = 0; |
| | | } |
| | | } |
| | | #endregion |
| | | inventoryInfosUp.AddRange(dt_InventoryInfos); |
| | | batchesUp.Add(inventory_Batch); |
| | | //_inventory_BatchServices.Repository.UpdateData(inventory_Batch); |
| | | //_inventoryInfoService.Repository.UpdateData(dt_InventoryInfos); |
| | | //_supplyTaskService.AddData(supplyTasks); |
| | | } |
| | | #endregion |
| | | else |
| | | { |
| | | SendErrorToUpstream(3, order.Out_no, resp?.msg ?? "WCS æ¨é失败", ""); |
| | | Console.WriteLine($"订å {order.Out_no} æ¨é失败ï¼{resp?.msg}"); |
| | | if (materielInfo.BoxQty < 1) throw new Exception($"请设置è¯åç¼å·ã{detail.goods_no}ãçç®±è§æ°é"); |
| | | Dt_DeliveryOrderDetail orderDetail = null; |
| | | Dt_DeliveryOrderDetail orderDetailLK = null; |
| | | var ys = Order_qty % materielInfo.BoxQty; //ä¸è½æ´é¤ç®±è§çæ£ä»¶æ° |
| | | var xs = (int)(Order_qty / materielInfo.BoxQty);//ä¿çæ´æ° |
| | | #region æ£ä»¶ä¼å
åé
ç«åº |
| | | if (ys > 0) |
| | | { |
| | | orderDetailLK = new Dt_DeliveryOrderDetail() |
| | | { |
| | | Reservoirarea = entityOrderLK.Warehouse_no, |
| | | Goods_no = detail.goods_no, |
| | | Order_qty = ys, |
| | | Batch_num = detail.batch_num, |
| | | Exp_date = detail.exp_date, |
| | | OotDetailStatus = "æ°å»º", |
| | | Order_Outqty = 0, |
| | | Status = 0 |
| | | }; |
| | | } |
| | | #endregion |
| | | |
| | | #region æ´ä»¶ä¼å
åé
大件åº,计ååºå,æ·»å åºåºä»»å¡ |
| | | foreach (var item in dt_InventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ)) |
| | | { |
| | | if (xs <= 0 || item.AvailableQuantity <= 0) break; |
| | | decimal outqty = 0; |
| | | while (item.AvailableQuantity > 0 && xs > 0) |
| | | { |
| | | xs--; |
| | | if (orderDetail == null) |
| | | { |
| | | orderDetail = new Dt_DeliveryOrderDetail() |
| | | { |
| | | Reservoirarea = entityOrder.Warehouse_no, |
| | | Goods_no = detail.goods_no, |
| | | Order_qty = materielInfo.BoxQty, |
| | | Batch_num = detail.batch_num, |
| | | Exp_date = detail.exp_date, |
| | | OotDetailStatus = "æ°å»º", |
| | | Order_Outqty = 0, |
| | | Status = 2 |
| | | }; |
| | | item.AvailableQuantity -= materielInfo.BoxQty; |
| | | item.OutboundQuantity += materielInfo.BoxQty; |
| | | outqty += materielInfo.BoxQty; |
| | | } |
| | | else |
| | | { |
| | | orderDetail.Order_qty += materielInfo.BoxQty; |
| | | item.AvailableQuantity -= materielInfo.BoxQty; |
| | | item.OutboundQuantity += materielInfo.BoxQty; |
| | | outqty += materielInfo.BoxQty; |
| | | } |
| | | } |
| | | Dt_SupplyTask supplyTask = new Dt_SupplyTask() |
| | | { |
| | | WarehouseCode = item.WarehouseCode, |
| | | BatchNo = item.BatchNo, |
| | | MaterielName = item.MaterielName, |
| | | MaterielCode = item.MaterielCode, |
| | | MaterielSpec = item.MaterielSpec, |
| | | TaskStatus = SupplyStatusEnum.NewOut.ObjToInt(), |
| | | TaskType = outorder.order_type == "1" ? TaskTypeEnum.Out.ObjToInt() : TaskTypeEnum.InReturn.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName ?? "System", |
| | | LocationCode = item.LocationCode, |
| | | OrderNo = entityOrder.Out_no, |
| | | StockQuantity = outqty, |
| | | SupplyQuantity = 0, |
| | | Remark = "åºåº" |
| | | }; |
| | | supplyTasks.Add(supplyTask); |
| | | inventoryInfosUp.Add(item); |
| | | //_inventoryInfoService.Repository.UpdateData(item); |
| | | } |
| | | #endregion |
| | | |
| | | #region åé
å®å¤§ä»¶åºå¦æè¿æç®±æ°ï¼åéæ©åé
ç«åº |
| | | if (xs > 0) |
| | | { |
| | | if (orderDetailLK == null) |
| | | { |
| | | orderDetailLK = new Dt_DeliveryOrderDetail() |
| | | { |
| | | Reservoirarea = entityOrderLK.Warehouse_no, |
| | | Goods_no = detail.goods_no, |
| | | Order_qty = xs * materielInfo.BoxQty, |
| | | Batch_num = detail.batch_num, |
| | | Exp_date = detail.exp_date, |
| | | OotDetailStatus = "æ°å»º", |
| | | Order_Outqty = 0, |
| | | Status = 0 |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | orderDetailLK.Order_qty += xs * materielInfo.BoxQty; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region ç«åºåºåºåï¼ä¿®æ¹ç«åºåºåï¼æ·»å ç«åºåºåºä»»å¡ |
| | | if (orderDetailLK != null) |
| | | { |
| | | #region æ·»å åºåºä»»å¡ãä¿®æ¹åºåä¿¡æ¯ |
| | | Dt_InventoryInfo? inventoryInfo = dt_InventoryInfos.FirstOrDefault(x => x.WarehouseCode == WareCodeLK); |
| | | if (inventoryInfo == null) |
| | | throw new Exception($"æªæ¾å°ç©æç¼å·ã{detail.goods_no}ãç©ææ¹æ¬¡ã{detail.batch_num}ãå¨ç«åºä¸çåºåä¿¡æ¯ï¼æéæ°éã{orderDetailLK.Order_qty}ã请补货"); |
| | | inventoryInfo.AvailableQuantity -= orderDetailLK.Order_qty; |
| | | inventoryInfo.OutboundQuantity += orderDetailLK.Order_qty; |
| | | Dt_SupplyTask supplyTask = new Dt_SupplyTask() |
| | | { |
| | | WarehouseCode = inventoryInfo.WarehouseCode, |
| | | BatchNo = inventoryInfo.BatchNo, |
| | | MaterielName = inventoryInfo.MaterielName, |
| | | MaterielCode = inventoryInfo.MaterielCode, |
| | | MaterielSpec = inventoryInfo.MaterielSpec, |
| | | TaskStatus = SupplyStatusEnum.NewOut.ObjToInt(), |
| | | TaskType = outorder.order_type == "1" ? TaskTypeEnum.Out.ObjToInt() : TaskTypeEnum.InReturn.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName ?? "System", |
| | | LocationCode = inventoryInfo.LocationCode, |
| | | OrderNo = entityOrder.Out_no, |
| | | StockQuantity = orderDetailLK.Order_qty, |
| | | SupplyQuantity = 0, |
| | | Remark = "åºåº" |
| | | }; |
| | | supplyTasks.Add(supplyTask); |
| | | #endregion |
| | | //_inventoryInfoService.Repository.UpdateData(inventoryInfo); |
| | | inventoryInfosUp.Add(inventoryInfo); |
| | | entityOrderLK.Details.Add(orderDetailLK); |
| | | } |
| | | #endregion |
| | | if (orderDetail != null) entityOrder.Details.Add(orderDetail); |
| | | batchesUp.Add(inventory_Batch); |
| | | //_inventory_BatchServices.Repository.UpdateData(inventory_Batch); |
| | | //_supplyTaskService.AddData(supplyTasks); |
| | | } |
| | | //å é¤å
¨é¨ç¶ä¸ºå·²å®æçæç»å表头ï¼ç§»å
¥åå²è¡¨ |
| | | } |
| | | try |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | _supplyTaskService.AddData(supplyTasks); |
| | | _inventory_BatchServices.UpdateData(batchesUp); |
| | | _inventoryInfoService.UpdateData(inventoryInfosUp); |
| | | if (entityOrder.Details.Count > 0) |
| | | BaseDal.Db.InsertNav(entityOrder).Include(x => x.Details).ExecuteCommand(); |
| | | if (entityOrderLK.Details.Count > 0) |
| | | BaseDal.Db.InsertNav(entityOrderLK).Include(x => x.Details).ExecuteCommand(); |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | SendErrorToUpstream(3, order.Out_no, ex.Message, ""); |
| | | Console.WriteLine($"订å {order.Out_no} æ¨éå¼å¸¸ï¼{ex.Message}"); |
| | | _unitOfWorkManage.RollbackTran(); |
| | | } |
| | | #endregion |
| | | } |
| | | |
| | | return responseContent.OK("åºåºè®¢åæ¨é宿"); |
| | | webResponseContent.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine("EdiOut å¼å¸¸ï¼" + ex.Message); |
| | | return responseContent.Error("åºåºè®¢åæ¨é失败ï¼" + ex.Message); |
| | | _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, (outorder.order_type == "3" ? "å
¥åºéè´§" : "æ£å¸¸åºåº") + $"ï¼åå·ã{outorder.order_no}ã", ex.Message); |
| | | webResponseContent.Error(ex.Message); |
| | | } |
| | | return webResponseContent; |
| | | } |
| | | #endregion |
| | | |
| | | #region å建çäºåºåºå |
| | | public WebResponseContent CreateCheckOutOrder(UpstramOutOrderInfo order) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string WareCodeMJ = WarehouseEnum.麻精åº.ObjToInt().ToString("000"); |
| | | string WareCodeLD = WarehouseEnum.å·å»åº.ObjToInt().ToString("000"); |
| | | List<Dt_SupplyTask_Hty> supplyTask_Hties = new List<Dt_SupplyTask_Hty>(); |
| | | List<Dt_Inventory_Batch> batchesUp = new List<Dt_Inventory_Batch>(); |
| | | List<Dt_InventoryInfo> infosUp = new List<Dt_InventoryInfo>(); |
| | | var codes = order.details.Select(x => x.goods_no).ToList(); |
| | | #region ç¹æ®åºæ¿ |
| | | if (order.warehouse_no == WareCodeMJ || order.warehouse_no == WareCodeLD) |
| | | { |
| | | List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => codes.Contains(x.MaterielCode)); |
| | | List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoService.Repository.QueryData(x => codes.Contains(x.MaterielCode)); |
| | | #region åºåãåºåæ¹æ¬¡å¹³è´¦ |
| | | foreach (var item in order.details) |
| | | { |
| | | //æ¾åºåæ¹æ¬¡ä¿¡æ¯ |
| | | Dt_Inventory_Batch inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num).First(); |
| | | var Qty = Math.Abs(inventory_Batch.SupplyQuantity); |
| | | if (Qty != item.order_qty) throw new Exception($"çäºåºåºåã{order.order_no}ãç©æç¼å·ã{item.goods_no}ãç©ææ¹æ¬¡ã{item.batch_num}ãççäºæ°éæè¯¯"); |
| | | //æ¾ææåºå |
| | | List<Dt_InventoryInfo> inventoryInfos = _InventoryInfos.Where(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo).ToList(); |
| | | foreach (var inventoryInfo in inventoryInfos) |
| | | { |
| | | #region æ·»å çäºåºåºä»»å¡ |
| | | if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity) |
| | | { |
| | | Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty() |
| | | { |
| | | WarehouseCode = inventoryInfo.WarehouseCode, |
| | | OperateType = OperateTypeEnum.èªå¨å®æ.ToString(), |
| | | InsertTime = DateTime.Now, |
| | | TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt(), |
| | | BatchNo = inventoryInfo.BatchNo, |
| | | MaterielName = inventoryInfo.MaterielName, |
| | | MaterielCode = inventoryInfo.MaterielCode, |
| | | MaterielSpec = inventoryInfo.MaterielSpec, |
| | | TaskType = TaskTypeEnum.ChenckOut.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName, |
| | | LocationCode = inventoryInfo.LocationCode, |
| | | OrderNo = order.order_no, |
| | | StockQuantity = Math.Abs(inventoryInfo.SupplyQuantity), |
| | | SupplyQuantity = 0, |
| | | Remark = "çäºå
¥åº" |
| | | }; |
| | | //_supplyTaskHtyService.AddData(supplyTask_Hty); |
| | | supplyTask_Hties.Add(supplyTask_Hty); |
| | | } |
| | | #endregion |
| | | inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity; |
| | | inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity; |
| | | inventoryInfo.SupplyQuantity = 0; |
| | | inventoryInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | } |
| | | inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity; |
| | | inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity; |
| | | inventory_Batch.SupplyQuantity = 0; |
| | | infosUp.AddRange(inventoryInfos); |
| | | batchesUp.Add(inventory_Batch); |
| | | //_inventoryInfoService.UpdateData(inventoryInfos); |
| | | //_inventory_BatchServices.UpdateData(inventory_Batch); |
| | | } |
| | | #endregion |
| | | |
| | | #region å建çç¹å |
| | | var entityOrder = new Dt_DeliveryOrder |
| | | { |
| | | Out_no = order.order_no, |
| | | Out_type = order.order_type, |
| | | Client_no = order.client_no, |
| | | Client_name = order.client_name, |
| | | OutStatus = "已宿", |
| | | Account_time = order.account_time, |
| | | Warehouse_no = order.warehouse_no, |
| | | Details = order.details.Select(d => new Dt_DeliveryOrderDetail |
| | | { |
| | | Goods_no = d.goods_no, |
| | | Order_qty = Math.Abs(d.order_qty), |
| | | Order_Outqty = Math.Abs(d.order_qty), |
| | | Batch_num = d.batch_num, |
| | | Exp_date = d.exp_date, |
| | | Reservoirarea = order.warehouse_no, |
| | | OotDetailStatus = "已宿", |
| | | Status = 2, |
| | | }).ToList() |
| | | }; |
| | | _unitOfWorkManage.BeginTran(); |
| | | _supplyTaskHtyService.AddData(supplyTask_Hties); |
| | | _inventoryInfoService.UpdateData(infosUp); |
| | | _inventory_BatchServices.UpdateData(batchesUp); |
| | | BaseDal.Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand(); |
| | | _unitOfWorkManage.CommitTran(); |
| | | #endregion |
| | | } |
| | | #endregion |
| | | else |
| | | { |
| | | List<Dt_DeliveryOrder> deliveryOrdersAdd = new List<Dt_DeliveryOrder>(); |
| | | string WareCodeLK = WarehouseEnum.ç«åº.ObjToInt().ToString("000"); |
| | | string WareCodeDJ = WarehouseEnum.大件åº.ObjToInt().ToString("000"); |
| | | List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => codes.Contains(x.MaterielCode)); |
| | | List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoService.Repository.QueryData(x => codes.Contains(x.MaterielCode)); |
| | | foreach (var item in order.details) |
| | | { |
| | | //æ¾åºåæ¹æ¬¡ä¿¡æ¯ |
| | | Dt_Inventory_Batch inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num).First(); |
| | | var Qty = Math.Abs(inventory_Batch.SupplyQuantity); |
| | | if (Qty != item.order_qty) throw new Exception($"çäºåºåºåã{order.order_no}ãç©æç¼å·ã{item.goods_no}ãç©ææ¹æ¬¡ã{item.batch_num}ãççäºæ°éæè¯¯"); |
| | | //æ¾ææåºå |
| | | List<Dt_InventoryInfo> inventoryInfos = _InventoryInfos.Where(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo).ToList(); |
| | | //è·åç«åºçç¹å·®å¼æ°.ãããããããããããã |
| | | var inventoryLK = inventoryInfos.Where(x => x.WarehouseCode == WareCodeLK).First(); |
| | | //var LkQty = Math.Abs(inventoryLK.SupplyQuantity); |
| | | var LkQty = inventoryLK.SupplyQuantity; |
| | | //è·å大件åºçç¹å·®å¼æ° |
| | | var inventoryDJ = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList(); |
| | | //var DJQty = Math.Abs(inventoryDJ.Sum(x => x.SupplyQuantity)); |
| | | var DJQty = inventoryDJ.Sum(x => x.SupplyQuantity); |
| | | var count = Math.Abs(LkQty + DJQty); |
| | | if (count != Qty) throw new Exception($"ã{order.order_no}ãç©æç¼å·ã{item.goods_no}ãç©ææ¹æ¬¡ã{item.batch_num}ãçç©æä¿¡æ¯ä¸ç©ææ¹æ¬¡ä¿¡æ¯çäºæ°éä¸ç¬¦"); |
| | | if (LkQty == 0)//ç«åºæ å·®å¼ |
| | | { |
| | | #region åºåãåºåæ¹æ¬¡å¹³è´¦ |
| | | foreach (var inventoryInfo in inventoryInfos) |
| | | { |
| | | #region æ·»å çäºåºåºä»»å¡ |
| | | if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity) |
| | | { |
| | | Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty() |
| | | { |
| | | WarehouseCode = inventoryInfo.WarehouseCode, |
| | | OperateType = OperateTypeEnum.èªå¨å®æ.ToString(), |
| | | InsertTime = DateTime.Now, |
| | | TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt(), |
| | | BatchNo = inventoryInfo.BatchNo, |
| | | MaterielName = inventoryInfo.MaterielName, |
| | | MaterielCode = inventoryInfo.MaterielCode, |
| | | MaterielSpec = inventoryInfo.MaterielSpec, |
| | | TaskType = TaskTypeEnum.ChenckOut.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName, |
| | | LocationCode = inventoryInfo.LocationCode, |
| | | OrderNo = order.order_no, |
| | | StockQuantity = Math.Abs(inventoryInfo.SupplyQuantity), |
| | | SupplyQuantity = 0, |
| | | Remark = "çäºå
¥åº" |
| | | }; |
| | | //_supplyTaskHtyService.AddData(supplyTask_Hty); |
| | | supplyTask_Hties.Add(supplyTask_Hty); |
| | | } |
| | | #endregion |
| | | inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity; |
| | | inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity; |
| | | inventoryInfo.SupplyQuantity = 0; |
| | | inventoryInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | } |
| | | //_inventoryInfoService.UpdateData(inventoryInfos); |
| | | inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity; |
| | | inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity; |
| | | inventory_Batch.SupplyQuantity = 0; |
| | | //_inventory_BatchServices.UpdateData(inventory_Batch); |
| | | infosUp.AddRange(inventoryInfos); |
| | | batchesUp.Add(inventory_Batch); |
| | | #endregion |
| | | |
| | | #region å建大件åºçç¹å |
| | | var entityOrder = new Dt_DeliveryOrder |
| | | { |
| | | Out_no = order.order_no, |
| | | Out_type = order.order_type, |
| | | Client_no = order.client_no, |
| | | Account_time = order.account_time, |
| | | OutStatus = "已宿", |
| | | Client_name = order.client_name, |
| | | Warehouse_no = WareCodeDJ, |
| | | Details = order.details.Select(d => new Dt_DeliveryOrderDetail |
| | | { |
| | | Goods_no = d.goods_no, |
| | | Order_qty = Math.Abs(d.order_qty), |
| | | Order_Outqty = Math.Abs(d.order_qty), |
| | | Batch_num = d.batch_num, |
| | | Exp_date = d.exp_date, |
| | | Reservoirarea = WareCodeDJ, |
| | | OotDetailStatus = "已宿", |
| | | Status = 2, |
| | | }).ToList() |
| | | }; |
| | | //Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand(); |
| | | //Repository.AddData(entityOrder); |
| | | deliveryOrdersAdd.Add(entityOrder); |
| | | #endregion |
| | | } |
| | | else |
| | | { |
| | | #region 大件åºåºå平账 |
| | | inventoryInfos = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList(); |
| | | foreach (var inventoryInfo in inventoryInfos) |
| | | { |
| | | #region æ·»å çäºåºåºä»»å¡ |
| | | if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity) |
| | | { |
| | | Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty() |
| | | { |
| | | WarehouseCode = inventoryInfo.WarehouseCode, |
| | | OperateType = OperateTypeEnum.èªå¨å®æ.ToString(), |
| | | InsertTime = DateTime.Now, |
| | | TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt(), |
| | | BatchNo = inventoryInfo.BatchNo, |
| | | MaterielName = inventoryInfo.MaterielName, |
| | | MaterielCode = inventoryInfo.MaterielCode, |
| | | MaterielSpec = inventoryInfo.MaterielSpec, |
| | | TaskType = TaskTypeEnum.ChenckOut.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName, |
| | | LocationCode = inventoryInfo.LocationCode, |
| | | OrderNo = order.order_no, |
| | | StockQuantity = Math.Abs(inventoryInfo.SupplyQuantity), |
| | | SupplyQuantity = 0, |
| | | Remark = "çäºåºåº" |
| | | }; |
| | | //_supplyTaskHtyService.AddData(supplyTask_Hty); |
| | | supplyTask_Hties.Add(supplyTask_Hty); |
| | | } |
| | | #endregion |
| | | inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity; |
| | | inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity; |
| | | inventoryInfo.SupplyQuantity = 0; |
| | | inventoryInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | } |
| | | //_inventoryInfoService.UpdateData(inventoryInfos); |
| | | infosUp.AddRange(inventoryInfos); |
| | | #endregion |
| | | |
| | | #region å建大件åºçç¹å |
| | | if (DJQty != 0) |
| | | { |
| | | var cabinOrder = new Dt_DeliveryOrder |
| | | { |
| | | Out_no = order.order_no, |
| | | Out_type = order.order_type, |
| | | Client_name = order.client_name, |
| | | Account_time = order.account_time, |
| | | OutStatus = "已宿", |
| | | Client_no = order.client_no, |
| | | Warehouse_no = WareCodeDJ, |
| | | Details = order.details.Select(d => new Dt_DeliveryOrderDetail |
| | | { |
| | | Goods_no = d.goods_no, |
| | | Order_qty = DJQty, |
| | | Order_Outqty = DJQty, |
| | | Batch_num = d.batch_num, |
| | | Exp_date = d.exp_date, |
| | | Reservoirarea = WareCodeDJ, |
| | | OotDetailStatus = "已宿", |
| | | Status = 2, |
| | | }).ToList() |
| | | }; |
| | | //Repository.AddData(cabinOrder); |
| | | //Db.InsertNav(cabinOrder).Include(it => it.Details).ExecuteCommand(); |
| | | deliveryOrdersAdd.Add(cabinOrder); |
| | | } |
| | | #endregion |
| | | //è¿é |
| | | #region å建ç«åºçç¹å |
| | | var entityOrder = new Dt_DeliveryOrder |
| | | { |
| | | Out_no = order.order_no, |
| | | Out_type = order.order_type, |
| | | Client_no = order.client_no, |
| | | Account_time = order.account_time, |
| | | OutStatus = "æ°å»º", |
| | | Client_name = order.client_name, |
| | | Warehouse_no = WareCodeLK, |
| | | Details = order.details.Select(d => new Dt_DeliveryOrderDetail |
| | | { |
| | | Goods_no = d.goods_no, |
| | | Order_qty = Math.Abs(LkQty), //ç»ä¸æ¸¸WCSçæ¯è¦æ´æ° |
| | | Batch_num = d.batch_num, |
| | | Exp_date = d.exp_date, |
| | | Reservoirarea = WareCodeLK, |
| | | OotDetailStatus = "æ°å»º", |
| | | Status = 0, |
| | | }).ToList() |
| | | }; |
| | | //Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand(); |
| | | //Repository.AddData(entityOrder); |
| | | deliveryOrdersAdd.Add(entityOrder); |
| | | #endregion |
| | | } |
| | | //return WebResponseContent.Instance.OK("æå"); |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | _supplyTaskHtyService.AddData(supplyTask_Hties); |
| | | _inventoryInfoService.UpdateData(infosUp); |
| | | _inventory_BatchServices.UpdateData(batchesUp); |
| | | BaseDal.Db.InsertNav(deliveryOrdersAdd).Include(it => it.Details).ExecuteCommand(); |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | return WebResponseContent.Instance.OK("æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | //çç¹ æ¿æ´ä¸ªæ¹æ¬¡ä¿¡æ¯è¡¨çååæ¹å·åååç¼å·æ¥è¿è¡çç¹ |
| | |
| | | try |
| | | { |
| | | // 1ï¸â£ æ¥æ¾æå®æ¹æ¬¡ä¸ç©æçåºåä¿¡æ¯ |
| | | var batchInfo = BaseDal.Db.Queryable<Dt_Inventory_Batch>() |
| | | .Where(x => x.BatchNo == batchNo && x.MaterielCode == goodsNo) |
| | | .First(); |
| | | var batchInfo = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == batchNo && x.MaterielCode == goodsNo); |
| | | |
| | | if (batchInfo == null) |
| | | return response.Error($"æªæ¾å°è¯¥ç©æ [{goodsNo}] æ¹æ¬¡ [{batchNo}] çåºåä¿¡æ¯"); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// åºåºæ¥å®ææ¥å£ |
| | | /// æ¥è¯¢åºåºåå表 |
| | | /// </summary> |
| | | /// <param name="out_no">åºåºåå·</param> |
| | | /// <param name="saveModel"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent CompleteAllOutOrders() |
| | | { |
| | | var responseContent = new WebResponseContent(); |
| | | try |
| | | { |
| | | // æ¥æ¾ææâå¼å§âç¶æçåºåºå |
| | | var orders = BaseDal.Db.Queryable<Dt_DeliveryOrder>() |
| | | .Where(o => o.OutStatus == "å¼å§") |
| | | .ToList(); |
| | | |
| | | if (orders == null || !orders.Any()) |
| | | { |
| | | return responseContent.OK("ææ éè¦å¤ççåºåºå"); |
| | | } |
| | | |
| | | int successCount = 0; |
| | | int failCount = 0; |
| | | |
| | | foreach (var order in orders) |
| | | { |
| | | try |
| | | { |
| | | Db.Ado.BeginTran(); |
| | | |
| | | // æ¥è¯¢è¯¥åçæç» |
| | | var details = BaseDal.Db.Queryable<Dt_DeliveryOrderDetail>() |
| | | .Where(d => d.DeliveryOrderId == order.Id) |
| | | .ToList(); |
| | | |
| | | // 夿æç»æ¯å¦å
¨é¨å®æ |
| | | var completedCount = details.Count(d => d.OotDetailStatus == "已宿"); |
| | | var totalCount = details.Count; |
| | | |
| | | if (totalCount > 0 && completedCount == totalCount) |
| | | { |
| | | // æ´æ°ç¶æä¸ºå·²å®æ |
| | | BaseDal.Db.Updateable<Dt_DeliveryOrder>() |
| | | .SetColumns(o => o.OutStatus == "已宿") |
| | | .Where(o => o.Id == order.Id) |
| | | .ExecuteCommand(); |
| | | |
| | | // è°ç¨ä¸æ¸¸æ¥å£ |
| | | var url = "http://121.37.118.63:80/GYZ2/95fck/outOrderOk"; |
| | | var requestDate = new |
| | | { |
| | | order_no = order.Out_no |
| | | }; |
| | | var result = HttpHelper.Post(url, requestDate.ToJsonString()); |
| | | var response = JsonConvert.DeserializeObject<UpstreamOrderResponse>(result); |
| | | |
| | | if (response.resultCode == "0") |
| | | { |
| | | // â
æå
¥åå²è¡¨ï¼è¡¨å¤´ + æç»ï¼ |
| | | var orderHistory = new Dt_DeliveryOrder_Hty |
| | | { |
| | | Id = order.Id, |
| | | Out_no = order.Out_no, |
| | | Out_type = order.Out_type, |
| | | Client_no = order.Client_no, |
| | | Client_name = order.Client_name, |
| | | Account_time = order.Account_time, |
| | | Warehouse_no = order.Warehouse_no, |
| | | OutStatus = "已宿", |
| | | Details = details.Select(d => new Dt_DeliveryOrderDetail |
| | | { |
| | | Id = d.Id, |
| | | DeliveryOrderId = d.DeliveryOrderId, |
| | | Reservoirarea = d.Reservoirarea, |
| | | Goods_no = d.Goods_no, |
| | | Order_qty = d.Order_qty, |
| | | Batch_num = d.Batch_num, |
| | | Exp_date = d.Exp_date, |
| | | OotDetailStatus = d.OotDetailStatus, |
| | | Status = d.Status |
| | | }).ToList() |
| | | }; |
| | | |
| | | // æå
¥è¡¨å¤´åå² |
| | | var historyId = BaseDal.Db.Insertable(orderHistory).ExecuteReturnIdentity(); |
| | | |
| | | // æå
¥æç»åå²ï¼å¸¦æ°å¤é®ï¼ |
| | | var detailHistories = details.Select(d => new Dt_DeliveryOrderDetail_Hty |
| | | { |
| | | Id = d.Id, |
| | | DeliveryOrderId = order.Id, |
| | | Reservoirarea = d.Reservoirarea, |
| | | Goods_no = d.Goods_no, |
| | | Order_qty = d.Order_qty, |
| | | Batch_num = d.Batch_num, |
| | | Exp_date = d.Exp_date, |
| | | OotDetailStatus = d.OotDetailStatus, |
| | | Status = d.Status |
| | | }).ToList(); |
| | | |
| | | BaseDal.Db.Insertable(detailHistories).ExecuteCommand(); |
| | | |
| | | // å é¤åå§æ°æ®ï¼æç» â è¡¨å¤´ï¼ |
| | | BaseDal.Db.Deleteable<Dt_DeliveryOrderDetail>().Where(d => d.DeliveryOrderId == order.Id).ExecuteCommand(); |
| | | BaseDal.Db.Deleteable<Dt_DeliveryOrder>().Where(o => o.Id == order.Id).ExecuteCommand(); |
| | | |
| | | Db.Ado.CommitTran(); |
| | | successCount++; |
| | | } |
| | | else |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | failCount++; |
| | | SendErrorToUpstream(4, "", $"䏿¸¸æ¥å£è¿å失败: {response.resultMsg}", order.Out_no); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // ææªå®ææç»ï¼ä¸æ´æ° |
| | | Db.Ado.RollbackTran(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | failCount++; |
| | | SendErrorToUpstream(1, "", ex.Message, order.Out_no); |
| | | } |
| | | } |
| | | |
| | | return responseContent.OK($"æ¹éå¤çå®æï¼æå {successCount} åï¼å¤±è´¥ {failCount} åã"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return responseContent.Error("æ¹éå¤ç失败ï¼" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ¨éå¼å¸¸ä¿¡æ¯ç»ä¸æ¸¸ç³»ç» 1.å
¥åºåæ¥å£ï¼2.å
¥åºåæ¥å®ææ¥å£ï¼3.åºåºåæ¥å£ï¼4.åºåºæ¥å®ææ¥å£ï¼5.è¯ååºç¡ä¿¡æ¯åæ¥æ¥å£ï¼6.ä¾åºåä¿¡æ¯æ¥å£ï¼7.客æ·ä¿¡æ¯æ¥å£ï¼8.åºåæ¥è¯¢æ¥å£ |
| | | /// </summary> |
| | | public void SendErrorToUpstream(int type, string code, string message, string remark) |
| | | { |
| | | try |
| | | { |
| | | var url = "http://121.37.118.63:80/GYZ2/95fck/exceptionLog"; |
| | | |
| | | var requestData = new |
| | | { |
| | | type = type.ToString(), |
| | | code = code, |
| | | message = message, |
| | | remark = remark |
| | | }; |
| | | |
| | | var result = HttpHelper.Post(url, requestData.ToJsonString()); |
| | | // å¯ä»¥ååºååæ£æ¥ resultCode æ¯å¦ä¸º0 |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | // è¿éä¸è¦åæå¼å¸¸äºï¼é¿å
æ»å¾ªç¯ |
| | | Console.WriteLine("å¼å¸¸æ¥å£æ¨é失败ï¼" + e.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent GetPdDeliveryOrders(SaveModel saveModel) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | int pageNo = saveModel.MainData["pageNo"].ObjToInt(); |
| | | string warehouseCode = saveModel.MainData["warehouseId"].ToString(); |
| | | string orderNo = saveModel.MainData["orderNo"].ToString(); |
| | | List<Dt_DeliveryOrder> dt_ReceiveOrders = new List<Dt_DeliveryOrder>(); |
| | | if (string.IsNullOrEmpty(orderNo)) |
| | | { |
| | | dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.OutStatus == "æ°å»º" || x.OutStatus == "å¼å§") && x.Warehouse_no == warehouseCode && x.Out_type == "3").Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5); |
| | | } |
| | | else |
| | | { |
| | | dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.Out_no.Contains(orderNo) || x.Client_no.Contains(orderNo)) && (x.OutStatus == "æ°å»º" || x.OutStatus == "å¼å§" && x.Out_type == "3") && x.Warehouse_no == warehouseCode).OrderByDescending(x => x.CreateDate).Includes(x => x.Details).ToPageList(pageNo, 5); |
| | | } |
| | | |
| | | content.OK(data: dt_ReceiveOrders); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public WebResponseContent GetDeliveryOrders(SaveModel saveModel) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | |
| | | List<Dt_DeliveryOrder> dt_ReceiveOrders = new List<Dt_DeliveryOrder>(); |
| | | if (string.IsNullOrEmpty(orderNo)) |
| | | { |
| | | dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.OutStatus == "æ°å»º" || x.OutStatus == "å¼å§") && x.Warehouse_no == warehouseCode && x.Out_type != "3").Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5); |
| | | dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.OutStatus == "æ°å»º" || x.OutStatus == "å¼å§") && x.Warehouse_no == warehouseCode && x.Out_type != "20").Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5); |
| | | } |
| | | else |
| | | { |
| | | dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.Out_no.Contains(orderNo) || x.Client_no.Contains(orderNo)) && (x.OutStatus == "æ°å»º" || x.OutStatus == "å¼å§" && x.Out_type != "3") && x.Warehouse_no == warehouseCode).OrderByDescending(x => x.CreateDate).Includes(x => x.Details).ToPageList(pageNo, 5); |
| | | dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.Out_no.Contains(orderNo) || x.Client_no.Contains(orderNo)) && (x.OutStatus == "æ°å»º" || x.OutStatus == "å¼å§") && x.Out_type != "20" && x.Warehouse_no == warehouseCode).OrderByDescending(x => x.CreateDate).Includes(x => x.Details).ToPageList(pageNo, 5); |
| | | } |
| | | |
| | | content.OK(data: dt_ReceiveOrders); |
| | |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢åºåº/çç¹å详æ
çåºåºåæç»ã |
| | | /// </summary> |
| | | /// <param name="pageNo"></param> |
| | | /// <param name="orderNo"></param> |
| | | /// <param name="isPick"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent GetDeliveryOrderDetail(int pageNo, string orderNo, bool isPick) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | Dt_DeliveryOrder cabinOrder = new Dt_DeliveryOrder(); |
| | | if (isPick) |
| | | cabinOrder = Db.Queryable<Dt_DeliveryOrder>().Includes(x => x.Details).First(x => x.Out_no == orderNo && x.Out_type == "3"); |
| | | cabinOrder = Db.Queryable<Dt_DeliveryOrder>().Includes(x => x.Details).First(x => x.Out_no == orderNo && x.Out_type == "20"); |
| | | else |
| | | cabinOrder = Db.Queryable<Dt_DeliveryOrder>().Includes(x => x.Details).First(x => x.Out_no == orderNo && x.Out_type != "3"); |
| | | List<Dt_DeliveryOrderDetail>? cabinOrderDetails = cabinOrder.Details?.Where(x => x.Reservoirarea == pageNo.ToString()).ToList(); |
| | | cabinOrder = Db.Queryable<Dt_DeliveryOrder>().Includes(x => x.Details).First(x => x.Out_no == orderNo && x.Out_type != "20"); |
| | | //List<Dt_DeliveryOrderDetail>? cabinOrderDetails = cabinOrder.Details?.Where(x => x.Reservoirarea == pageNo.ToString()).ToList(); |
| | | List<Dt_DeliveryOrderDetail>? cabinOrderDetails = cabinOrder.Details?.Where(x => x.Status == 2).ToList(); |
| | | content.OK(data: cabinOrderDetails); |
| | | return content; |
| | | } |
| | | public WebResponseContent MatPicking(SaveModel saveModel) |
| | | |
| | | |
| | | /// <summary> |
| | | /// padåºåºå®æ |
| | | /// </summary> |
| | | /// <param name="saveModel"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent OutFinish(SaveModel saveModel) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var LocationCode = saveModel.MainData["LocationCode"].ToString(); |
| | | var orderNo = saveModel.MainData["orderNo"].ToString(); |
| | | var batchNo = saveModel.MainData["batchNo"].ToString(); |
| | | var Inqty = saveModel.MainData["Inqty"].ObjToInt(); |
| | | var warehouseCode = saveModel.MainData["warehouseCode"].ToString(); |
| | | Dt_DeliveryOrder cabinOrder = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == orderNo && x.Warehouse_no == warehouseCode && x.Out_type == "3").Includes(x => x.Details).First(); |
| | | if (cabinOrder == null) return WebResponseContent.Instance.Error($"çç¹å已宿"); |
| | | Dt_DeliveryOrderDetail cabinOrderDetail = cabinOrder.Details.Where(x => x.Batch_num == batchNo && x.Reservoirarea == warehouseCode).First(); |
| | | if (cabinOrderDetail == null) return WebResponseContent.Instance.Error($"çç¹åæç»å·²å®æ"); |
| | | Dt_MaterielInfo materielInfo = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == cabinOrderDetail.Goods_no); |
| | | if (materielInfo == null) return WebResponseContent.Instance.Error($"请维æ¤ç©æç¼å·ã{cabinOrderDetail.Goods_no}ãçç©æä¿¡æ¯"); |
| | | cabinOrderDetail.Order_Outqty += Inqty; |
| | | if (cabinOrderDetail.Order_Outqty > cabinOrderDetail.Order_qty) |
| | | return WebResponseContent.Instance.Error($"å®çæ°éä¸å¯è¶
åºè´¦é¢æ°é"); |
| | | |
| | | #region å¤çåºåºåï¼è´§ä½ï¼åºåï¼åºåæ¹æ¬¡ä¿¡æ¯ |
| | | _unitOfWorkManage.BeginTran(); |
| | | |
| | | #region åºåºå |
| | | cabinOrder.OutStatus = "å¼å§"; |
| | | var LocationCode = saveModel.MainData["locationCode"].ToString(); |
| | | var TaskId = saveModel.MainData["taskId"].ObjToInt(); |
| | | Dt_SupplyTask supplyTask = _supplyTaskService.Repository.QueryFirst(x => x.TaskId == TaskId && x.TaskStatus == SupplyStatusEnum.NewOut.ObjToInt()); |
| | | if (supplyTask == null) throw new Exception("å½ååºåºä»»å¡å·²å®æ"); |
| | | if (supplyTask.LocationCode != LocationCode) throw new Exception($"å½ååºåºè´§ä½ã{LocationCode}ãä¸ä»»å¡åé
è´§ä½ä¸å¹é
"); |
| | | Dt_DeliveryOrder deliveryOrder = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == supplyTask.OrderNo && x.Warehouse_no == supplyTask.WarehouseCode).Includes(x => x.Details).First(); |
| | | if (deliveryOrder == null) return WebResponseContent.Instance.OK($"åºåºå已宿"); |
| | | content = OutTaskFinish(supplyTask, deliveryOrder); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | public WebResponseContent OutTaskFinish(Dt_SupplyTask supplyTask, Dt_DeliveryOrder deliveryOrder) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_DeliveryOrderDetail? cabinOrderDetail = deliveryOrder.Details.FirstOrDefault(x => x.Batch_num == supplyTask.BatchNo && x.Goods_no == supplyTask.MaterielCode); |
| | | if (cabinOrderDetail == null) throw new Exception($"åºåºåæç»æªæ¾å°"); |
| | | Dt_MaterielInfo materielInfo = _materielInfoService.Repository.QueryFirst(x => x.MaterielCode == supplyTask.MaterielCode); |
| | | if (materielInfo == null) throw new Exception($"请维æ¤ç©æç¼å·ã{supplyTask.MaterielCode}ãçç©æä¿¡æ¯"); |
| | | cabinOrderDetail.Order_Outqty += supplyTask.StockQuantity; |
| | | if (cabinOrderDetail.Order_Outqty > cabinOrderDetail.Order_qty) throw new Exception($"åºåºæ°éä¸å¯è¶
åºåæ®æ°é"); |
| | | deliveryOrder.OutStatus = "å¼å§"; |
| | | cabinOrderDetail.OotDetailStatus = "å¼å§"; |
| | | if (cabinOrderDetail.Order_Outqty == cabinOrderDetail.Order_qty) |
| | | { |
| | | cabinOrderDetail.OotDetailStatus = "已宿"; |
| | | _deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrderDetail, OperateTypeEnum.èªå¨å®æ); |
| | | } |
| | | else |
| | | { |
| | | _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail); |
| | | } |
| | | var cabinOrder1 = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == cabinOrder.Out_no && x.Out_type == "3").Includes(x => x.Details).First(); |
| | | if (cabinOrder1.Details == null || cabinOrder1.Details.Count < 1) cabinOrder.OutStatus = "已宿"; |
| | | if (cabinOrder.OutStatus == "已宿") |
| | | Repository.DeleteAndMoveIntoHty(cabinOrder, OperateTypeEnum.èªå¨å®æ); |
| | | else |
| | | Repository.UpdateData(cabinOrder); |
| | | #endregion |
| | | if (cabinOrderDetail.Order_Outqty == cabinOrderDetail.Order_qty) cabinOrderDetail.OotDetailStatus = "已宿"; |
| | | |
| | | #region åºå |
| | | Dt_InventoryInfo inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.LocationCode == LocationCode); |
| | | if (inventoryInfo == null) return WebResponseContent.Instance.Error($"æªæ¾å°è´§ä½ã{LocationCode}ãçåºåä¿¡æ¯"); |
| | | inventoryInfo.SupplyQuantity += Inqty; |
| | | _inventoryInfoService.UpdateData(inventoryInfo); |
| | | Dt_InventoryInfo inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.LocationCode == supplyTask.LocationCode); |
| | | if (inventoryInfo == null) throw new Exception($"æªæ¾å°è´§ä½ã{supplyTask.LocationCode}ãçåºåä¿¡æ¯"); |
| | | inventoryInfo.StockQuantity -= supplyTask.StockQuantity; |
| | | inventoryInfo.OutboundQuantity -= supplyTask.StockQuantity; |
| | | #endregion |
| | | |
| | | #region ä»»å¡è®°å½ |
| | | Dt_SupplyTask supplyTask = new Dt_SupplyTask() |
| | | Dt_LocationInfo location = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == supplyTask.LocationCode); |
| | | #region è´§ä½ |
| | | if (supplyTask.WarehouseCode != WarehouseEnum.ç«åº.ObjToInt().ToString("000")) |
| | | { |
| | | WarehouseCode = cabinOrderDetail.Reservoirarea, |
| | | BatchNo = inventoryInfo.BatchNo, |
| | | MaterielName = inventoryInfo.MaterielName, |
| | | MaterielCode = inventoryInfo.MaterielCode, |
| | | MaterielSpec = inventoryInfo.MaterielSpec, |
| | | TaskType = TaskTypeEnum.OutInventory.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName, |
| | | LocationCode = LocationCode, |
| | | OrderNo = cabinOrder.Out_no, |
| | | StockQuantity = inventoryInfo.StockQuantity, |
| | | SupplyQuantity = Inqty, |
| | | Remark = "çç¹" |
| | | }; |
| | | _supplyTaskService.AddData(supplyTask); |
| | | #endregion |
| | | |
| | | #region åºåæ¹æ¬¡ |
| | | Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode); |
| | | if (inventory_Batch != null) |
| | | { |
| | | inventory_Batch.SupplyQuantity += Inqty; |
| | | _inventory_BatchServices.UpdateData(inventory_Batch); |
| | | if (location == null) |
| | | return WebResponseContent.Instance.Error($"请维æ¤è´§ä½ç¼å·ã{supplyTask.LocationCode}ãçè´§ä½ä¿¡æ¯"); |
| | | Dt_InventoryInfo inventoryInfo1 = _inventoryInfoService.Repository.QueryFirst(x => x.LocationCode == supplyTask.LocationCode); |
| | | if (inventoryInfo1 == null) location.LocationStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | } |
| | | #endregion |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | #region åºåæ¹æ¬¡ 妿任å¡ç±»åæ¯è°æ¨åºåºä»»å¡ï¼8ï¼å°±ä¸ä¿®æ¹æ¹æ¬¡åºå |
| | | Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == |
| | | inventoryInfo.MaterielCode); |
| | | if (supplyTask.TaskType != TaskTypeEnum.AllocatOut.ObjToInt()) |
| | | { |
| | | inventory_Batch.StockQuantity -= supplyTask.StockQuantity; |
| | | inventory_Batch.OutboundQuantity -= supplyTask.StockQuantity; |
| | | } |
| | | #endregion |
| | | supplyTask.TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt(); |
| | | |
| | | content.OK(cabinOrderDetail.Order_Outqty.ToString()); |
| | | _unitOfWorkManage.BeginTran(); |
| | | if (inventory_Batch.StockQuantity <= 0) |
| | | _inventory_BatchServices.DeleteData(inventory_Batch); |
| | | else |
| | | _inventory_BatchServices.UpdateData(inventory_Batch); |
| | | _materielInfoService.UpdateData(materielInfo); |
| | | if (inventoryInfo.StockQuantity <= 0) |
| | | _inventoryInfoService.DeleteData(inventoryInfo); |
| | | else |
| | | _inventoryInfoService.UpdateData(inventoryInfo); |
| | | if (location != null) _locationInfoService.UpdateData(location); |
| | | _deliveryOrderDetailServices.UpdateData(cabinOrderDetail); |
| | | _supplyTaskService.Repository.DeleteAndMoveIntoHty(supplyTask, OperateTypeEnum.äººå·¥å®æ); |
| | | |
| | | #region å¤æè¯¦æ
æ¯å¦å
¨é¨å®æ |
| | | if (!_deliveryOrderDetailServices.Repository.QueryData(x => x.DeliveryOrderId == deliveryOrder.Id && x.OotDetailStatus != "已宿").Any()) |
| | | deliveryOrder.OutStatus = "已宿"; |
| | | BaseDal.UpdateData(deliveryOrder); |
| | | if (supplyTask.WarehouseCode == WarehouseEnum.ç«åº.ObjToInt().ToString("000")) |
| | | { |
| | | materielInfo.Business_qty -= supplyTask.StockQuantity; |
| | | if (materielInfo.Business_qty < materielInfo.MinQty) |
| | | CreateAllocatInOut(materielInfo);//åå»ºè°æ¨ä»»å¡ |
| | | } |
| | | #endregion |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | } |
| | | return content; |
| | | } |
| | | public WebResponseContent FeedbackOut(SaveModel saveModel) |
| | | public WebResponseContent OutTaskFinish(Dt_SupplyTask supplyTask) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var LocationCode = saveModel.MainData["LocationCode"].ToString(); |
| | | var orderNo = saveModel.MainData["orderNo"].ToString(); |
| | | var batchNo = saveModel.MainData["batchNo"].ToString(); |
| | | var Inqty = saveModel.MainData["Inqty"].ObjToInt(); |
| | | var warehouseCode = saveModel.MainData["warehouseCode"].ToString(); |
| | | Dt_DeliveryOrder cabinOrder = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == orderNo && x.Warehouse_no == warehouseCode && x.Out_type != "3").Includes(x => x.Details).First(); |
| | | if (cabinOrder == null) return WebResponseContent.Instance.Error($"åºåºå已宿"); |
| | | Dt_DeliveryOrderDetail cabinOrderDetail = cabinOrder.Details.Where(x => x.Batch_num == batchNo && x.Reservoirarea == warehouseCode).First(); |
| | | if (cabinOrderDetail == null) return WebResponseContent.Instance.Error($"åºåºåæç»å·²å®æ"); |
| | | Dt_MaterielInfo materielInfo = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == cabinOrderDetail.Goods_no); |
| | | Dt_DeliveryOrder? cabinOrder = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == supplyTask.OrderNo && x.Warehouse_no == supplyTask.WarehouseCode).Includes(x => x.Details).First(); |
| | | if (cabinOrder == null) return WebResponseContent.Instance.OK($"åºåºå已宿"); |
| | | |
| | | Dt_DeliveryOrderDetail? cabinOrderDetail = cabinOrder.Details.Where(x => x.Batch_num == supplyTask.BatchNo && x.Reservoirarea == supplyTask.WarehouseCode && x.Goods_no == supplyTask.MaterielCode).FirstOrDefault(); |
| | | if (cabinOrderDetail == null) return WebResponseContent.Instance.Error($"åºåºåæç»æªæ¾å°"); |
| | | Dt_MaterielInfo materielInfo = _materielInfoService.Repository.QueryFirst(x => x.MaterielCode == cabinOrderDetail.Goods_no); |
| | | if (materielInfo == null) return WebResponseContent.Instance.Error($"请维æ¤ç©æç¼å·ã{cabinOrderDetail.Goods_no}ãçç©æä¿¡æ¯"); |
| | | cabinOrderDetail.Order_Outqty += Inqty; |
| | | cabinOrderDetail.Order_Outqty += supplyTask.StockQuantity; |
| | | if (cabinOrderDetail.Order_Outqty > cabinOrderDetail.Order_qty) |
| | | return WebResponseContent.Instance.Error($"åºåºæ°éä¸å¯è¶
åºåæ®æ°é"); |
| | | |
| | | #region å¤çåºåºåï¼è´§ä½ï¼åºåï¼åºåæ¹æ¬¡ä¿¡æ¯ |
| | | _unitOfWorkManage.BeginTran(); |
| | | |
| | | #region å¤çåºåºåï¼è´§ä½ï¼åºåï¼åºåæ¹æ¬¡ä¿¡æ¯,åºåºä»»å¡ |
| | | //_unitOfWorkManage.BeginTran(); |
| | | |
| | | #region åºåºå |
| | | cabinOrder.OutStatus = "å¼å§"; |
| | |
| | | if (cabinOrderDetail.Order_Outqty == cabinOrderDetail.Order_qty) |
| | | { |
| | | cabinOrderDetail.OotDetailStatus = "已宿"; |
| | | _deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrderDetail, OperateTypeEnum.èªå¨å®æ); |
| | | //_deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrderDetail, OperateTypeEnum.èªå¨å®æ); |
| | | } |
| | | else |
| | | { |
| | | _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail); |
| | | } |
| | | var cabinOrder1 = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == cabinOrder.Out_no && x.Out_type != "3").Includes(x => x.Details).First(); |
| | | if (cabinOrder1.Details == null || cabinOrder1.Details.Count < 1) cabinOrder.OutStatus = "已宿"; |
| | | _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail); |
| | | var cabinOrder1 = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == cabinOrder.Out_no && x.Warehouse_no == supplyTask.WarehouseCode && x.Out_type != "20").Includes(x => x.Details).First(); |
| | | if (!cabinOrder1.Details.Where(x => x.OotDetailStatus != "已宿").Any()) |
| | | cabinOrder.OutStatus = "已宿"; |
| | | Repository.UpdateData(cabinOrder); |
| | | #endregion |
| | | |
| | | #region åºå |
| | | Dt_InventoryInfo inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.LocationCode == LocationCode); |
| | | if (inventoryInfo == null) return WebResponseContent.Instance.Error($"æªæ¾å°è´§ä½ã{LocationCode}ãçåºåä¿¡æ¯"); |
| | | inventoryInfo.StockQuantity -= Inqty; |
| | | Dt_InventoryInfo inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.LocationCode == supplyTask.LocationCode); |
| | | if (inventoryInfo == null) return WebResponseContent.Instance.Error($"æªæ¾å°è´§ä½ã{supplyTask.LocationCode}ãçåºåä¿¡æ¯"); |
| | | inventoryInfo.StockQuantity -= supplyTask.StockQuantity; |
| | | inventoryInfo.OutboundQuantity -= supplyTask.StockQuantity; |
| | | if (inventoryInfo.StockQuantity <= 0) |
| | | _inventoryInfoService.DeleteData(inventoryInfo); |
| | | else |
| | |
| | | #endregion |
| | | |
| | | #region è´§ä½ |
| | | var location = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode); |
| | | if (location == null) return WebResponseContent.Instance.Error($"请维æ¤è´§ä½ç¼å·ã{LocationCode}ãçè´§ä½ä¿¡æ¯"); |
| | | if (location.EnableStatus == EnableStatusEnum.Disable.ObjToInt()) |
| | | return WebResponseContent.Instance.Error($"è´§ä½ç¼å·ã{LocationCode}ãå·²ç¦ç¨ï¼è¯·æ¢å¤æ£å¸¸å使ç¨"); |
| | | Dt_InventoryInfo inventoryInfo1 = _inventoryInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode); |
| | | if (inventoryInfo1 == null) |
| | | if (supplyTask.WarehouseCode != WarehouseEnum.ç«åº.ObjToInt().ToString("000")) |
| | | { |
| | | location.LocationStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | _basicService.LocationInfoService.UpdateData(location); |
| | | var location = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == supplyTask.LocationCode); |
| | | if (location == null) |
| | | return WebResponseContent.Instance.Error($"请维æ¤è´§ä½ç¼å·ã{supplyTask.LocationCode}ãçè´§ä½ä¿¡æ¯"); |
| | | //if (location.EnableStatus == EnableStatusEnum.Disable.ObjToInt()) |
| | | // return WebResponseContent.Instance.Error($"è´§ä½ç¼å·ã{supplyTask.LocationCode}ãå·²ç¦ç¨ï¼è¯·æ¢å¤æ£å¸¸å使ç¨"); |
| | | Dt_InventoryInfo inventoryInfo1 = _inventoryInfoService.Repository.QueryFirst(x => x.LocationCode == supplyTask.LocationCode); |
| | | if (inventoryInfo1 == null) |
| | | { |
| | | location.LocationStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | _locationInfoService.UpdateData(location); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region ä»»å¡è®°å½ |
| | | Dt_SupplyTask supplyTask = new Dt_SupplyTask() |
| | | { |
| | | WarehouseCode = cabinOrderDetail.Reservoirarea, |
| | | BatchNo = inventoryInfo.BatchNo, |
| | | MaterielName = inventoryInfo.MaterielName, |
| | | MaterielCode = inventoryInfo.MaterielCode, |
| | | MaterielSpec = inventoryInfo.MaterielSpec, |
| | | TaskType = TaskTypeEnum.OutPick.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName, |
| | | LocationCode = location.LocationCode, |
| | | OrderNo = cabinOrder.Out_no, |
| | | StockQuantity = Inqty, |
| | | SupplyQuantity = 0, |
| | | Remark = "åºåº" |
| | | }; |
| | | _supplyTaskService.AddData(supplyTask); |
| | | #endregion |
| | | //_supplyTaskService.UpdateData(supplyTask); |
| | | supplyTask.TaskNum = cabinOrderDetail.Id; |
| | | supplyTask.TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt(); |
| | | _supplyTaskService.Repository.DeleteAndMoveIntoHty(supplyTask, OperateTypeEnum.äººå·¥å®æ); |
| | | |
| | | #region åºåæ¹æ¬¡ |
| | | Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode); |
| | | if (inventory_Batch != null) |
| | | #region åºåæ¹æ¬¡ 妿任å¡ç±»åæ¯è°æ¨åºåºä»»å¡ï¼8ï¼å°±ä¸ä¿®æ¹æ¹æ¬¡åºå |
| | | if (supplyTask.TaskType != TaskTypeEnum.AllocatOut.ObjToInt()) |
| | | { |
| | | inventory_Batch.StockQuantity -= Inqty; |
| | | if (inventory_Batch.StockQuantity <= 0) |
| | | _inventory_BatchServices.DeleteData(inventory_Batch); |
| | | else |
| | | _inventory_BatchServices.UpdateData(inventory_Batch); |
| | | Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode); |
| | | if (inventory_Batch != null) |
| | | { |
| | | inventory_Batch.StockQuantity -= supplyTask.StockQuantity; |
| | | inventory_Batch.OutboundQuantity -= supplyTask.StockQuantity; |
| | | if (inventory_Batch.StockQuantity <= 0) |
| | | _inventory_BatchServices.DeleteData(inventory_Batch); |
| | | else |
| | | _inventory_BatchServices.UpdateData(inventory_Batch); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | if (supplyTask.WarehouseCode == WarehouseEnum.ç«åº.ObjToInt().ToString("000")) |
| | | { |
| | | materielInfo.Business_qty -= supplyTask.StockQuantity; |
| | | _materielInfoService.UpdateData(materielInfo); |
| | | if (materielInfo.Business_qty < materielInfo.MinQty) |
| | | CreateAllocatInOut(materielInfo);//åå»ºè°æ¨ä»»å¡ |
| | | } |
| | | //_unitOfWorkManage.CommitTran(); |
| | | #endregion |
| | | |
| | | content.OK(cabinOrderDetail.Order_Outqty.ToString()); |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 人工å¨åºåºåä¸ç¹å»å®ææé®å®ç°ä¸æ¥ |
| | | /// </summary> |
| | | /// <param name="key">id</param> |
| | | /// <returns></returns> |
| | | public WebResponseContent FinishOutOrder(int key) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_DeliveryOrder deliveryOrder = BaseDal.QueryFirst(x => x.Id == key); |
| | | List<Dt_DeliveryOrder> deliveryOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == deliveryOrder.Out_no).Includes(x => x.Details).ToList();//æ¾åºææåºåºåå·ç¸åçåºåºå |
| | | List<Dt_DeliveryOrderDetail> deliveryOrderDetails = new List<Dt_DeliveryOrderDetail>(); |
| | | foreach (var item in deliveryOrders) |
| | | { |
| | | if (item.Details != null) deliveryOrderDetails.AddRange(item.Details); |
| | | item.Modifier = App.User.UserName; |
| | | item.ModifyDate = DateTime.Now; |
| | | item.Details = null; |
| | | } |
| | | if (deliveryOrder.Out_type == OutOrderTypeEnum.Allocate.ObjToInt().ToString()) |
| | | { |
| | | _deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(deliveryOrderDetails, OperateTypeEnum.äººå·¥å®æ); |
| | | BaseDal.DeleteAndMoveIntoHty(deliveryOrders, OperateTypeEnum.äººå·¥å®æ); |
| | | } |
| | | else |
| | | { |
| | | var url = "http://121.37.118.63:80/GYZ2/95fck/outOrderOk"; |
| | | if (deliveryOrder.Out_type == "3") url = "http://121.37.118.63:80/GYZ2/95fck/inOrderOk"; |
| | | var requestDate = new |
| | | { |
| | | order_no = deliveryOrder.Out_no |
| | | }; |
| | | var result = HttpHelper.Post(url, requestDate.ToJsonString()); |
| | | var response = JsonConvert.DeserializeObject<UpstreamOrderResponse>(result); |
| | | if (response == null) throw new Exception("䏿¥ERPåºåºåå®æå¤±è´¥ï¼"); |
| | | if (response.resultCode != "0" && response.resultMsg != "æªæ¾å°åæ³åæ®") throw new Exception(response.resultMsg); |
| | | _deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(deliveryOrderDetails, OperateTypeEnum.äººå·¥å®æ); |
| | | BaseDal.DeleteAndMoveIntoHty(deliveryOrders, OperateTypeEnum.äººå·¥å®æ); |
| | | } |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |