| | |
| | | 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; |
| | |
| | | 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(); |
| | | 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 (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 |
| | | |
| | | #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); |
| | | } |
| | | if (inventoryInfo == null) return WebResponseContent.Instance.Error($"æªæ¾å°ç«åºçåºåä¿¡æ¯"); |
| | | inventoryInfo.SupplyQuantity = supplyTask.SupplyQuantity - inventoryInfo.StockQuantity; |
| | | #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 && x.TaskId != supplyTask.TaskId).ToList(); |
| | | List<Dt_SupplyTask> supplyTasks1 = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt() && x.TaskId != supplyTask.TaskId).ToList(); |
| | | Dt_Inventory_Batch inventory_Batch = new Dt_Inventory_Batch(); |
| | | List<Dt_InventoryInfo> inventoryInfos = new List<Dt_InventoryInfo>(); |
| | | if (supplyTasks1.Count < 1) |
| | | 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 æ¥æ¾åºå |
| | | inventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.Id != inventoryInfo.Id); |
| | | var SupplyQuantitys = inventoryInfos.Sum(x => x.SupplyQuantity) + inventoryInfo.SupplyQuantity;//计ç®çç¹æ»æ° |
| | | #endregion |
| | | |
| | | #region åºåæ¹æ¬¡ |
| | | inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no); |
| | | |
| | | #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) |
| | | 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; |
| | | inventoryInfo.SupplyQuantity = 0; |
| | | inventoryInfo.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 å¤çå
¶ä»åºåæ¹æ¬¡ååºå |
| | | 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 |
| | | { |
| | |
| | | } |
| | | #endregion |
| | | } |
| | | #endregion |
| | | } |
| | | #endregion |
| | | _unitOfWorkManage.BeginTran(); |
| | | #region å¤ççç¹å |
| | | if (supplyTasks.Count < 1) |
| | |
| | | _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail); |
| | | } |
| | | #endregion |
| | | _inventoryInfoService.UpdateData(inventoryInfo); |
| | | //_inventoryInfoService.UpdateData(inventoryInfo); |
| | | _supplyTaskService.Repository.DeleteAndMoveIntoHty(supplyTask, OperateTypeEnum.èªå¨å®æ); |
| | | _inventoryInfoService.UpdateData(inventoryInfos); |
| | | _inventory_BatchServices.UpdateData(inventory_Batch); |
| | | if (inventoryInfosDel.Count > 0) _inventoryInfoService.DeleteData(inventoryInfosDel); |
| | | _inventory_BatchServices.UpdateData(inventory_Batchs); |
| | | _unitOfWorkManage.CommitTran(); |
| | | #endregion |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |