| | |
| | | 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; |
| | |
| | | private readonly IDeliveryOrderDetailServices _deliveryOrderDetailServices; |
| | | private readonly ISupplyTaskService _supplyTaskService; |
| | | private readonly ICabinOrderServices _cabinOrderServices; |
| | | private readonly ITacticsService _tacticsService; |
| | | 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, ICabinOrderServices cabinOrderServices) : base(BaseDal) |
| | | public DeliveryOrderServices(IRepository<Dt_DeliveryOrder> BaseDal, IBasicService basicService, IUnitOfWorkManage unitOfWorkManage, IInventory_BatchServices inventory_BatchServices, IInventoryInfoService inventoryInfoService, IDeliveryOrderDetailServices deliveryOrderDetailServices, ISupplyTaskService supplyTaskService, ICabinOrderServices cabinOrderServices, ITacticsService tacticsService) : base(BaseDal) |
| | | { |
| | | _basicService = basicService; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | |
| | | _inventory_BatchServices = inventory_BatchServices; |
| | | _inventoryInfoService = inventoryInfoService; |
| | | _cabinOrderServices = cabinOrderServices; |
| | | _tacticsService = tacticsService; |
| | | } |
| | | public WebResponseContent GetUpstreamOutOrder() |
| | | { |
| | |
| | | WebResponseContent webResponseContent = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Tactics tactics = _tacticsService.Repository.QueryFirst(x => x.TacticeName == "åºåºçç¥"); |
| | | if (outorder.warehouse_no == WarehouseEnum.麻精åº.ObjToInt().ToString("000") || outorder.warehouse_no == WarehouseEnum.å·å»åº.ObjToInt().ToString("000")) |
| | | { |
| | | #region æ·»å åºåºå |
| | |
| | | OutStatus = "æ°å»º", |
| | | Details = outorder.details.Select(d => new Dt_DeliveryOrderDetail |
| | | { |
| | | Reservoirarea = outorder.warehouse_no, |
| | | Goods_no = d.goods_no, |
| | | Order_qty = Math.Abs(d.order_qty), // åºåºæ°éè½¬ä¸ºæ£æ° |
| | | Batch_num = d.batch_num, |
| | |
| | | }; |
| | | BaseDal.Db.InsertNav(entityOrder).Include(x => x.Details).ExecuteCommand(); |
| | | #endregion |
| | | |
| | | #region å¤çåºå |
| | | |
| | | #endregion |
| | | |
| | | #region æ·»å åºåºä»»å¡ |
| | | |
| | | #region å¤çåºåãåºåæ¹æ¬¡ãæ·»å åºåºä»»å¡ |
| | | foreach (var item in entityOrder.Details) |
| | | { |
| | | Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.MaterielCode == item.Goods_no && x.BatchNo == item.Batch_num); |
| | | 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 = _inventoryInfoService.Repository.QueryData(x => x.MaterielCode == item.Goods_no && x.BatchNo == item.Batch_num && x.StockStatus == StockStatusEmun.å
¥åºå®æ.ObjToInt() && x.StockQuantity > x.OutboundQuantity && x.WarehouseCode == item.Reservoirarea); |
| | | #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) |
| | | { |
| | | if (Order_qty <= 0) break; |
| | | if (InventoryInfo.AvailableQuantity < Order_qty) |
| | | { |
| | | InventoryInfo.AvailableQuantity = 0; |
| | | Order_qty -= InventoryInfo.AvailableQuantity; |
| | | InventoryInfo.OutboundQuantity += InventoryInfo.AvailableQuantity; |
| | | InventoryInfo.StockStatus = StockStatusEmun.åºåºéå®.ObjToInt(); |
| | | } |
| | | else |
| | | { |
| | | InventoryInfo.AvailableQuantity -= Order_qty; |
| | | Order_qty = 0; |
| | | InventoryInfo.OutboundQuantity += Order_qty; |
| | | InventoryInfo.StockStatus = StockStatusEmun.åºåºéå®.ObjToInt(); |
| | | } |
| | | } |
| | | dt_InventoryInfos = dt_InventoryInfos.Where(X => X.StockStatus == StockStatusEmun.åºåºéå®.ObjToInt()).ToList(); |
| | | List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>(); |
| | | foreach (var inventoryInfo in dt_InventoryInfos) |
| | | { |
| | | 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 = TaskTypeEnum.OutPick.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName ?? "System", |
| | | LocationCode = inventoryInfo.LocationCode, |
| | | OrderNo = entityOrder.Out_no, |
| | | StockQuantity = inventoryInfo.OutboundQuantity, |
| | | SupplyQuantity = 0, |
| | | Remark = "åºåº" |
| | | }; |
| | | supplyTasks.Add(supplyTask); |
| | | } |
| | | _inventory_BatchServices.Repository.UpdateData(inventory_Batch); |
| | | _inventoryInfoService.Repository.UpdateData(dt_InventoryInfos); |
| | | _supplyTaskService.AddData(supplyTasks); |
| | | } |
| | | #endregion |
| | | } |
| | | else |
| | | { |
| | | #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 = WarehouseEnum.大件åº.ObjToInt().ToString("000"), |
| | | 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 = WarehouseEnum.ç«åº.ObjToInt().ToString("000"), |
| | | Details = new List<Dt_DeliveryOrderDetail>() |
| | | }; |
| | | #endregion |
| | | #region æ¥æ¾åºå |
| | | foreach (var detail in outorder.details) |
| | | { |
| | | #region æ¥è¯¢åºåæ¹æ¬¡ååºå |
| | | Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.MaterielCode == detail.goods_no && x.BatchNo == detail.batch_num); |
| | | 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 = _inventoryInfoService.Repository.QueryData(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo && x.StockStatus == StockStatusEmun.å
¥åºå®æ.ObjToInt() && x.StockQuantity > x.OutboundQuantity && (x.WarehouseCode == WarehouseEnum.大件åº.ObjToInt().ToString("000") || x.WarehouseCode == WarehouseEnum.ç«åº.ObjToInt().ToString("000"))); |
| | | #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 = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == detail.goods_no); |
| | | if (materielInfo == null) throw new Exception($"æªæ¾å°è¯åç¼ç ã{detail.goods_no}ãçä¿¡æ¯"); |
| | | if (!Enum.IsDefined(typeof(MaterielSourceTypeEnum), materielInfo.MaterielSourceType)) |
| | | throw new Exception($"请设置è¯åç¼å·ã{detail.goods_no}ãç屿§åç±»"); |
| | | if (materielInfo.BoxQty < 1) 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) |
| | | { |
| | | InventoryInfo.AvailableQuantity = 0; |
| | | Order_qty -= InventoryInfo.AvailableQuantity; |
| | | InventoryInfo.OutboundQuantity += InventoryInfo.AvailableQuantity; |
| | | InventoryInfo.StockStatus = StockStatusEmun.åºåºéå®.ObjToInt(); |
| | | } |
| | | else |
| | | { |
| | | InventoryInfo.AvailableQuantity -= Order_qty; |
| | | Order_qty = 0; |
| | | InventoryInfo.OutboundQuantity += Order_qty; |
| | | InventoryInfo.StockStatus = StockStatusEmun.åºåºéå®.ObjToInt(); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region çæåºåºä»»å¡ |
| | | dt_InventoryInfos = dt_InventoryInfos.Where(X => X.StockStatus == StockStatusEmun.åºåºéå®.ObjToInt()).ToList(); |
| | | List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>(); |
| | | foreach (var inventoryInfo in dt_InventoryInfos) |
| | | { |
| | | 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 = TaskTypeEnum.OutPick.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName ?? "System", |
| | | LocationCode = inventoryInfo.LocationCode, |
| | | OrderNo = entityOrder.Out_no, |
| | | StockQuantity = inventoryInfo.OutboundQuantity, |
| | | SupplyQuantity = 0, |
| | | Remark = "åºåº" |
| | | }; |
| | | supplyTasks.Add(supplyTask); |
| | | } |
| | | #endregion |
| | | _inventory_BatchServices.Repository.UpdateData(inventory_Batch); |
| | | _inventoryInfoService.Repository.UpdateData(dt_InventoryInfos); |
| | | _supplyTaskService.AddData(supplyTasks); |
| | | } |
| | | #endregion |
| | | else |
| | | { |
| | | 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 == WarehouseEnum.大件åº.ObjToInt().ToString("000"))) |
| | | { |
| | | if (xs <= 0) break; |
| | | item.StockStatus = StockStatusEmun.åºåºéå®.ObjToInt(); |
| | | 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 = 0 |
| | | }; |
| | | item.AvailableQuantity -= materielInfo.BoxQty; |
| | | item.OutboundQuantity += materielInfo.BoxQty; |
| | | } |
| | | else |
| | | { |
| | | orderDetail.Order_qty += materielInfo.BoxQty; |
| | | item.AvailableQuantity -= materielInfo.BoxQty; |
| | | item.OutboundQuantity += materielInfo.BoxQty; |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region åé
å®å¤§ä»¶åºå¦æè¿æç®±æ°ï¼åéæ©åé
ç«åº |
| | | 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 |
| | | List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>(); |
| | | if (orderDetailLK != null) |
| | | { |
| | | #region æ·»å åºåºä»»å¡ãä¿®æ¹åºåä¿¡æ¯ |
| | | Dt_InventoryInfo inventoryInfo = dt_InventoryInfos.Where(x => x.WarehouseCode == WarehouseEnum.ç«åº.ObjToInt().ToString("000")).First(); |
| | | inventoryInfo.AvailableQuantity -= orderDetailLK.Order_qty; |
| | | inventoryInfo.OutboundQuantity += orderDetailLK.Order_qty; |
| | | inventoryInfo.StockStatus = StockStatusEmun.åºåºéå®.ObjToInt(); |
| | | _inventoryInfoService.Repository.UpdateData(inventoryInfo); |
| | | 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 = TaskTypeEnum.OutPick.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName ?? "System", |
| | | LocationCode = inventoryInfo.LocationCode, |
| | | OrderNo = entityOrder.Out_no, |
| | | StockQuantity = inventoryInfo.OutboundQuantity, |
| | | SupplyQuantity = 0, |
| | | Remark = "åºåº" |
| | | }; |
| | | supplyTasks.Add(supplyTask); |
| | | #endregion |
| | | entityOrderLK.Details.Add(orderDetailLK); |
| | | } |
| | | if (orderDetail != null) |
| | | { |
| | | #region æ·»å åºåºä»»å¡ãä¿®æ¹åºåä¿¡æ¯ |
| | | dt_InventoryInfos = dt_InventoryInfos.Where(X => X.StockStatus == StockStatusEmun.åºåºéå®.ObjToInt()).ToList(); |
| | | foreach (var inventoryInfo in dt_InventoryInfos) |
| | | { |
| | | 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 = TaskTypeEnum.OutPick.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName ?? "System", |
| | | LocationCode = inventoryInfo.LocationCode, |
| | | OrderNo = entityOrder.Out_no, |
| | | StockQuantity = inventoryInfo.OutboundQuantity, |
| | | SupplyQuantity = 0, |
| | | Remark = "åºåº" |
| | | }; |
| | | supplyTasks.Add(supplyTask); |
| | | } |
| | | #endregion |
| | | entityOrder.Details.Add(orderDetail); |
| | | } |
| | | _inventory_BatchServices.Repository.UpdateData(inventory_Batch); |
| | | _inventoryInfoService.Repository.UpdateData(dt_InventoryInfos); |
| | | _supplyTaskService.AddData(supplyTasks); |
| | | } |
| | | } |
| | | 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(); |
| | | #endregion |
| | | } |
| | | } |
| | | catch (Exception ex) |