|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return sugarQueryable.InnerJoin(sugarQueryable1, (a, b) => a.LocationCode == b.LocationCode).Select((a, b) => new StockViewDTO | 
|---|
|  |  |  | { | 
|---|
|  |  |  | AreaId = a.AreaId, | 
|---|
|  |  |  | LocationCode = b.LocationCode, | 
|---|
|  |  |  | Column = a.Column, | 
|---|
|  |  |  | CreateDate = b.CreateDate, | 
|---|
|  |  |  | Creater = b.Creater, | 
|---|
|  |  |  | Depth = a.Depth, | 
|---|
|  |  |  | EnalbeStatus = a.EnableStatus, | 
|---|
|  |  |  | IsFull = b.IsFull, | 
|---|
|  |  |  | Layer = a.Layer, | 
|---|
|  |  |  | LocationName = a.LocationName, | 
|---|
|  |  |  | LocationStatus = a.LocationStatus, | 
|---|
|  |  |  | 
|---|
|  |  |  | //return sugarQueryable.InnerJoin(sugarQueryable1, (a, b) => a.LocationCode == b.LocationCode).Select((a, b) => b).Includes(x => x.Details).ToList(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public List<Dt_StockInfo> GetStockInfos(string materielCode, List<string> locationCodes) | 
|---|
|  |  |  | public List<Dt_StockInfo> GetStockInfos(string materielCode, string lotNo, List<string> locationCodes) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return Db.Queryable<Dt_StockInfo>().Where(x => locationCodes.Contains(x.LocationCode)).Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode)).ToList(); | 
|---|
|  |  |  | List<Dt_StockInfo> stockInfos = null; | 
|---|
|  |  |  | if (!string.IsNullOrEmpty(lotNo)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var stockSort = Db.Queryable<Dt_StockInfo>().Where(x => locationCodes.Contains(x.LocationCode)).Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode && v.BatchNo == lotNo)).ToList(); | 
|---|
|  |  |  | stockInfos = stockSort.OrderBy(x=>x.Details.FirstOrDefault()?.EffectiveDate).ThenBy(x=>x.Details.Sum(v=>v.StockQuantity)).ToList(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var stockSort = Db.Queryable<Dt_StockInfo>().Where(x => locationCodes.Contains(x.LocationCode)).Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode)).ToList(); | 
|---|
|  |  |  | stockInfos = stockSort.OrderBy(x => x.Details.FirstOrDefault()?.EffectiveDate).ThenBy(x => x.Details.Sum(v => v.StockQuantity)).ToList(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return stockInfos; | 
|---|
|  |  |  | //ISugarQueryable<Dt_LocationInfo> sugarQueryable = Db.Queryable<Dt_LocationInfo>().Where(x => locationCodes.Contains(x.LocationCode)); | 
|---|
|  |  |  | //ISugarQueryable<Dt_StockInfo> sugarQueryable1 = Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode)); | 
|---|
|  |  |  | //return sugarQueryable.InnerJoin(sugarQueryable1, (a, b) => a.LocationCode == b.LocationCode).Select((a, b) => b).OrderBy(a => a.CreateDate).Includes(a => a.Details).ToList(); | 
|---|
|  |  |  | 
|---|
|  |  |  | public bool UpdateDataWithDetail(Dt_StockInfo stockInfo) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return Db.UpdateNav(stockInfo).Include(x => x.Details).ExecuteCommand(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Dt_StockInfo GetPalletStockInfo(string roadwayNo) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //ISugarQueryable<string> locationCodes = Db.Queryable<Dt_LocationInfo>().Where(x => x.RoadwayNo == roadwayNo && x.LocationStatus == LocationStatusEnum.Pallet.ObjToInt() && (x.EnalbeStatus == LocationEnalbeStatusEnum.OnlyOut.ObjToInt() || LocationEnalbeStatusEnum.Normal.ObjToInt() == x.EnalbeStatus)).Select(x => x.LocationCode); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return Db.Queryable<Dt_StockInfo>().Where(x => x.StockStatus == StockStatusEmun.å·²å
¥åº.ObjToInt() && SqlFunc.Subqueryable<Dt_LocationInfo>().Where(v => v.LocationCode == x.LocationCode && v.RoadwayNo == roadwayNo && v.LocationStatus == LocationStatusEnum.Pallet.ObjToInt() && (v.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt() || EnableStatusEnum.Normal.ObjToInt() == v.EnableStatus)).Any()).OrderBy(x => x.ModifyDate).First(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|