public virtual IEnumerable Storages() { var result = new PXDelegateResult(); result.IsResultSorted = true; result.IsResultTruncated = Filter.Current.ExpandByLotSerialNbr == false; PXSelectBase <StoragePlaceStatus> byLocationSelect = new SelectFrom <StoragePlaceStatus> .Where < StoragePlaceFilter.siteID.FromCurrent.NoDefault.IsEqual <StoragePlaceStatus.siteID> .And <StoragePlaceStatus.qty.IsGreater <Zero> > .And < Not <FeatureInstalled <FeaturesSet.wMSCartTracking> > .Or <StoragePlaceFilter.showLocations.FromCurrent.NoDefault.IsEqual <True> > .And <StoragePlaceStatus.isCart.IsEqual <False> > .Or <StoragePlaceFilter.showCarts.FromCurrent.NoDefault.IsEqual <True> > .And <StoragePlaceStatus.isCart.IsEqual <True> > > > .AggregateTo < GroupBy <StoragePlaceStatus.siteCD>, GroupBy <StoragePlaceStatus.storageCD>, GroupBy <StoragePlaceStatus.isCart>, GroupBy <StoragePlaceStatus.active>, GroupBy <StoragePlaceStatus.inventoryCD>, GroupBy <StoragePlaceStatus.subItemID>, Sum <StoragePlaceStatus.qty> > .OrderBy < StoragePlaceStatus.isCart.Asc, StoragePlaceStatus.siteCD.Asc, StoragePlaceStatus.storageCD.Desc, StoragePlaceStatus.active.Desc, StoragePlaceStatus.inventoryCD.Asc, StoragePlaceStatus.subItemID.Asc, StoragePlaceStatus.qty.Desc> .View(this); if (Filter.Current.StorageID != null) { byLocationSelect.WhereAnd <Where <StoragePlaceFilter.storageID.FromCurrent.IsEqual <StoragePlaceStatus.storageID> > >(); } if (Filter.Current.InventoryID != null) { byLocationSelect.WhereAnd <Where <StoragePlaceFilter.inventoryID.FromCurrent.IsEqual <StoragePlaceStatus.inventoryID> > >(); } if (Filter.Current.SubItemID != null) { byLocationSelect.WhereAnd <Where <StoragePlaceFilter.subItemID.FromCurrent.IsEqual <StoragePlaceStatus.subItemID> > >(); } int startRow = PXView.StartRow; int totalRows = 0; var byLocation = Filter.Current.ExpandByLotSerialNbr == true ? byLocationSelect.SelectMain() : byLocationSelect.View.Select(PXView.Currents, PXView.Parameters, PXView.Searches, PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows).RowCast <StoragePlaceStatus>().ToArray(); if (byLocation.Length > 0 && Filter.Current.ExpandByLotSerialNbr == true) { PXSelectBase <StoragePlaceStatusExpanded> byLotSerialSelect = new SelectFrom <StoragePlaceStatusExpanded> .Where < StoragePlaceFilter.siteID.FromCurrent.NoDefault.IsEqual <StoragePlaceStatusExpanded.siteID> .And <StoragePlaceStatusExpanded.qty.IsGreater <Zero> > > .AggregateTo < GroupBy <StoragePlaceStatusExpanded.siteCD>, GroupBy <StoragePlaceStatusExpanded.storageCD>, GroupBy <StoragePlaceStatusExpanded.active>, GroupBy <StoragePlaceStatusExpanded.inventoryCD>, GroupBy <StoragePlaceStatusExpanded.subItemID>, GroupBy <StoragePlaceStatusExpanded.lotSerialNbr>, Sum <StoragePlaceStatusExpanded.qty> > .OrderBy < StoragePlaceStatusExpanded.siteCD.Asc, StoragePlaceStatusExpanded.storageCD.Desc, StoragePlaceStatusExpanded.active.Desc, StoragePlaceStatusExpanded.inventoryCD.Asc, StoragePlaceStatusExpanded.subItemID.Asc, StoragePlaceStatusExpanded.lotSerialNbr.Asc, StoragePlaceStatusExpanded.qty.Desc> .View(this); if (Filter.Current.StorageID != null) { byLotSerialSelect.WhereAnd <Where <StoragePlaceFilter.storageID.FromCurrent.IsEqual <StoragePlaceStatusExpanded.storageID> > >(); } if (Filter.Current.InventoryID != null) { byLotSerialSelect.WhereAnd <Where <StoragePlaceFilter.inventoryID.FromCurrent.IsEqual <StoragePlaceStatusExpanded.inventoryID> > >(); } if (Filter.Current.SubItemID != null) { byLotSerialSelect.WhereAnd <Where <StoragePlaceFilter.subItemID.FromCurrent.IsEqual <StoragePlaceStatusExpanded.subItemID> > >(); } if (Filter.Current.LotSerialNbr != null) { byLotSerialSelect.WhereAnd <Where <StoragePlaceFilter.lotSerialNbr.FromCurrent.IsEqual <StoragePlaceStatusExpanded.lotSerialNbr> > >(); } var byLotSerial = byLotSerialSelect .SelectMain() .Select( r => new StoragePlaceStatus { SplittedIcon = r.SplittedIcon, SiteID = r.SiteID, SiteCD = r.SiteCD, LocationID = r.LocationID, CartID = null, StorageID = r.StorageID, StorageCD = r.StorageCD, Descr = r.Descr, IsCart = false, Active = r.Active, InventoryID = r.InventoryID, InventoryCD = r.InventoryCD, SubItemID = r.SubItemID, LotSerialNbr = r.LotSerialNbr, ExpireDate = r.ExpireDate, Qty = r.Qty, BaseUnit = r.BaseUnit }) .ToArray(); if (byLotSerial.Length > 0) { int locationIdx = 1; int lotSerIdx = 0; StoragePlaceStatus current = byLocation[0]; result.Add(current); while (locationIdx < byLocation.Length || lotSerIdx < byLotSerial.Length) { if (locationIdx >= byLocation.Length || lotSerIdx < byLotSerial.Length && current.SiteID == byLotSerial[lotSerIdx].SiteID && current.StorageID == byLotSerial[lotSerIdx].StorageID && current.InventoryID == byLotSerial[lotSerIdx].InventoryID && current.SubItemID == byLotSerial[lotSerIdx].SubItemID) { result.Add(byLotSerial[lotSerIdx]); lotSerIdx++; } else { current = byLocation[locationIdx]; result.Add(current); locationIdx++; } } } else { result.AddRange(byLocation); } } else { result.AddRange(byLocation); } PXView.StartRow = 0; return(result); }