| | |
| | | using System; |
| | | using SqlSugar.Extensions; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Drawing.Drawing2D; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common; |
| | | 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; |
| | |
| | | public class Inventory_BatchServices : ServiceBase<Dt_Inventory_Batch, IRepository<Dt_Inventory_Batch>>, IInventory_BatchServices |
| | | { |
| | | private IMessageInfoService _messageInfoService; |
| | | public Inventory_BatchServices(IRepository<Dt_Inventory_Batch> BaseDal, IMessageInfoService messageInfoService) : base(BaseDal) |
| | | private IMaterielInfoService _materielInfoService; |
| | | private IInventoryInfoService _inventoryInfoService; |
| | | private ISupplyTaskService _supplyTaskService; |
| | | public Inventory_BatchServices(IRepository<Dt_Inventory_Batch> BaseDal, IMessageInfoService messageInfoService, IMaterielInfoService materielInfoService, IInventoryInfoService inventoryInfoService, ISupplyTaskService supplyTaskService) : base(BaseDal) |
| | | { |
| | | _messageInfoService = messageInfoService; |
| | | _materielInfoService = materielInfoService; |
| | | _inventoryInfoService = inventoryInfoService; |
| | | _supplyTaskService = supplyTaskService; |
| | | } |
| | | |
| | | public IRepository<Dt_Inventory_Batch> Repository => BaseDal; |
| | | public override WebResponseContent UpdateData(SaveModel saveModel) |
| | | { |
| | | return base.UpdateData(saveModel); |
| | | try |
| | | { |
| | | string WareCode = WarehouseEnum.大件åº.ObjToInt().ToString("000"); |
| | | var qty = saveModel.MainData["availableQuantity"].ObjToInt(); |
| | | var id = saveModel.MainData["id"].ObjToInt(); |
| | | var materielCode = saveModel.MainData["materielCode"].ToString(); |
| | | var batchNo = saveModel.MainData["batchNo"].ToString(); |
| | | //var Inventory_Batch = BaseDal.QueryFirst(x => x.Id == id); |
| | | //if (qty > Inventory_Batch.AvailableQuantity) throw new Exception("è°æ¨æ°éä¸å¯å¤§äºå¯ç¨æ°é"); |
| | | var materielInfo = _materielInfoService.Repository.QueryFirst(x => x.MaterielCode == materielCode); |
| | | if (materielInfo == null) return WebResponseContent.Instance.Error($"请维æ¤è¯åç¼å·ã{materielCode}ãçä¿¡æ¯"); |
| | | if (!Enum.IsDefined(typeof(MaterielSourceTypeEnum), materielInfo.MaterielSourceType)) |
| | | return WebResponseContent.Instance.Error($"请设置è¯åç¼å·ã{materielCode}ãç屿§åç±»"); |
| | | if (materielInfo.MaterielSourceType == MaterielSourceTypeEnum.PurchasePart) |
| | | return WebResponseContent.Instance.Error($"è¯åç¼å·ã{materielCode}ãç屿§å类为大件,ä¸å¯è°æ¨"); |
| | | List<Dt_InventoryInfo> dt_InventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.MaterielCode == materielInfo.MaterielCode && x.BatchNo == batchNo && x.StockStatus == StockStatusEmun.å
¥åºå®æ.ObjToInt() && x.AvailableQuantity > 0 && x.WarehouseCode == WareCode).OrderBy(x => x.InDate).ToList(); |
| | | if (dt_InventoryInfos.Count < 1) return WebResponseContent.Instance.Error($"ç©æç¼å·ã{materielInfo.MaterielCode}ãå¤§ä»¶åºæ åºåï¼è¯·åæ¶è¡¥å
åºåï¼"); |
| | | var StockQty = dt_InventoryInfos.Sum(x => x.AvailableQuantity); |
| | | if (StockQty < qty) return WebResponseContent.Instance.Error($"è°æ¨æ°éä¸å¯å¤§äºå¤§ä»¶åºå¯ç¨æ°é,大件åºå¯ç¨æ°é为ã{StockQty}ã"); |
| | | var zx = (qty / materielInfo.BoxQty).ObjToInt(); |
| | | var ys = qty % materielInfo.BoxQty; |
| | | if (ys > 0) zx++; |
| | | decimal Qty = 0; |
| | | List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>(); |
| | | Dt_DeliveryOrder deliveryOrder = new Dt_DeliveryOrder() |
| | | { |
| | | Out_no = DateTime.Now.ToString("yyMMddHHmmss"), |
| | | Warehouse_no = WareCode, |
| | | Out_type = OutOrderTypeEnum.Allocate.ObjToInt().ToString(), |
| | | OutStatus = "æ°å»º", |
| | | Details = new List<Dt_DeliveryOrderDetail>() |
| | | }; |
| | | foreach (var item in dt_InventoryInfos) |
| | | { |
| | | decimal taskQty = 0; |
| | | if (zx < 1) break; |
| | | while (item.AvailableQuantity > 0 && zx > 0) |
| | | { |
| | | zx--; |
| | | Qty += materielInfo.BoxQty; |
| | | taskQty += materielInfo.BoxQty; |
| | | materielInfo.Business_qty += materielInfo.BoxQty; |
| | | item.OutboundQuantity += materielInfo.BoxQty; |
| | | item.AvailableQuantity -= materielInfo.BoxQty; |
| | | } |
| | | #region æ·»å è°æ¨åºåºä»»å¡ |
| | | 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 = TaskTypeEnum.AllocatOut.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName ?? "System", |
| | | LocationCode = item.LocationCode, |
| | | OrderNo = deliveryOrder.Out_no, |
| | | StockQuantity = taskQty, |
| | | SupplyQuantity = 0, |
| | | Remark = "è°æ¨åºåº" |
| | | }; |
| | | supplyTasks.Add(supplyTask); |
| | | #endregion |
| | | } |
| | | Dt_DeliveryOrderDetail deliveryOrderDetail = new Dt_DeliveryOrderDetail() |
| | | { |
| | | Batch_num = batchNo, |
| | | Order_Outqty = 0, |
| | | Order_qty = Qty, |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserName ?? "System", |
| | | Goods_no = materielCode, |
| | | OotDetailStatus = "æ°å»º", |
| | | Status = 2, |
| | | Reservoirarea = WareCode |
| | | }; |
| | | deliveryOrder.Details.Add(deliveryOrderDetail); |
| | | #region æ·»å è°æ¨å
¥åºå |
| | | Dt_CabinOrder cabinOrder = new Dt_CabinOrder() |
| | | { |
| | | Order_no = deliveryOrder.Out_no, |
| | | Order_type = InOrderTypeEnum.Allocat.ObjToInt().ToString(), |
| | | Warehouse_no = "001", |
| | | OdrderStatus = "æ°å»º", |
| | | Details = new List<Dt_CabinOrderDetail>() |
| | | }; |
| | | foreach (var item in deliveryOrder.Details) |
| | | { |
| | | Dt_CabinOrderDetail orderDetail = new Dt_CabinOrderDetail() |
| | | { |
| | | Reservoirarea = cabinOrder.Warehouse_no, |
| | | Goods_no = item.Goods_no, |
| | | Order_qty = item.Order_qty, |
| | | Batch_num = item.Batch_num, |
| | | OrderDetailStatus = "æ°å»º", |
| | | Status = 0 |
| | | }; |
| | | cabinOrder.Details.Add(orderDetail); |
| | | } |
| | | #endregion |
| | | Db.Ado.BeginTran(); |
| | | _materielInfoService.UpdateData(materielInfo); |
| | | _inventoryInfoService.Repository.UpdateData(dt_InventoryInfos); |
| | | _supplyTaskService.AddData(supplyTasks); |
| | | if (deliveryOrder.Details.Count > 0) Db.InsertNav(deliveryOrder).Include(x => x.Details).ExecuteCommand(); |
| | | if (cabinOrder.Details.Count > 0) Db.InsertNav(cabinOrder).Include(x => x.Details).ExecuteCommand(); |
| | | Db.Ado.CommitTran(); |
| | | return WebResponseContent.Instance.OK("è°æ¨åºå
¥åºåçææå,请æä½è°æ¨å"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | public WebResponseContent GetExpiredAndlow() |
| | | { |