hutongqing
2024-12-10 8d341db9d2d5699d527c88c935f0c4ce255a57a4
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
@@ -23,53 +23,11 @@
{
    public partial class StockInfoService : ServiceBase<Dt_StockInfo, IStockInfoRepository>, IStockInfoService
    {
        /// <summary>
        /// æ ¹æ®æ‰˜ç›˜å·æŸ¥è¯¢åº“å­˜
        /// </summary>
        /// <param name="palletCode"></param>
        /// <returns></returns>
        public Dt_StockInfo? GetStockByPalletCode(string palletCode)
        {
            Dt_StockInfo stockInfo = BaseDal.QueryFirst(x => x.PalletCode == palletCode);
            if (stockInfo != null)
            {
                stockInfo.Details = _stockRepository.StockInfoDetailRepository.QueryData(x => x.StockId == stockInfo.Id);
            }
            return stockInfo;
        }
        public void AddMaterielGroup(Dt_StockInfo stockInfo)
        {
            decimal beforeQuantity = 0;
            List<Dt_StockInfoDetail> details = new List<Dt_StockInfoDetail>();
            if (stockInfo.Id == 0)
            {
                BaseDal.Db.InsertNav(stockInfo).Include(x => x.Details).ExecuteCommand();
                details = stockInfo.Details;
            }
            else
            {
                beforeQuantity = stockInfo.Details.Where(x => x.Id != 0).Sum(x => x.StockQuantity);
                for (int i = 0; i < stockInfo.Details.Count; i++)
                {
                    if (stockInfo.Details[i].Id == 0)
                    {
                        details.Add(_stockRepository.StockInfoDetailRepository.Db.Insertable(stockInfo.Details[i]).ExecuteReturnEntity());
                    }
                }
            }
            stockInfo.Details = details;
            _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) + beforeQuantity, StockChangeTypeEnum.MaterielGroup,0);
        }
        public List<Dt_StockInfo> GetOutboundStocks(List<Dt_StockInfo> stockInfos, string materielCode, decimal needQuantity, out decimal residueQuantity)
        public List<Dt_StockInfo> GetOutboundStocks(List<Dt_StockInfo> stockInfos, string materielCode, float needQuantity, out float residueQuantity)
        {
            List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
            decimal stockTotalQuantity = stockInfos.Select(x => x.Details.Sum(v => v.StockQuantity - v.OutboundQuantity)).Sum(x => x);
            float stockTotalQuantity = stockInfos.Select(x => x.Details.Sum(v => v.StockQuantity - v.OutboundQuantity)).Sum(x => x);
            stockInfos = stockInfos.OrderBy(x => x.Id).ToList();
            if (stockTotalQuantity >= needQuantity)//库存够
            {
@@ -78,7 +36,7 @@
                {
                    Dt_StockInfo stockInfo = stockInfos[index];
                    decimal useableStockQuantity = stockInfo.Details.Where(x => x.MaterielCode == materielCode).Sum(x => x.StockQuantity - x.OutboundQuantity);
                    float useableStockQuantity = stockInfo.Details.Where(x => x.MaterielCode == materielCode).Sum(x => x.StockQuantity - x.OutboundQuantity);
                    if (useableStockQuantity < needQuantity)
                    {
                        stockInfo.Details.ForEach(x => x.OutboundQuantity = x.StockQuantity);
@@ -112,7 +70,7 @@
                for (int i = 0; i < stockInfos.Count; i++)
                {
                    Dt_StockInfo stockInfo = stockInfos[i];
                    decimal useableStockQuantity = stockInfo.Details.Where(x => x.MaterielCode == materielCode).Sum(x => x.StockQuantity - x.OutboundQuantity);
                    float useableStockQuantity = stockInfo.Details.Where(x => x.MaterielCode == materielCode).Sum(x => x.StockQuantity - x.OutboundQuantity);
                    if (useableStockQuantity < needQuantity)
                    {
                        stockInfo.Details.ForEach(x => x.OutboundQuantity = x.StockQuantity);