|  |  |  | 
|---|
|  |  |  | _recordService = recordService; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public (List<Dt_StockInfo>, Dt_MesPPOutboundOrder, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(Dt_MesPPOutboundOrder mesPPOutboundOrder) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); | 
|---|
|  |  |  | //public (List<Dt_StockInfo>, Dt_MesPPOutboundOrder, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(Dt_MesPPOutboundOrder mesPPOutboundOrder) | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); | 
|---|
|  |  |  | List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); | 
|---|
|  |  |  | //    List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); | 
|---|
|  |  |  | //    List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float originalNeedQuantity = mesPPOutboundOrder.OrderQuantity; | 
|---|
|  |  |  | //    float originalNeedQuantity = mesPPOutboundOrder.OrderQuantity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float needQuantity = originalNeedQuantity; | 
|---|
|  |  |  | //    float needQuantity = originalNeedQuantity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(mesPPOutboundOrder.MaterialCode, "", mesPPOutboundOrder.Details.FirstOrDefault()?.CarrierCode ?? "",mesPPOutboundOrder.WarehouseId); | 
|---|
|  |  |  | if (!stockInfos.Any()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new Exception($"æªæ¾å°å¯åé
åºå"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, mesPPOutboundOrder.MaterialCode, needQuantity, out float residueQuantity); | 
|---|
|  |  |  | mesPPOutboundOrder.LockQuantity += needQuantity - residueQuantity; | 
|---|
|  |  |  | outStocks.AddRange(autoAssignStocks); | 
|---|
|  |  |  | float assignQuantity = needQuantity - residueQuantity; | 
|---|
|  |  |  | //    List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(mesPPOutboundOrder.MaterialCode, "", mesPPOutboundOrder.Details.FirstOrDefault()?.CarrierCode ?? "",mesPPOutboundOrder.WarehouseId); | 
|---|
|  |  |  | //    if (!stockInfos.Any()) | 
|---|
|  |  |  | //    { | 
|---|
|  |  |  | //        throw new Exception($"æªæ¾å°å¯åé
åºå"); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | //    List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, mesPPOutboundOrder.MaterialCode, needQuantity, out float residueQuantity); | 
|---|
|  |  |  | //    mesPPOutboundOrder.LockQuantity += needQuantity - residueQuantity; | 
|---|
|  |  |  | //    outStocks.AddRange(autoAssignStocks); | 
|---|
|  |  |  | //    float assignQuantity = needQuantity - residueQuantity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float orderQuantity = mesPPOutboundOrder.OrderQuantity; | 
|---|
|  |  |  | for (int j = 0; j < autoAssignStocks.Count; j++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | float detailAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == mesPPOutboundOrder.MaterialCode).Sum(x => x.AssignQuantity);//åºåºè®¢åæç»å·²åé
æ°é | 
|---|
|  |  |  | //    float orderQuantity = mesPPOutboundOrder.OrderQuantity; | 
|---|
|  |  |  | //    for (int j = 0; j < autoAssignStocks.Count; j++) | 
|---|
|  |  |  | //    { | 
|---|
|  |  |  | //        float detailAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == mesPPOutboundOrder.MaterialCode).Sum(x => x.AssignQuantity);//åºåºè®¢åæç»å·²åé
æ°é | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float palletAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == mesPPOutboundOrder.MaterialCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//åºåºè¯¦æ
å·²åé
æ°é | 
|---|
|  |  |  | //        float palletAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == mesPPOutboundOrder.MaterialCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//åºåºè¯¦æ
å·²åé
æ°é | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float palletOutboundQuantity = autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity); | 
|---|
|  |  |  | if (palletAssignQuantity < palletOutboundQuantity)//妿åºåºè¯¦æ
å·²åé
æ°éå°äºæçå·²åé
æ°éï¼åå¯ä»¥ç»§ç»æ·»å è¯¥æçåºåºä¿¡æ¯ | 
|---|
|  |  |  | { | 
|---|
|  |  |  | float orderDetailNeedQuantity = mesPPOutboundOrder.OrderQuantity - detailAssignQuantity; | 
|---|
|  |  |  | if (orderDetailNeedQuantity > autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | mesPPOutboundOrder.LockQuantity += autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity; | 
|---|
|  |  |  | Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(mesPPOutboundOrder, autoAssignStocks[j], autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity); | 
|---|
|  |  |  | outStockLockInfos.Add(outStockLockInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(mesPPOutboundOrder, autoAssignStocks[j], mesPPOutboundOrder.OrderQuantity - mesPPOutboundOrder.LockQuantity); | 
|---|
|  |  |  | outStockLockInfos.Add(outStockLockInfo); | 
|---|
|  |  |  | mesPPOutboundOrder.LockQuantity = mesPPOutboundOrder.OrderQuantity; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList())); | 
|---|
|  |  |  | //        float palletOutboundQuantity = autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity); | 
|---|
|  |  |  | //        if (palletAssignQuantity < palletOutboundQuantity)//妿åºåºè¯¦æ
å·²åé
æ°éå°äºæçå·²åé
æ°éï¼åå¯ä»¥ç»§ç»æ·»å è¯¥æçåºåºä¿¡æ¯ | 
|---|
|  |  |  | //        { | 
|---|
|  |  |  | //            float orderDetailNeedQuantity = mesPPOutboundOrder.OrderQuantity - detailAssignQuantity; | 
|---|
|  |  |  | //            if (orderDetailNeedQuantity > autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity) | 
|---|
|  |  |  | //            { | 
|---|
|  |  |  | //                mesPPOutboundOrder.LockQuantity += autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity; | 
|---|
|  |  |  | //                Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(mesPPOutboundOrder, autoAssignStocks[j], autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity); | 
|---|
|  |  |  | //                outStockLockInfos.Add(outStockLockInfo); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //            else | 
|---|
|  |  |  | //            { | 
|---|
|  |  |  | //                Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(mesPPOutboundOrder, autoAssignStocks[j], mesPPOutboundOrder.OrderQuantity - mesPPOutboundOrder.LockQuantity); | 
|---|
|  |  |  | //                outStockLockInfos.Add(outStockLockInfo); | 
|---|
|  |  |  | //                mesPPOutboundOrder.LockQuantity = mesPPOutboundOrder.OrderQuantity; | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | //    locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return (outStocks, mesPPOutboundOrder, outStockLockInfos, locationInfos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //    return (outStocks, mesPPOutboundOrder, outStockLockInfos, locationInfos); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public (List<Dt_StockInfo>, Dt_MesPPCutOutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(Dt_MesPPCutOutboundOrder mesPPOutboundOrder, Dt_MesPPCutOutboundOrderDetail mesPPCutOutboundOrderDetail) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); | 
|---|
|  |  |  | //public (List<Dt_StockInfo>, Dt_MesPPCutOutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(Dt_MesPPCutOutboundOrder mesPPOutboundOrder, Dt_MesPPCutOutboundOrderDetail mesPPCutOutboundOrderDetail) | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); | 
|---|
|  |  |  | List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); | 
|---|
|  |  |  | //Dt_MesPPCutOutboundOrder outboundOrder = BaseDal.Db.Queryable<Dt_MesPPCutOutboundOrder>().Where(x=>x.Id==mesPPOutboundOrder.OrderId).First(); | 
|---|
|  |  |  | float originalNeedQuantity = mesPPCutOutboundOrderDetail.OrderQuantity; | 
|---|
|  |  |  | //    List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); | 
|---|
|  |  |  | //    List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); | 
|---|
|  |  |  | //    //Dt_MesPPCutOutboundOrder outboundOrder = BaseDal.Db.Queryable<Dt_MesPPCutOutboundOrder>().Where(x=>x.Id==mesPPOutboundOrder.OrderId).First(); | 
|---|
|  |  |  | //    float originalNeedQuantity = mesPPCutOutboundOrderDetail.OrderQuantity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float needQuantity = originalNeedQuantity; | 
|---|
|  |  |  | //    float needQuantity = originalNeedQuantity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(mesPPCutOutboundOrderDetail.MaterielCode,  "", mesPPOutboundOrder.WarehouseId); | 
|---|
|  |  |  | if (!stockInfos.Any()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new Exception($"æªæ¾å°å¯åé
åºå"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, mesPPCutOutboundOrderDetail.MaterielCode, needQuantity, out float residueQuantity); | 
|---|
|  |  |  | mesPPCutOutboundOrderDetail.LockQuantity += needQuantity - residueQuantity; | 
|---|
|  |  |  | outStocks.AddRange(autoAssignStocks); | 
|---|
|  |  |  | float assignQuantity = needQuantity - residueQuantity; | 
|---|
|  |  |  | //    List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(mesPPCutOutboundOrderDetail.MaterielCode,  "", mesPPOutboundOrder.WarehouseId); | 
|---|
|  |  |  | //    if (!stockInfos.Any()) | 
|---|
|  |  |  | //    { | 
|---|
|  |  |  | //        throw new Exception($"æªæ¾å°å¯åé
åºå"); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | //    List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, mesPPCutOutboundOrderDetail.MaterielCode, needQuantity, out float residueQuantity); | 
|---|
|  |  |  | //    mesPPCutOutboundOrderDetail.LockQuantity += needQuantity - residueQuantity; | 
|---|
|  |  |  | //    outStocks.AddRange(autoAssignStocks); | 
|---|
|  |  |  | //    float assignQuantity = needQuantity - residueQuantity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float orderQuantity = mesPPCutOutboundOrderDetail.OrderQuantity; | 
|---|
|  |  |  | for (int j = 0; j < autoAssignStocks.Count; j++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | float detailAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == mesPPCutOutboundOrderDetail.MaterielCode).Sum(x => x.AssignQuantity);//åºåºè®¢åæç»å·²åé
æ°é | 
|---|
|  |  |  | //    float orderQuantity = mesPPCutOutboundOrderDetail.OrderQuantity; | 
|---|
|  |  |  | //    for (int j = 0; j < autoAssignStocks.Count; j++) | 
|---|
|  |  |  | //    { | 
|---|
|  |  |  | //        float detailAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == mesPPCutOutboundOrderDetail.MaterielCode).Sum(x => x.AssignQuantity);//åºåºè®¢åæç»å·²åé
æ°é | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float palletAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == mesPPCutOutboundOrderDetail.MaterielCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//åºåºè¯¦æ
å·²åé
æ°é | 
|---|
|  |  |  | //        float palletAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == mesPPCutOutboundOrderDetail.MaterielCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//åºåºè¯¦æ
å·²åé
æ°é | 
|---|
|  |  |  |  | 
|---|
|  |  |  | float palletOutboundQuantity = autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity); | 
|---|
|  |  |  | if (palletAssignQuantity < palletOutboundQuantity)//妿åºåºè¯¦æ
å·²åé
æ°éå°äºæçå·²åé
æ°éï¼åå¯ä»¥ç»§ç»æ·»å è¯¥æçåºåºä¿¡æ¯ | 
|---|
|  |  |  | { | 
|---|
|  |  |  | float orderDetailNeedQuantity = mesPPCutOutboundOrderDetail.OrderQuantity - detailAssignQuantity; | 
|---|
|  |  |  | if (orderDetailNeedQuantity > autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | mesPPCutOutboundOrderDetail.LockQuantity += autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity; | 
|---|
|  |  |  | Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(mesPPOutboundOrder, mesPPCutOutboundOrderDetail, autoAssignStocks[j], autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity); | 
|---|
|  |  |  | outStockLockInfos.Add(outStockLockInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(mesPPOutboundOrder, mesPPCutOutboundOrderDetail, autoAssignStocks[j], mesPPCutOutboundOrderDetail.OrderQuantity - mesPPCutOutboundOrderDetail.LockQuantity); | 
|---|
|  |  |  | outStockLockInfos.Add(outStockLockInfo); | 
|---|
|  |  |  | mesPPCutOutboundOrderDetail.LockQuantity = mesPPCutOutboundOrderDetail.OrderQuantity; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList())); | 
|---|
|  |  |  | //        float palletOutboundQuantity = autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity); | 
|---|
|  |  |  | //        if (palletAssignQuantity < palletOutboundQuantity)//妿åºåºè¯¦æ
å·²åé
æ°éå°äºæçå·²åé
æ°éï¼åå¯ä»¥ç»§ç»æ·»å è¯¥æçåºåºä¿¡æ¯ | 
|---|
|  |  |  | //        { | 
|---|
|  |  |  | //            float orderDetailNeedQuantity = mesPPCutOutboundOrderDetail.OrderQuantity - detailAssignQuantity; | 
|---|
|  |  |  | //            if (orderDetailNeedQuantity > autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity) | 
|---|
|  |  |  | //            { | 
|---|
|  |  |  | //                mesPPCutOutboundOrderDetail.LockQuantity += autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity; | 
|---|
|  |  |  | //                Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(mesPPOutboundOrder, mesPPCutOutboundOrderDetail, autoAssignStocks[j], autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity); | 
|---|
|  |  |  | //                outStockLockInfos.Add(outStockLockInfo); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //            else | 
|---|
|  |  |  | //            { | 
|---|
|  |  |  | //                Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(mesPPOutboundOrder, mesPPCutOutboundOrderDetail, autoAssignStocks[j], mesPPCutOutboundOrderDetail.OrderQuantity - mesPPCutOutboundOrderDetail.LockQuantity); | 
|---|
|  |  |  | //                outStockLockInfos.Add(outStockLockInfo); | 
|---|
|  |  |  | //                mesPPCutOutboundOrderDetail.LockQuantity = mesPPCutOutboundOrderDetail.OrderQuantity; | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | //    locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return (outStocks, mesPPCutOutboundOrderDetail, outStockLockInfos, locationInfos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //    return (outStocks, mesPPCutOutboundOrderDetail, outStockLockInfos, locationInfos); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|