| | |
| | | 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; |
| | |
| | | List<Dt_Inventory_Batch> inventory_Batches = _inventory_BatchServices.Repository.QueryData(x => keys.Contains(x.Id)); |
| | | foreach (var item in inventory_Batches) |
| | | { |
| | | var supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList(); |
| | | var supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList(); |
| | | if (item.SupplyQuantity != 0) throw new Exception($"ç©æç¼å·ã{item.MaterielCode}ãæ¹æ¬¡å·ã{item.BatchNo}ãå·²åå¨çç¹å·®å¼!"); |
| | | if (supplyTasks.Count > 0) throw new Exception($"ç©æç¼å·ã{item.MaterielCode}ãæ¹æ¬¡å·ã{item.BatchNo}ãå·²åå¨çç¹ä»»å¡ï¼è¯·å
宿å½åçç¹ä»»å¡"); |
| | | supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewOut.ObjToInt()).ToList(); |
| | | if (supplyTasks.Count > 0) throw new Exception($"ç©æç¼å·ã{item.MaterielCode}ãæ¹æ¬¡å·ã{item.BatchNo}ãå·²åå¨çç¹ä»»å¡ï¼è¯·å
宿å½åçç¹ä»»å¡"); |
| | | if (supplyTasks.Count > 0) throw new Exception($"ç©æç¼å·ã{item.MaterielCode}ãæ¹æ¬¡å·ã{item.BatchNo}ãå·²åå¨åºåºä»»å¡ï¼è¯·å
宿å½ååºåºä»»å¡"); |
| | | List<Dt_InventoryInfo> inventoryInfos = _inventoryInfoService.Repository.QueryData(x => item.MaterielCode == x.MaterielCode && x.BatchNo == item.BatchNo); |
| | | if (inventoryInfos.Count > 0) |
| | | { |
| | | foreach (var items in inventoryInfos.GroupBy(x => x.WarehouseCode)) |
| | | { |
| | | Dt_DeliveryOrder deliveryOrder = new Dt_DeliveryOrder() |
| | | Dt_DeliveryOrder? deliveryOrder = deliveryOrders.Where(x => x.Warehouse_no == items.Key).FirstOrDefault(); |
| | | bool isNull = false; |
| | | if (deliveryOrder == null) |
| | | { |
| | | Out_no = item.MaterielCode + "_" + item.BatchNo, |
| | | Out_type = "20", |
| | | OutStatus = "æ°å»º", |
| | | Warehouse_no = items.Key, |
| | | Details = new List<Dt_DeliveryOrderDetail>() |
| | | }; |
| | | isNull = true; |
| | | deliveryOrder = new Dt_DeliveryOrder() |
| | | { |
| | | //Out_no = item.MaterielCode + "_" + item.BatchNo, |
| | | Out_no = $"PD{items.Key}{DateTime.Now.ToString("yyMMddHHmmss")}", |
| | | Out_type = "20", |
| | | OutStatus = "æ°å»º", |
| | | Warehouse_no = items.Key, |
| | | Details = new List<Dt_DeliveryOrderDetail>() |
| | | }; |
| | | } |
| | | var Status = items.Key == "001" ? 0 : 2;//夿æ¯å¦ä¸ºç«åºåºå |
| | | Dt_DeliveryOrderDetail deliveryOrderDetail = new Dt_DeliveryOrderDetail() |
| | | { |
| | |
| | | Reservoirarea = items.Key |
| | | }; |
| | | deliveryOrder.Details.Add(deliveryOrderDetail); |
| | | deliveryOrders.Add(deliveryOrder); |
| | | if (isNull) deliveryOrders.Add(deliveryOrder); |
| | | #region å建çç¹ä»»å¡ |
| | | foreach (var inventory in items) |
| | | { |
| | |
| | | if (materielInfo == null) return WebResponseContent.Instance.Error($"请维æ¤ç©æç¼å·ã{cabinOrderDetail.Goods_no}ãçç©æä¿¡æ¯"); |
| | | cabinOrderDetail.Order_Outqty += supplyTask.SupplyQuantity; |
| | | #region å¹³åºçç¹åªè½åºç°æ´ç®±å·®å¼ |
| | | if (supplyTask.WarehouseCode == WarehouseEnum.大件åº.ObjToInt().ToString("000")) |
| | | if (supplyTask.WarehouseCode == WarehouseEnum.大件åº.ObjToInt().ToString("000") && materielInfo.MaterielSourceType != MaterielSourceTypeEnum.PurchasePart) |
| | | { |
| | | var Qty = supplyTask.SupplyQuantity % materielInfo.BoxQty; |
| | | if (Qty != 0) return WebResponseContent.Instance.Error($"大件åºåºå为æ´ç®±ï¼çç¹æ°éä¸è½å卿£ä»¶"); |
| | | } |
| | | #endregion |
| | | //if (cabinOrderDetail.Order_Outqty > cabinOrderDetail.Order_qty) |
| | | // return WebResponseContent.Instance.Error($"å®çæ°éä¸å¯è¶
åºè´¦é¢æ°é"); |
| | | |
| | | #region å¤çåºåºåï¼è´§ä½ï¼åºåï¼åºåæ¹æ¬¡ä¿¡æ¯ |
| | | _unitOfWorkManage.BeginTran(); |
| | | |
| | | #region ä¿®æ¹çç¹å |
| | | cabinOrder.OutStatus = "å¼å§"; |
| | | cabinOrderDetail.OotDetailStatus = "å¼å§"; |
| | | Repository.UpdateData(cabinOrder); |
| | | _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail); |
| | | #endregion |
| | | |
| | | #region åºå |
| | | Dt_InventoryInfo inventoryInfo = new Dt_InventoryInfo(); |
| | | List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => cabinOrder.Details.Select(x => x.Goods_no).Contains(x.MaterielCode)); |
| | | List<Dt_InventoryInfo> inventoryInfos = _inventoryInfoService.Repository.QueryData(x => cabinOrder.Details.Select(x => x.Goods_no).Contains(x.MaterielCode) && x.WarehouseCode == supplyTask.WarehouseCode && x.StockStatus == StockStatusEmun.çç¹éå®.ObjToInt()); |
| | | Dt_InventoryInfo? inventoryInfo = new(); |
| | | List<Dt_InventoryInfo> inventoryInfosDel = new List<Dt_InventoryInfo>(); |
| | | if (supplyTask.WarehouseCode != WarehouseEnum.ç«åº.ObjToInt().ToString("000")) |
| | | { |
| | | inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.WarehouseCode == supplyTask.WarehouseCode && x.LocationCode == supplyTask.LocationCode); |
| | | inventoryInfo = inventoryInfos.FirstOrDefault(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.LocationCode == supplyTask.LocationCode); |
| | | if (inventoryInfo == null) return WebResponseContent.Instance.Error($"æªæ¾å°è´§ä½ã{LocationCode}ãçåºåä¿¡æ¯"); |
| | | } |
| | | else |
| | | { |
| | | inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.WarehouseCode == supplyTask.WarehouseCode); |
| | | inventoryInfo = inventoryInfos.FirstOrDefault(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no); |
| | | } |
| | | inventoryInfo.SupplyQuantity = supplyTask.SupplyQuantity; |
| | | _inventoryInfoService.UpdateData(inventoryInfo); |
| | | if (inventoryInfo == null) return WebResponseContent.Instance.Error($"æªæ¾å°ç«åºçåºåä¿¡æ¯"); |
| | | inventoryInfo.SupplyQuantity = supplyTask.SupplyQuantity - inventoryInfo.StockQuantity; |
| | | #endregion |
| | | |
| | | #region ä»»å¡è®°å½ |
| | | //_supplyTaskService.UpdateData(supplyTask); |
| | | _supplyTaskService.Repository.DeleteAndMoveIntoHty(supplyTask, OperateTypeEnum.èªå¨å®æ); |
| | | #endregion |
| | | List<Dt_SupplyTask> supplyTasks = _supplyTaskService.Repository.QueryData(x => x.OrderNo == supplyTask.OrderNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt() && x.TaskId != supplyTask.TaskId).ToList();//æ¥æ¾å½åçç¹åççç¹ä»»å¡ |
| | | if (!supplyTasks.Where(x => cabinOrderDetail.Goods_no == x.MaterielCode && x.BatchNo == cabinOrderDetail.Batch_num).Any()) |
| | | cabinOrderDetail.OotDetailStatus = "已宿"; |
| | | #region 夿å½åçç¹å任塿¯å¦å
¨é¨å®æ |
| | | if (supplyTasks.Count < 1) |
| | | { |
| | | #region å¤çå½åç©ææ¹æ¬¡çåºååæ¹æ¬¡ä¿¡æ¯ |
| | | Dt_Inventory_Batch inventory_Batch = inventory_Batchs.First(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode); |
| | | var SupplyQuantitys = inventoryInfos.Where(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode).Sum(x => x.SupplyQuantity); |
| | | if (SupplyQuantitys == 0) |
| | | { |
| | | foreach (var item in inventoryInfos.Where(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode)) |
| | | { |
| | | item.StockQuantity += item.SupplyQuantity; |
| | | if (item.StockQuantity <= 0) |
| | | { |
| | | inventoryInfosDel.Add(item); |
| | | continue; |
| | | } |
| | | item.AvailableQuantity = item.StockQuantity; |
| | | item.SupplyQuantity = 0; |
| | | item.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | } |
| | | //inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity; |
| | | //if (inventoryInfo.StockQuantity <= 0) |
| | | //{ |
| | | // inventoryInfosDel.Add(inventoryInfo); |
| | | // inventoryInfo = null; |
| | | //} |
| | | //else |
| | | //{ |
| | | // inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity; |
| | | // inventoryInfo.SupplyQuantity = 0; |
| | | // inventoryInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | //} |
| | | } |
| | | else |
| | | { |
| | | inventory_Batch.SupplyQuantity += SupplyQuantitys; |
| | | } |
| | | #endregion |
| | | |
| | | #region 夿å½åç©ææ¹æ¬¡ççç¹ä»»å¡æ¯å¦å
¨é¨å®æ |
| | | List<Dt_SupplyTask> supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt() && x.WarehouseCode == supplyTask.WarehouseCode).ToList(); |
| | | #region å¤çå
¶ä»åºåæ¹æ¬¡ååºå |
| | | foreach (var detail in cabinOrder.Details.Where(x => x.Id != cabinOrderDetail.Id)) |
| | | { |
| | | SupplyQuantitys = inventoryInfos.Where(x => x.BatchNo == detail.Batch_num && x.MaterielCode == detail.Goods_no).Sum(x => x.SupplyQuantity);//计ç®çç¹æ»æ° |
| | | inventory_Batch = inventory_Batchs.First(x => x.BatchNo == detail.Batch_num && x.MaterielCode == detail.Goods_no); |
| | | #region åºåæ¹æ¬¡ |
| | | if (SupplyQuantitys == 0) |
| | | { |
| | | foreach (var item in inventoryInfos.Where(x => x.BatchNo == detail.Batch_num && x.MaterielCode == detail.Goods_no)) |
| | | { |
| | | item.StockQuantity += item.SupplyQuantity; |
| | | if (item.StockQuantity <= 0) |
| | | { |
| | | inventoryInfosDel.Add(item); |
| | | continue; |
| | | } |
| | | item.AvailableQuantity = item.StockQuantity; |
| | | item.SupplyQuantity = 0; |
| | | item.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | inventory_Batch.SupplyQuantity += SupplyQuantitys; |
| | | } |
| | | #endregion |
| | | } |
| | | #endregion |
| | | } |
| | | #endregion |
| | | _unitOfWorkManage.BeginTran(); |
| | | #region å¤ççç¹å |
| | | if (supplyTasks.Count < 1) |
| | | { |
| | | #region 宿çç¹å |
| | |
| | | }); |
| | | _deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrder.Details, OperateTypeEnum.èªå¨å®æ); |
| | | cabinOrder.Details = null; |
| | | Repository.DeleteAndMoveIntoHty(cabinOrder, OperateTypeEnum.èªå¨å®æ); |
| | | BaseDal.DeleteAndMoveIntoHty(cabinOrder, OperateTypeEnum.èªå¨å®æ); |
| | | |
| | | #endregion |
| | | } |
| | | supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList(); |
| | | if (supplyTasks.Count < 1) |
| | | else |
| | | { |
| | | #region æ¥æ¾åºå |
| | | var inventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no); |
| | | var SupplyQuantitys = inventoryInfos.Sum(x => x.SupplyQuantity); |
| | | #endregion |
| | | |
| | | #region åºåæ¹æ¬¡ |
| | | Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no); |
| | | //妿çç¹æ°åæ¹æ¬¡æ»æ°å¯¹ä¸äºï¼çç¹æ°èµå¼ä¸º0ï¼èµå¼å°±æ·»å çç¹æ° |
| | | if (SupplyQuantitys == inventory_Batch.StockQuantity) |
| | | { |
| | | foreach (var item in inventoryInfos) |
| | | { |
| | | item.StockQuantity = item.SupplyQuantity; |
| | | item.SupplyQuantity = 0; |
| | | item.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | } |
| | | _inventoryInfoService.UpdateData(inventoryInfos); |
| | | } |
| | | else |
| | | { |
| | | inventory_Batch.SupplyQuantity = SupplyQuantitys; |
| | | _inventory_BatchServices.UpdateData(inventory_Batch); |
| | | } |
| | | #endregion |
| | | BaseDal.UpdateData(cabinOrder); |
| | | _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail); |
| | | } |
| | | |
| | | #endregion |
| | | //_inventoryInfoService.UpdateData(inventoryInfo); |
| | | _supplyTaskService.Repository.DeleteAndMoveIntoHty(supplyTask, OperateTypeEnum.èªå¨å®æ); |
| | | _inventoryInfoService.UpdateData(inventoryInfos); |
| | | if (inventoryInfosDel.Count > 0) _inventoryInfoService.DeleteData(inventoryInfosDel); |
| | | _inventory_BatchServices.UpdateData(inventory_Batchs); |
| | | _unitOfWorkManage.CommitTran(); |
| | | #endregion |
| | | content.OK(); |
| | | #endregion |
| | | } |
| | | catch (Exception ex) |
| | | { |