| | |
| | | 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 System.Text; |
| | | using System.Threading.Tasks; |
| | | 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.SquareCabin; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_ISquareCabinServices; |
| | | using WIDESEA_IWMsInfoServices; |
| | | using WIDESEA_Model.Models; |
| | | using static WIDESEA_DTO.SquareCabin.OrderDto; |
| | | |
| | |
| | | |
| | | 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 = ""; |
| | | |
| | | public DeliveryOrderServices(IRepository<Dt_DeliveryOrder> BaseDal) : base(BaseDal) |
| | | 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, 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) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _deliveryOrderDetailServices = deliveryOrderDetailServices; |
| | | _supplyTaskService = supplyTaskService; |
| | | _inventory_BatchServices = inventory_BatchServices; |
| | | _inventoryInfoService = inventoryInfoService; |
| | | _cabinOrderServices = cabinOrderServices; |
| | | _tacticsService = tacticsService; |
| | | _supplyTaskHtyService = supplyTaskHtyService; |
| | | _messageInfoService = messageInfoService; |
| | | _materielInfoService = materielInfoService; |
| | | _locationInfoService = locationInfoService; |
| | | } |
| | | public override WebResponseContent UpdateData(SaveModel saveModel) |
| | | { |
| | | return base.UpdateData(saveModel); |
| | | } |
| | | |
| | | #region å建åºåºå |
| | | /// <summary> |
| | | /// è·å䏿¸¸åºåºå 0æå1失败 |
| | | /// å建åºåºå |
| | | /// </summary> |
| | | /// <param name="searchDate"></param> |
| | | /// <param name="outorder"></param> |
| | | /// <returns></returns> |
| | | //public WebResponseContent GetUpstreamOutOrder() |
| | | //{ |
| | | // var responseContent = new WebResponseContent(); |
| | | // try |
| | | // { |
| | | // // 请æ±å°å |
| | | // var url = "http://127.0.0.1:9000/GYZ2/95fck/outOrder"; |
| | | |
| | | // if (string.IsNullOrEmpty(SearchDate)) SearchDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | // //// 请æ±åæ° |
| | | // var requestData = new |
| | | // { |
| | | // searchDate = SearchDate |
| | | // }; |
| | | // 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("æ æ°åºåºåæ°æ®"); |
| | | // } |
| | | |
| | | // Db.Ado.BeginTran(); |
| | | |
| | | // foreach (var outorder in response.data) |
| | | // { |
| | | // try |
| | | // { |
| | | // // æå
¥åºåºå |
| | | // var entityOrder = new Dt_DeliveryOrder |
| | | // { |
| | | // Out_no = outorder.out_no, |
| | | // Out_type = outorder.out_type, |
| | | // Client_no = outorder.client_no, |
| | | // Client_name=outorder.client_name, |
| | | // Account_time = outorder.account_time, |
| | | // OutStatus= "æªå®æ", |
| | | // }; |
| | | // var outorderId = BaseDal.Db.Insertable(entityOrder).ExecuteReturnIdentity(); |
| | | |
| | | // // æå
¥åºåºåæç» |
| | | // var detailEntities = outorder.details.Select(d => new Dt_DeliveryOrderDetail |
| | | // { |
| | | // DeliveryOrderId = outorderId, |
| | | // Goods_no = d.goods_no, |
| | | // Order_qty = d.out_qty, |
| | | // Batch_num = d.batch_num, |
| | | // Exp_date = d.exp_date, |
| | | // OotDetailStatus="æ°å»º" |
| | | // }).ToList(); |
| | | // BaseDal.Db.Insertable(detailEntities).ExecuteCommand(); |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // SendErrorToUpstream(3, outorder.out_no, ex.Message, ""); |
| | | // throw; // 让å¤å±æè·å¹¶åæ» |
| | | // } |
| | | // } |
| | | |
| | | // Db.Ado.CommitTran(); |
| | | // return responseContent.OK("忥åºåºåæå"); |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // SendErrorToUpstream(3, "", ex.Message, ""); |
| | | // Db.Ado.RollbackTran(); |
| | | // return responseContent.Error("åæ¥å¤±è´¥: " + ex.Message); |
| | | // } |
| | | //} |
| | | |
| | | public WebResponseContent GetUpstreamOutOrder() |
| | | 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"; |
| | | |
| | | //if (string.IsNullOrEmpty(SearchDate)) SearchDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | //// 请æ±åæ° |
| | | 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 = 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) |
| | | #region æ·»å åºåºå |
| | | var entityOrder = new Dt_DeliveryOrder |
| | | { |
| | | 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 = outorder.details.Select(d => new Dt_DeliveryOrderDetail |
| | | { |
| | | // InsertNav ä¼èªå¨è®¾ç½®å
³èåæ®µ DeliveryOrderId |
| | | Goods_no = d.goods_no, |
| | | Order_qty = d.out_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 |
| | | //æ ¹æ®ç©æåç§°æ¥æ¾ç©æä¿¡æ¯ |
| | | |
| | | //æ ¹æ®ç®±è§å¤ææ¯å¦ææ£ä»¶ï¼è®¡ç®åºæ£ä»¶æ°éåæ´ä»¶æ° |
| | | |
| | | //æ ¹æ®å
¥åºæ¶é´åç»ï¼ææ£ä»¶å°±ä¼å
åé
ç«åºæ°éï¼æ´ä»¶ä¼å
åé
å¹³åºæ°é |
| | | |
| | | |
| | | #endregion |
| | | _DeliveryOrders.Add(entityOrder); |
| | | //orderNos.Add(outorder.out_no); |
| | | }; |
| | | |
| | | // ä½¿ç¨ 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); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <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 materialCode = "YY";//é»è®¤å¼ |
| | | //è·åå½å订åç第ä¸ä¸ªæç»é¡¹ |
| | | var firstDetail = order.Details.FirstOrDefault(); |
| | | if (firstDetail?.MedicineGoods != null && !string.IsNullOrEmpty(firstDetail.MedicineGoods.MaterialCode)) |
| | | { |
| | | //妿æ¡ä»¶æ»¡è¶³ï¼å°ç©æä»£ç 设置为第ä¸ä¸ªæç»é¡¹å¯¹åºçè¯åç©æä»£ç |
| | | 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 |
| | | { |
| | | 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() |
| | | }; |
| | | |
| | | // 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} æ¨éæå"); |
| | | } |
| | | else |
| | | { |
| | | SendErrorToUpstream(3, order.Out_no, resp?.msg ?? "WCS æ¨é失败", ""); |
| | | Console.WriteLine($"订å {order.Out_no} æ¨é失败ï¼{resp?.msg}"); |
| | | } |
| | | //å é¤å
¨é¨ç¶ä¸ºå·²å®æçæç»å表头ï¼ç§»å
¥åå²è¡¨ |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | SendErrorToUpstream(3, order.Out_no, ex.Message, ""); |
| | | Console.WriteLine($"订å {order.Out_no} æ¨éå¼å¸¸ï¼{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | return responseContent.OK("åºåºè®¢åæ¨é宿"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine("EdiOut å¼å¸¸ï¼" + ex.Message); |
| | | return responseContent.Error("åºåºè®¢åæ¨é失败ï¼" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// åºåºæ¥å®ææ¥å£ |
| | | /// </summary> |
| | | /// <param name="out_no">åºåºåå·</param> |
| | | /// <returns></returns> |
| | | //public WebResponseContent CompleteOutOrder(string out_no) |
| | | //{ |
| | | // var responseContent = new WebResponseContent(); |
| | | // try |
| | | // { |
| | | // if (string.IsNullOrWhiteSpace(out_no)) |
| | | // { |
| | | // return responseContent.Error("å
¥åºåå·ä¸å¯ä»¥ä¸ºç©º"); |
| | | // } |
| | | |
| | | // Db.Ado.BeginTran(); |
| | | // //å
æ¥å¤´è¡¨ |
| | | // var outOerd= BaseDal.Db.Queryable<Dt_DeliveryOrder>() |
| | | // .Where(o => o.Out_no == out_no) |
| | | // .First(); |
| | | // if (outOerd == null) |
| | | // { |
| | | // return responseContent.Error($"æ²¡ææ¾å°è¯¥åºåºåå·{out_no}"); |
| | | // } |
| | | // //æ¥æ¾æææç»è¡¨æ¯å¦é½å·²å®æ |
| | | // var incompleteDetails = BaseDal.Db.Queryable<Dt_DeliveryOrderDetail>() |
| | | // .Where(d => d.DeliveryOrderId == outOerd.Id && d.OotDetailStatus == "已宿") |
| | | // .Count(); |
| | | // if (incompleteDetails>0) |
| | | // { |
| | | // // æ´æ°åºåºåç¶æ |
| | | // BaseDal.Db.Updateable<Dt_DeliveryOrder>() |
| | | // .SetColumns(o => new Dt_DeliveryOrder { OutStatus = "å¼å§" }) |
| | | // .Where(o => o.Out_no == out_no) |
| | | // .ExecuteCommand(); |
| | | // var url = " http://127.0.0.1:9090/GYZ2/95fck/outOrderOk"; |
| | | // var reslut = HttpHelper.Post(url, new { out_no }.ToJsonString()); |
| | | // var response = JsonConvert.DeserializeObject<UpstreamOrderResponse>(reslut); |
| | | // if (response.resultCode != "0") |
| | | // { |
| | | // SendErrorToUpstream(4, "", "䏿¸¸æ¥å£è¿å失败", ""); |
| | | // return responseContent.Error(response.resultMsg ?? "䏿¸¸æ¥å£è¿å失败"); |
| | | // } |
| | | // Db.Ado.CommitTran(); |
| | | // return responseContent.OK("æä½æå,åºåºå以åæç»å
¨é¨å®æ"); |
| | | // } |
| | | // else |
| | | // { |
| | | // return responseContent.OK("æä½æåï¼ä½ä»»æä¸ºå®æçæç»"); |
| | | // } |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // Db.Ado.RollbackTran(); |
| | | // SendErrorToUpstream(1, "", ex.Message, ""); |
| | | // return responseContent.Error("åæ¥å¤±è´¥: " + ex.Message); |
| | | // } |
| | | //} |
| | | |
| | | |
| | | /// <summary> |
| | | ///çç¹åºåºåæ¨éç» WCS |
| | | /// </summary> |
| | | /// <param name="externalOrderNo">åºåºåå·</param> |
| | | /// <returns></returns> |
| | | //public WebResponseContent InventoryGood(string externalOrderNo) |
| | | //{ |
| | | // try |
| | | // { |
| | | // // æ¥è¯¢åºåºååæç» |
| | | // var orders = BaseDal.Db.CopyNew().Queryable<Dt_DeliveryOrder>() |
| | | // .Where(x => x.Out_no == externalOrderNo) |
| | | // .Includes(o => o.Details, d => d.MedicineGoods) |
| | | // .ToList(); |
| | | |
| | | |
| | | // if (orders == null || orders.Count == 0) |
| | | // { |
| | | // return new WebResponseContent().Error("æ²¡ææ¾å°è¯¥åºåºå"); |
| | | // } |
| | | |
| | | // var url = "http://172.16.1.2:9357/file-admin/api/out/ediOut"; |
| | | // bool allSuccess = true; |
| | | |
| | | // foreach (var order in orders) |
| | | // { |
| | | // //æ¥æ¾ç»ååçåºå |
| | | // var Invert = BaseDal.Db.Queryable<Dt_Inventory>() |
| | | // .Where(i => i.Goods_no == order.Out_no).First(); |
| | | // var ediDto = new TowcsDto.ToediOutInfo |
| | | // { |
| | | // customerCode = "905", |
| | | // materialCode = "YY", |
| | | // externalOrderNo = order.Out_no, |
| | | // outOrderType = "20", // çç¹åºåºå |
| | | // priority = 1, |
| | | // Is_cancel = 0, |
| | | // details = order.Details.Select(d => new TowcsDto.ToeOutdiInDetail |
| | | // { |
| | | // batchNo = d.Batch_num, |
| | | // productCode = d.Goods_no, |
| | | // productName = d.MedicineGoods?.Goods_spm, |
| | | // productSpecifications = d.MedicineGoods?.Model, |
| | | // quantity = (int)d.Order_qty, |
| | | // stocktakingDetails = new List<TowcsDto.ToOutediInStock> |
| | | // { |
| | | // new TowcsDto.ToOutediInStock |
| | | // { |
| | | // palletCode = Invert.PalletCode, // å®é
ä»ç³»ç»å |
| | | // quantity = d.Order_qty.ToString() |
| | | // } |
| | | // } |
| | | // }).ToList() |
| | | // }; |
| | | |
| | | // var result = HttpHelper.Post(url, ediDto.ToJsonString()); |
| | | // var resp = JsonConvert.DeserializeObject<TowcsDto.TowcsResponse<object>>(result); |
| | | |
| | | // if (resp == null || resp.code != "0") |
| | | // { |
| | | // allSuccess = false; |
| | | // break; |
| | | // } |
| | | // } |
| | | |
| | | // return allSuccess |
| | | // ? new WebResponseContent { Status = true, Message = "çç¹æå" } |
| | | // : new WebResponseContent { Status = false, Message = "çç¹å¤±è´¥" }; |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // return new WebResponseContent { Status = false, Message = ex.Message }; |
| | | // } |
| | | //} |
| | | public WebResponseContent InventoryGood(string externalOrderNo) |
| | | { |
| | | try |
| | | { |
| | | // 1. æ¥åºåºåºååæç» |
| | | var orders = BaseDal.Db.CopyNew().Queryable<Dt_DeliveryOrder>() |
| | | .Where(x => x.Out_no == externalOrderNo) |
| | | .Includes(o => o.Details, d => d.MedicineGoods) |
| | | .ToList(); |
| | | |
| | | if (orders == null || orders.Count == 0) |
| | | return new WebResponseContent().Error("æ²¡ææ¾å°è¯¥åºåºå"); |
| | | |
| | | // 2. è·åææååç¼å· |
| | | var allGoodsNos = orders |
| | | .SelectMany(o => o.Details.Select(d => d.Goods_no)) |
| | | .Distinct() |
| | | .ToList(); |
| | | |
| | | // 3. 䏿¬¡æ§æ¥è¯¢åºåä¿¡æ¯ |
| | | var inventoryList = BaseDal.Db.Queryable<Dt_Inventory>() |
| | | .Where(i => allGoodsNos.Contains(i.Goods_no)) |
| | | .ToList(); |
| | | |
| | | var inventoryDict = inventoryList.ToDictionary(i => i.Goods_no, i => i); |
| | | |
| | | string url = "http://172.16.1.2:9357/file-admin/api/out/ediOut"; |
| | | bool allSuccess = true; |
| | | |
| | | // 4. æé çç¹åºåºè¯·æ± |
| | | foreach (var order in orders) |
| | | { |
| | | var ediDto = new TowcsDto.ToediOutInfo |
| | | { |
| | | customerCode = "905", |
| | | materialCode = "YY", |
| | | externalOrderNo = order.Out_no, |
| | | outOrderType = "20", // çç¹åºåºå |
| | | priority = 1, |
| | | Is_cancel = 0, |
| | | details = order.Details.Select(d => |
| | | { |
| | | inventoryDict.TryGetValue(d.Goods_no, out var invert); |
| | | |
| | | return new TowcsDto.ToeOutdiInDetail |
| | | { |
| | | batchNo = d.Batch_num, |
| | | productCode = d.Goods_no, |
| | | productName = d.MedicineGoods?.Goods_spm, |
| | | productSpecifications = d.MedicineGoods?.Model, |
| | | quantity = (int)d.Order_qty, |
| | | stocktakingDetails = new List<TowcsDto.ToOutediInStock> |
| | | { |
| | | new TowcsDto.ToOutediInStock |
| | | { |
| | | palletCode = invert?.PalletCode ?? string.Empty, |
| | | quantity = d.Order_qty.ToString() |
| | | } |
| | | } |
| | | }; |
| | | 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() |
| | | }; |
| | | |
| | | var result = HttpHelper.Post(url, ediDto.ToJsonString()); |
| | | var resp = JsonConvert.DeserializeObject<TowcsDto.TowcsResponse<object>>(result); |
| | | |
| | | if (resp == null || resp.code != "0") |
| | | #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) |
| | | { |
| | | allSuccess = false; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | return allSuccess |
| | | ? new WebResponseContent { Status = true, Message = "çç¹æå" } |
| | | : new WebResponseContent { Status = false, Message = "çç¹å¤±è´¥" }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = ex.Message }; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// åºåºæ¥å®ææ¥å£ |
| | | /// </summary> |
| | | /// <param name="out_no">åºåºåå·</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) |
| | | 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) |
| | | { |
| | | // æ´æ°ç¶æä¸ºå·²å®æ |
| | | 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 |
| | | if (Order_qty <= 0) break; |
| | | if (InventoryInfo.AvailableQuantity <= Order_qty) |
| | | { |
| | | 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 |
| | | Order_qty -= InventoryInfo.AvailableQuantity; |
| | | InventoryInfo.OutboundQuantity += InventoryInfo.AvailableQuantity; |
| | | Dt_SupplyTask supplyTask = new Dt_SupplyTask() |
| | | { |
| | | 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() |
| | | 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 = "åºåº" |
| | | }; |
| | | |
| | | // æå
¥è¡¨å¤´åå² |
| | | 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++; |
| | | supplyTasks.Add(supplyTask); |
| | | InventoryInfo.AvailableQuantity = 0; |
| | | } |
| | | else |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | failCount++; |
| | | SendErrorToUpstream(4, "", $"䏿¸¸æ¥å£è¿å失败: {response.resultMsg}", order.Out_no); |
| | | 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; |
| | | } |
| | | inventoryInfosUp.Add(InventoryInfo); |
| | | } |
| | | batchesUp.Add(inventory_Batch); |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | _supplyTaskService.AddData(supplyTasks); |
| | | _inventory_BatchServices.UpdateData(batchesUp); |
| | | _inventoryInfoService.UpdateData(inventoryInfosUp); |
| | | BaseDal.Db.CopyNew().InsertNav(entityOrder).Include(x => x.Details).ExecuteCommand(); |
| | | _unitOfWorkManage.CommitTran(); |
| | | #endregion |
| | | } |
| | | #endregion |
| | | else |
| | | { |
| | | string WareCodeDJ = WarehouseEnum.大件åº.ObjToInt().ToString("000"); |
| | | string WareCodeLK = WarehouseEnum.ç«åº.ObjToInt().ToString("000"); |
| | | #region å建大件åºãç«åºåºåºå¤´è¡¨ |
| | | var entityOrder = 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 = 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)//å¦æç©ææ¯å¤§ä»¶ |
| | | { |
| | | #region æ·»å åºåºè¯¦æ
|
| | | Dt_DeliveryOrderDetail orderDetail = new Dt_DeliveryOrderDetail() |
| | | { |
| | | 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 |
| | | |
| | | #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 |
| | | { |
| | | // ææªå®ææç»ï¼ä¸æ´æ° |
| | | Db.Ado.RollbackTran(); |
| | | 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.CopyNew().InsertNav(entityOrder).Include(x => x.Details).ExecuteCommand(); |
| | | if (entityOrderLK.Details.Count > 0) |
| | | BaseDal.Db.CopyNew().InsertNav(entityOrderLK).Include(x => x.Details).ExecuteCommand(); |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | failCount++; |
| | | SendErrorToUpstream(1, "", ex.Message, order.Out_no); |
| | | _unitOfWorkManage.RollbackTran(); |
| | | } |
| | | #endregion |
| | | } |
| | | |
| | | return responseContent.OK($"æ¹éå¤çå®æï¼æå {successCount} åï¼å¤±è´¥ {failCount} åã"); |
| | | webResponseContent.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | 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 |
| | | |
| | | |
| | | //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; |
| | | // int serverErrorCount = 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 |
| | | // }; |
| | | |
| | | // string result; |
| | | // try |
| | | // { |
| | | // result = HttpHelper.Post(url, requestDate.ToJsonString()); |
| | | // } |
| | | // catch (Exception httpEx) |
| | | // { |
| | | // // HTTP请æ±å¼å¸¸ï¼ç½ç»é®é¢çï¼ |
| | | // Db.Ado.RollbackTran(); |
| | | // failCount++; |
| | | // SendErrorToUpstream(3, "", $"ç½ç»è¯·æ±å¤±è´¥: {httpEx.Message}", order.Out_no); |
| | | // continue; |
| | | // } |
| | | |
| | | // // â
æ£æ¥æ¯å¦æ¯500éè¯¯é¡µé¢ |
| | | // if (!string.IsNullOrEmpty(result) && result.Contains("500é误页é¢")) |
| | | // { |
| | | // Db.Ado.RollbackTran(); |
| | | // serverErrorCount++; |
| | | // SendErrorToUpstream(5, "", "䏿¸¸æ¥å£æå¡å¨å
é¨é误(500)ï¼è¯·èç³»ä¸æ¸¸ç³»ç»ç®¡çå", order.Out_no); |
| | | // continue; |
| | | // } |
| | | |
| | | // // â
æ£æ¥æ¯å¦æ¯HTMLååº |
| | | // if (!string.IsNullOrEmpty(result) && result.Trim().StartsWith("<")) |
| | | // { |
| | | // Db.Ado.RollbackTran(); |
| | | // failCount++; |
| | | // SendErrorToUpstream(4, "", "䏿¸¸æ¥å£è¿åéJSONæ ¼å¼ååº", order.Out_no); |
| | | // continue; |
| | | // } |
| | | |
| | | // // â
å®å
¨è§£æJSON |
| | | // UpstreamOrderResponse response; |
| | | // try |
| | | // { |
| | | // response = JsonConvert.DeserializeObject<UpstreamOrderResponse>(result); |
| | | // } |
| | | // catch (JsonReaderException jsonEx) |
| | | // { |
| | | // Db.Ado.RollbackTran(); |
| | | // failCount++; |
| | | // SendErrorToUpstream(4, "", $"䏿¸¸æ¥å£è¿åæ°æ®æ ¼å¼é误: {jsonEx.Message}", order.Out_no); |
| | | // continue; |
| | | // } |
| | | |
| | | // 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} åï¼æå¡å¨é误 {serverErrorCount} åã"); |
| | | // } |
| | | // 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) |
| | | #region å建çäºåºåºå |
| | | public WebResponseContent CreateCheckOutOrder(UpstramOutOrderInfo order) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var url = "http://121.37.118.63:80/GYZ2/95fck/exceptionLog"; |
| | | |
| | | var requestData = new |
| | | 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) |
| | | { |
| | | type = type.ToString(), |
| | | code = code, |
| | | message = message, |
| | | remark = remark |
| | | 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 inventoryDJ = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList(); |
| | | var DJQty = Math.Abs(inventoryDJ.Sum(x => x.SupplyQuantity)); |
| | | if (LkQty + DJQty != 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 = LkQty, |
| | | 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 |
| | | |
| | | |
| | | //çç¹ æ¿æ´ä¸ªæ¹æ¬¡ä¿¡æ¯è¡¨çååæ¹å·åååç¼å·æ¥è¿è¡çç¹ |
| | | public WebResponseContent InventoryGood(string batchNo, string goodsNo) |
| | | { |
| | | var response = new WebResponseContent(); |
| | | try |
| | | { |
| | | // 1ï¸â£ æ¥æ¾æå®æ¹æ¬¡ä¸ç©æçåºåä¿¡æ¯ |
| | | var batchInfo = BaseDal.Db.CopyNew().Queryable<Dt_Inventory_Batch>() |
| | | .Where(x => x.BatchNo == batchNo && x.MaterielCode == goodsNo) |
| | | .First(); |
| | | |
| | | if (batchInfo == null) |
| | | return response.Error($"æªæ¾å°è¯¥ç©æ [{goodsNo}] æ¹æ¬¡ [{batchNo}] çåºåä¿¡æ¯"); |
| | | |
| | | // 2ï¸â£ ç»è£
è¯·æ± DTOï¼å®å
¨ç¬¦åæ¥å£ææ¡£ç»æï¼ |
| | | var ediDto = new TowcsDto.ToediOutInfo |
| | | { |
| | | customerCode = "905", |
| | | materialCode = "YY", // ç©æç±»åCODE |
| | | externalOrderNo = $"PDCK-{batchInfo.Id}", // å¤é¨åºåºåå· |
| | | outOrderType = "20", // çç¹åºåºå |
| | | priority = 1, |
| | | Is_cancel = 0, |
| | | details = new List<TowcsDto.ToeOutdiInDetail> |
| | | { |
| | | new TowcsDto.ToeOutdiInDetail |
| | | { |
| | | batchNo = batchInfo.BatchNo, |
| | | productCode = batchInfo.MaterielCode, |
| | | productName = batchInfo.MaterielName, |
| | | productSpecifications = batchInfo.MaterielSpec, |
| | | quantity = (int)batchInfo.SupplyQuantity, |
| | | //stocktakingDetails = new List<TowcsDto.ToOutediInStock> |
| | | //{ |
| | | // // çç¹æç»å¯æ ¹æ®å®é
æçæåï¼æ¤å¤ç¤ºä¾ä»
1æ¡ |
| | | // new TowcsDto.ToOutediInStock |
| | | // { |
| | | // palletCode = "FC00001", |
| | | // quantity = batchInfo.SupplyQuantity.ToString() |
| | | // } |
| | | //} |
| | | } |
| | | } |
| | | }; |
| | | |
| | | var result = HttpHelper.Post(url, requestData.ToJsonString()); |
| | | // å¯ä»¥ååºååæ£æ¥ resultCode æ¯å¦ä¸º0 |
| | | // 3ï¸â£ è°ç¨æ¥å£ |
| | | string 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); |
| | | |
| | | // 4ï¸â£ ååºå¤ç |
| | | if (resp == null) |
| | | return response.Error("WCS æ ååº"); |
| | | if (resp.code != "0") |
| | | return response.Error($"WCSè¿å失败: {resp.msg}"); |
| | | |
| | | return response.OK("çç¹åºåºä¸åæå"); |
| | | } |
| | | catch (Exception e) |
| | | catch (Exception ex) |
| | | { |
| | | // è¿éä¸è¦åæå¼å¸¸äºï¼é¿å
æ»å¾ªç¯ |
| | | Console.WriteLine("å¼å¸¸æ¥å£æ¨é失败ï¼" + e.Message); |
| | | return response.Error("çç¹å¤±è´¥ï¼" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢åºåºåå表 |
| | | /// </summary> |
| | | /// <param name="saveModel"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent GetDeliveryOrders(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 != "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 != "20" && 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; |
| | | } |
| | | |
| | | /// <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 == "20"); |
| | | else |
| | | 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; |
| | | } |
| | | |
| | | |
| | | /// <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 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 = "已宿"; |
| | | |
| | | #region åºå |
| | | 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 |
| | | Dt_LocationInfo location = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == supplyTask.LocationCode); |
| | | #region è´§ä½ |
| | | if (supplyTask.WarehouseCode != WarehouseEnum.ç«åº.ObjToInt().ToString("000")) |
| | | { |
| | | 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 |
| | | |
| | | #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(); |
| | | |
| | | _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) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | public WebResponseContent OutTaskFinish(Dt_SupplyTask supplyTask) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_DeliveryOrder? cabinOrder = BaseDal.Db.CopyNew().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 += supplyTask.StockQuantity; |
| | | if (cabinOrderDetail.Order_Outqty > cabinOrderDetail.Order_qty) |
| | | return WebResponseContent.Instance.Error($"åºåºæ°éä¸å¯è¶
åºåæ®æ°é"); |
| | | |
| | | |
| | | #region å¤çåºåºåï¼è´§ä½ï¼åºåï¼åºåæ¹æ¬¡ä¿¡æ¯,åºåºä»»å¡ |
| | | //_unitOfWorkManage.BeginTran(); |
| | | |
| | | #region åºåºå |
| | | cabinOrder.OutStatus = "å¼å§"; |
| | | cabinOrderDetail.OotDetailStatus = "å¼å§"; |
| | | if (cabinOrderDetail.Order_Outqty == cabinOrderDetail.Order_qty) |
| | | { |
| | | cabinOrderDetail.OotDetailStatus = "已宿"; |
| | | //_deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrderDetail, OperateTypeEnum.èªå¨å®æ); |
| | | } |
| | | _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail); |
| | | var cabinOrder1 = BaseDal.Db.CopyNew().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 == 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 |
| | | _inventoryInfoService.UpdateData(inventoryInfo); |
| | | #endregion |
| | | |
| | | #region è´§ä½ |
| | | if (supplyTask.WarehouseCode != WarehouseEnum.ç«åº.ObjToInt().ToString("000")) |
| | | { |
| | | 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 |
| | | |
| | | //_supplyTaskService.UpdateData(supplyTask); |
| | | supplyTask.TaskNum = cabinOrderDetail.Id; |
| | | supplyTask.TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt(); |
| | | _supplyTaskService.Repository.DeleteAndMoveIntoHty(supplyTask, OperateTypeEnum.äººå·¥å®æ); |
| | | |
| | | #region åºåæ¹æ¬¡ 妿任å¡ç±»åæ¯è°æ¨åºåºä»»å¡ï¼8ï¼å°±ä¸ä¿®æ¹æ¹æ¬¡åºå |
| | | if (supplyTask.TaskType != TaskTypeEnum.AllocatOut.ObjToInt()) |
| | | { |
| | | 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 |
| | | 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(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | 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; |
| | | } |
| | | } |
| | | } |