| | |
| | | using AutoMapper; |
| | | using Magicodes.ExporterAndImporter.Core; |
| | | using Magicodes.ExporterAndImporter.Excel; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; |
| | | using SqlSugar; |
| | | using System; |
| | |
| | | using WIDESEA_IStockRepository; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | | using static WIDESEA_IStockService.IStockInfoService; |
| | | |
| | | namespace WIDESEA_StockService |
| | | { |
| | |
| | | |
| | | return BaseDal.GetStockInfos(materielCode, locationCodes); |
| | | } |
| | | |
| | | //public List<Dt_StockInfo> GetUseableStocks(string materielCode, string batchNo, int warehoseId) |
| | | //{ |
| | | // List<string> locationCodes = _basicRepository.LocationInfoRepository.GetCanOutLocationCodes(warehoseId); |
| | | |
| | | // return BaseDal.GetStockInfos(materielCode, batchNo, locationCodes); |
| | | //} |
| | | |
| | | public List<StockSelectViewDTO> GetStockSelectViews(string materielCode) |
| | | { |
| | |
| | | return outStocks; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 低温、药水分配库存 |
| | | /// </summary> |
| | | /// <param name="stockInfos"></param> |
| | | /// <param name="dt_OutboundOrderDetails"></param> |
| | | /// <param name="residueQuantitys"></param> |
| | | /// <returns></returns> |
| | | public List<Dt_StockInfo> DWANDYSGetOutboundStocks(List<Dt_StockInfo> stockInfos,List<Dt_OutboundOrderDetail> dt_OutboundOrderDetails, out List<IStockInfoService.residueQuantity> residueQuantitys) |
| | | { |
| | | List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); |
| | | List<IStockInfoService.residueQuantity> newresidueQantity = new List<IStockInfoService.residueQuantity>(); |
| | | List<Dt_StockInfo> notStocks = new List<Dt_StockInfo>(); ; |
| | | foreach(var dt_OutboundOrderDetail in dt_OutboundOrderDetails) |
| | | { |
| | | notStocks = stockInfos.Where(x => x.Details.Any(x => x.BatchNo == dt_OutboundOrderDetail.BatchNo && x.MaterielCode == dt_OutboundOrderDetail.MaterielCode)).OrderBy(x => x.Id).ToList(); |
| | | if(notStocks.Count > 0) |
| | | { |
| | | decimal stockTotalQuantity = stockInfos.SelectMany(x => x.Details).Where(d => d.BatchNo == dt_OutboundOrderDetail.BatchNo).Sum(v => v.StockQuantity - v.OutboundQuantity); |
| | | decimal needQuantity = dt_OutboundOrderDetail.OrderQuantity - dt_OutboundOrderDetail.LockQuantity; |
| | | if (stockTotalQuantity >= needQuantity)//库存够 |
| | | { |
| | | int index = 0; |
| | | while (needQuantity > 0) |
| | | { |
| | | |
| | | Dt_StockInfo stockInfo = stockInfos[index]; |
| | | Dt_StockInfoDetail dt_StockInfoDetail = new Dt_StockInfoDetail(); |
| | | foreach (var detail in stockInfo.Details) |
| | | { |
| | | if (detail.BatchNo == dt_OutboundOrderDetail.BatchNo && detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode) |
| | | { |
| | | dt_StockInfoDetail = detail; |
| | | } |
| | | } |
| | | decimal useableStockQuantity = dt_StockInfoDetail.StockQuantity - dt_StockInfoDetail.OutboundQuantity; |
| | | if (useableStockQuantity < needQuantity) |
| | | { |
| | | stockInfo.Details.ForEach(x => |
| | | { |
| | | if (x.MaterielCode == dt_OutboundOrderDetail.MaterielCode && x.BatchNo == dt_OutboundOrderDetail.BatchNo) |
| | | { |
| | | x.OutboundQuantity = x.StockQuantity; |
| | | } |
| | | }); |
| | | needQuantity -= useableStockQuantity; |
| | | } |
| | | else |
| | | { |
| | | |
| | | stockInfo.Details.ForEach(x => |
| | | { |
| | | if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == dt_OutboundOrderDetail.MaterielCode && x.BatchNo == dt_OutboundOrderDetail.BatchNo) |
| | | { |
| | | if (x.StockQuantity - x.OutboundQuantity >= needQuantity) |
| | | { |
| | | x.OutboundQuantity += needQuantity; |
| | | needQuantity = 0; |
| | | } |
| | | else |
| | | { |
| | | needQuantity -= (x.StockQuantity - x.OutboundQuantity); |
| | | x.OutboundQuantity = x.StockQuantity; |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | outStocks.Add(stockInfo); |
| | | index++; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | for (int i = 0; i < stockInfos.Count; i++) |
| | | { |
| | | Dt_StockInfo stockInfo = stockInfos[i]; |
| | | decimal useableStockQuantity = 0; |
| | | foreach (var detail in stockInfo.Details) |
| | | { |
| | | if (detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode && detail.BatchNo == dt_OutboundOrderDetail.BatchNo) |
| | | { |
| | | useableStockQuantity = detail.StockQuantity - detail.OutboundQuantity; |
| | | } |
| | | } |
| | | |
| | | if (useableStockQuantity < needQuantity) |
| | | { |
| | | stockInfo.Details.ForEach(x => { |
| | | if (x.MaterielCode == dt_OutboundOrderDetail.MaterielCode && x.BatchNo == dt_OutboundOrderDetail.BatchNo) |
| | | { |
| | | x.OutboundQuantity = x.StockQuantity; |
| | | } |
| | | }); |
| | | needQuantity -= useableStockQuantity; |
| | | } |
| | | else |
| | | { |
| | | stockInfo.Details.ForEach(x => |
| | | { |
| | | if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == dt_OutboundOrderDetail.MaterielCode && x.BatchNo == dt_OutboundOrderDetail.BatchNo) |
| | | { |
| | | if (x.StockQuantity - x.OutboundQuantity >= needQuantity) |
| | | { |
| | | x.OutboundQuantity += needQuantity; |
| | | needQuantity = 0; |
| | | } |
| | | else |
| | | { |
| | | needQuantity -= (x.StockQuantity - x.OutboundQuantity); |
| | | x.OutboundQuantity = x.StockQuantity; |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | outStocks.Add(stockInfo); |
| | | } |
| | | } |
| | | IStockInfoService.residueQuantity newResidueQuantity = new IStockInfoService.residueQuantity(); |
| | | newResidueQuantity.MaterielCode = dt_OutboundOrderDetail.MaterielCode; |
| | | newResidueQuantity.BatchNo = dt_OutboundOrderDetail.BatchNo; |
| | | newResidueQuantity.NewNeendQuantity = needQuantity; |
| | | newresidueQantity.Add(newResidueQuantity); |
| | | } |
| | | else |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | } |
| | | residueQuantitys = newresidueQantity; |
| | | if(outStocks.Count() > 1) |
| | | { |
| | | outStocks.RemoveRange(0, outStocks.Count - 1); |
| | | } |
| | | return outStocks; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 成品分配库存 |
| | | /// </summary> |
| | | /// <param name="stockInfos"></param> |
| | | /// <param name="dt_OutboundOrderDetails"></param> |
| | | /// <param name="residueQuantitys"></param> |
| | | /// <returns></returns> |
| | | public List<Dt_StockInfo> CPGetOutboundStocks(List<Dt_StockInfo> stockInfos, List<Dt_NewOutboundOrderDetail> dt_OutboundOrderDetails, out List<IStockInfoService.residueQuantity> residueQuantitys) |
| | | { |
| | | List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); |
| | | List<IStockInfoService.residueQuantity> newresidueQantity = new List<IStockInfoService.residueQuantity>(); |
| | | List<Dt_StockInfo> notStocks = new List<Dt_StockInfo>(); |
| | | |
| | | foreach (var dt_OutboundOrderDetail in dt_OutboundOrderDetails) |
| | | { |
| | | notStocks = stockInfos.Where(x => x.Details.Any(x =>x.MaterielCode == dt_OutboundOrderDetail.MaterielCode)).OrderBy(x => x.Id).ToList(); |
| | | |
| | | if (notStocks.Count > 0) |
| | | { |
| | | decimal stockTotalQuantity = stockInfos.SelectMany(x => x.Details).Where(d => d.MaterielCode == dt_OutboundOrderDetail.MaterielCode).Sum(v => v.StockQuantity - v.OutboundQuantity); |
| | | decimal needQuantity = dt_OutboundOrderDetail.OrderQuantity - dt_OutboundOrderDetail.LockQuantity; |
| | | if (stockTotalQuantity >= needQuantity)//库存够 |
| | | { |
| | | int index = 0; |
| | | while (needQuantity > 0) |
| | | { |
| | | |
| | | Dt_StockInfo stockInfo = stockInfos[index]; |
| | | List<Dt_StockInfoDetail> dt_StockInfoDetails = new List<Dt_StockInfoDetail>(); |
| | | foreach (var detail in stockInfo.Details) |
| | | { |
| | | if (detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode) |
| | | { |
| | | dt_StockInfoDetails.Add(detail); |
| | | } |
| | | } |
| | | foreach(var dt_StockInfoDetail in dt_StockInfoDetails) |
| | | { |
| | | decimal useableStockQuantity = dt_StockInfoDetail.StockQuantity - dt_StockInfoDetail.OutboundQuantity; |
| | | if (useableStockQuantity < needQuantity) |
| | | { |
| | | foreach (var item in stockInfo.Details) |
| | | { |
| | | if(item.MaterielCode == dt_OutboundOrderDetail.MaterielCode && dt_StockInfoDetail.BatchNo == item.BatchNo) |
| | | { |
| | | item.OutboundQuantity = item.StockQuantity; |
| | | } |
| | | } |
| | | needQuantity -= useableStockQuantity; |
| | | } |
| | | else |
| | | { |
| | | foreach (var item in stockInfo.Details) |
| | | { |
| | | if(item.StockQuantity > item.OutboundQuantity && item.MaterielCode == dt_StockInfoDetail.MaterielCode && item.BatchNo == dt_StockInfoDetail.BatchNo) |
| | | { |
| | | if (item.StockQuantity - item.OutboundQuantity >= needQuantity) |
| | | { |
| | | dt_StockInfoDetail.OutboundQuantity += needQuantity; |
| | | needQuantity = 0; |
| | | } |
| | | else |
| | | { |
| | | needQuantity -= (item.StockQuantity - item.OutboundQuantity); |
| | | item.OutboundQuantity = item.StockQuantity; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | outStocks.Add(stockInfo); |
| | | index++; |
| | | if (needQuantity == 0) break; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | for (int i = 0; i < stockInfos.Count; i++) |
| | | { |
| | | Dt_StockInfo stockInfo = stockInfos[i]; |
| | | decimal useableStockQuantity = 0; |
| | | foreach (var detail in stockInfo.Details) |
| | | { |
| | | if (detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode) |
| | | { |
| | | useableStockQuantity += detail.StockQuantity - detail.OutboundQuantity; |
| | | } |
| | | } |
| | | |
| | | if (useableStockQuantity < needQuantity) |
| | | { |
| | | stockInfo.Details.ForEach(x => { |
| | | if (x.MaterielCode == dt_OutboundOrderDetail.MaterielCode) |
| | | { |
| | | x.OutboundQuantity = x.StockQuantity; |
| | | } |
| | | }); |
| | | needQuantity -= useableStockQuantity; |
| | | } |
| | | else |
| | | { |
| | | foreach (var detail in stockInfo.Details) |
| | | { |
| | | if(detail.StockQuantity > detail.OutboundQuantity && detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode) |
| | | { |
| | | if(detail.StockQuantity - detail.OutboundQuantity >= needQuantity) |
| | | { |
| | | detail.OutboundQuantity += needQuantity; |
| | | needQuantity = 0; |
| | | } |
| | | else |
| | | { |
| | | needQuantity -= (detail.StockQuantity - detail.OutboundQuantity); |
| | | detail.OutboundQuantity = detail.StockQuantity; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | outStocks.Add(stockInfo); |
| | | } |
| | | } |
| | | IStockInfoService.residueQuantity newResidueQuantity = new IStockInfoService.residueQuantity(); |
| | | newResidueQuantity.MaterielCode = dt_OutboundOrderDetail.MaterielCode; |
| | | newResidueQuantity.BatchNo = dt_OutboundOrderDetail.BatchNo; |
| | | newResidueQuantity.NewNeendQuantity = needQuantity; |
| | | newresidueQantity.Add(newResidueQuantity); |
| | | } |
| | | else |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | } |
| | | residueQuantitys = newresidueQantity; |
| | | if (outStocks.Count() > 1) |
| | | { |
| | | outStocks.RemoveRange(0, outStocks.Count - 1); |
| | | } |
| | | return outStocks; |
| | | } |
| | | //导出 |
| | | public override WebResponseContent Export(PageDataOptions options) |
| | | { |
| | |
| | | List<Dt_StockInfodt> stolist= new List<Dt_StockInfodt>(); |
| | | for (int i = 0; i < entities.Count; i++) |
| | | { |
| | | Dt_StockInfoDetail dt_StockIndet = detdata.Where(x => x.StockId == entities[i].Id).FirstOrDefault(); |
| | | List<Dt_StockInfoDetail> dt_StockIndet = detdata.Where(x => x.StockId == entities[i].Id).ToList(); |
| | | string MaterialTypet = "原材料"; |
| | | if (entities[i].MaterialType == (int)InventoryMaterialType.成品) |
| | | { |
| | | MaterialTypet = "成品"; |
| | | } |
| | | else if(entities[i].MaterialType == (int)InventoryMaterialType.空托) |
| | | else if (entities[i].MaterialType == (int)InventoryMaterialType.空托) |
| | | { |
| | | MaterialTypet = "空托"; |
| | | } |
| | | |
| | | string Wlstatust = "待检"; |
| | | if (entities[i].Wlstatus== (int)InventoryMaterialStatus.合格) |
| | | if (entities[i].Wlstatus == (int)InventoryMaterialStatus.合格) |
| | | { |
| | | Wlstatust = "合格"; |
| | | } |
| | |
| | | MaterialType = MaterialTypet, |
| | | LocationCode = entities[i].LocationCode, |
| | | Wlstatus = Wlstatust, |
| | | MaterielCode = dt_StockIndet?.MaterielCode ?? "", // 如果 dt_StockIndet 为 null,使用空字符串作为默认值 |
| | | MaterielName = dt_StockIndet?.MaterielName ?? "", |
| | | OrderNo = dt_StockIndet?.OrderNo ?? "", |
| | | BatchNo = dt_StockIndet?.BatchNo ?? "", |
| | | SerialNumber = dt_StockIndet?.SerialNumber ?? "", |
| | | StockQuantity = dt_StockIndet?.StockQuantity ?? 0, // 假设 StockQuantity 是数值类型,使用 0 作为默认值 |
| | | BatchNoName = dt_StockIndet?.BatchNoName ?? "", |
| | | CreateDate = dt_StockIndet?.CreateDate ?? DateTime.MinValue, // 假设 CreateDate 是日期类型,使用默认时间 |
| | | MaterielCode = dt_StockIndet?.FirstOrDefault()?.MaterielCode ?? "", |
| | | MaterielName = dt_StockIndet?.FirstOrDefault()?.MaterielName ?? "", |
| | | OrderNo = dt_StockIndet?.FirstOrDefault()?.OrderNo ?? "", |
| | | BatchNo = dt_StockIndet?.FirstOrDefault()?.BatchNo ?? "", |
| | | SerialNumber = dt_StockIndet?.FirstOrDefault()?.SerialNumber ?? "", |
| | | StockQuantity = dt_StockIndet?.Sum(item => item.StockQuantity) ?? 0, |
| | | BatchNoName = dt_StockIndet?.FirstOrDefault()?.BatchNoName ?? "", |
| | | CreateDate = dt_StockIndet?.FirstOrDefault()?.CreateDate ?? DateTime.MinValue, |
| | | Remark = entities[i].Remark, |
| | | }; |
| | | stolist.Add(dt_); |
| | |
| | | [ExporterHeader(DisplayName = "物料状态")] |
| | | public string Wlstatus { get; set; } |
| | | } |
| | | |
| | | |
| | | public List<Dt_StockInfo> GetUseableStocks(string materielCode, string batchNo, List<Dt_Warehouse> warehouse) |
| | | { |
| | | List<string> locationCodes = _basicRepository.LocationInfoRepository.GetCanOutLocationCodes(warehouse); |
| | | |
| | | return BaseDal.GetStockInfos(materielCode, batchNo, locationCodes); |
| | | } |
| | | } |
| | | } |