public IEnumerable transactions()
            {
                if (!IsCartRequired)
                {
                    return(null);
                }
                PXDelegateResult sorted = new PXDelegateResult
                {
                    IsResultSorted    = true,
                    IsResultFiltered  = true,
                    IsResultTruncated = true
                };
                var view     = new PXView(Base, false, Base.transactions.View.BqlSelect);
                int startRow = PXView.StartRow;
                int totalRow = 0;
                var lines    = view.Select(
                    PXView.Currents, PXView.Parameters, PXView.Searches, PXView.SortColumns, PXView.Descendings, PXView.Filters,
                    ref startRow, PXView.MaximumRows, ref totalRow)
                               .OfType <INTran>()
                               .Select(x => new { Line = x, IsInCart = (GetCartQty(x) ?? 0) > 0 })
                               .OrderByDescending(x => x.IsInCart)
                               .Select(x => x.Line)
                               .ToList();

                sorted.AddRange(lines);
                return(sorted);
            }
Exemple #2
0
        public IEnumerable detailsView()
        {
            //var lastFinPeriod = DateTime.Now.AddMonths(-1).ToString("yyyyMM");

            var filter = MasterViewFilter.Current?.FinPeriodID;

            if (filter == null)
            {
                filter = ((DateTime)Accessinfo.BusinessDate).AddMonths(-1).ToString("yyyyMM");
            }

            PXSelectBase <LCMValuation> command = new SelectFrom <LCMValuation> .View.ReadOnly(this);

            var result = new PXDelegateResult();

            foreach (PXResult <LCMValuation> row in command.Select())
            {
                if (((LCMValuation)row).FinPeriodID == filter)
                {
                    result.Add(row);
                }
            }

            return(result);
        }
Exemple #3
0
        protected virtual IEnumerable viewHandler()
        {
            if (intView == null)
            {
                intView = CreateIntView(View.Graph);
            }
            int startRow = PXView.StartRow;
            int num      = 0;
            PXDelegateResult pXDelegateResult = new PXDelegateResult();

            foreach (object obj in intView.Select(null, null, PXView.Searches, PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref num))
            {
                var statu  = PXResult.Unwrap <RowToSelect>(obj);
                var statu1 = statu;
                var statu2 = (Cache.Locate(statu) as RowToSelect);
                if (statu2 != null)
                {
                    bool?value = (Cache.GetValue(statu2, Selected) as bool?);
                    if (value.GetValueOrDefault() & value.HasValue)
                    {
                        Cache.RestoreCopy(statu2, statu);
                        Cache.SetValue(statu2, Selected, true);
                        statu1 = statu2;
                    }
                }
                pXDelegateResult.Add(statu1);
            }
            PXView.StartRow = 0;
            if (PXView.ReverseOrder)
            {
                pXDelegateResult.Reverse();
            }
            pXDelegateResult.IsResultSorted = true;
            return(pXDelegateResult);
        }
        public PXDelegateResult CreateDelegateResult(bool restricted = true)
        {
            PXDelegateResult list = new PXDelegateResult();

            if (this.MappedFilters.Any(_ => _.UseExt))
            {
                restricted = false;
            }

            list.IsResultFiltered  = restricted;
            list.IsResultSorted    = restricted;
            list.IsResultTruncated = restricted;
            return(list);
        }
Exemple #5
0
        protected virtual IEnumerable result()
        {
            var filter = Filter.Current;

            if (!ValidateFilter(filter))
            {
                return(new LumDeadStockEnqResult[0]);
            }

            GetStartDates(filter, out DateTime? inStockSince, out DateTime? noSalesSince);
            PXSelectBase <INSiteStatus> command = CreateCommand();
            var parameters = AddFilters(filter, command, inStockSince, noSalesSince);

            var singleRow = GetRowByPrimaryKeys(command, filter, inStockSince, noSalesSince);

            if (singleRow != null)
            {
                return new LumDeadStockEnqResult[] { singleRow }
            }
            ;

            bool userSortsFilters = ValidateViewSortsFilters();

            var result = new PXDelegateResult();

            result.IsResultFiltered = !userSortsFilters;
            result.IsResultSorted   = !userSortsFilters;
            int resultCounter = 0;

            foreach (PXResult <INSiteStatus> row in command.Select(parameters.ToArray()))
            {
                LumDeadStockEnqResult newResult = MakeResult(row, inStockSince, noSalesSince);

                if (newResult == null)
                {
                    continue;
                }

                result.Add(new PXResult <LumDeadStockEnqResult, InventoryItem>(newResult, row.GetItem <InventoryItem>()));
                resultCounter++;

                if (!userSortsFilters && (PXView.StartRow + PXView.MaximumRows) <= resultCounter)
                {
                    break;
                }
            }

            return(result);
        }
        protected virtual IEnumerable Location()
        {
            var rows =
                SelectFrom <INLocation> .
                Where <INLocation.siteID.IsEqual <INSite.siteID.FromCurrent> > .
                OrderBy <INLocation.pathPriority.Asc, INLocation.locationCD.Asc> .
                View.Select(Base);

            var result = new PXDelegateResult {
                IsResultSorted = true
            };

            result.AddRange(rows);
            return(result);
        }
Exemple #7
0
        protected virtual IEnumerable internalResultRecords()
        {
            InventoryTranHistEnqFilter filter = Filter.Current;

            bool summaryByDay      = filter.SummaryByDay ?? false;
            bool includeUnreleased = filter.IncludeUnreleased ?? false;

            var resultList = new List <PXResult <InventoryTranHistEnqResult, INTran, INTranSplit> >();

            if (filter.InventoryID == null)
            {
                PXDelegateResult emptyResult = new PXDelegateResult();
                emptyResult.IsResultFiltered  = true;
                emptyResult.IsResultSorted    = true;
                emptyResult.IsResultTruncated = true;

                return(emptyResult);                 //empty
            }

            PXSelectBase <INTranSplit> cmd = new PXSelectReadonly2 <INTranSplit,
                                                                    InnerJoin <INTran, On <INTranSplit.FK.Tran>,
                                                                               InnerJoin <INSubItem, On <INTranSplit.FK.SubItem>,
                                                                                          InnerJoin <INSite, On <INTran.FK.Site> > > >,
                                                                    Where <INTranSplit.inventoryID, Equal <Current <InventoryTranHistEnqFilter.inventoryID> >, And <Match <INSite, Current <AccessInfo.userName> > > >,
                                                                    OrderBy <Asc <INTranSplit.docType, Asc <INTranSplit.refNbr, Asc <INTranSplit.lineNbr, Asc <INTranSplit.splitLineNbr> > > > > >(this);

            PXSelectBase <INItemSiteHistByDay> cmdBegBalanceNew = new PXSelectReadonly2 <INItemSiteHistByDay,
                                                                                         InnerJoin <INItemSiteHistDay,
                                                                                                    On <INItemSiteHistDay.inventoryID, Equal <INItemSiteHistByDay.inventoryID>,
                                                                                                        And <INItemSiteHistDay.siteID, Equal <INItemSiteHistByDay.siteID>,
                                                                                                             And <INItemSiteHistDay.subItemID, Equal <INItemSiteHistByDay.subItemID>,
                                                                                                                  And <INItemSiteHistDay.locationID, Equal <INItemSiteHistByDay.locationID>,
                                                                                                                       And <INItemSiteHistDay.sDate, Equal <INItemSiteHistByDay.lastActivityDate> > > > > >,
                                                                                                    InnerJoin <INSubItem,
                                                                                                               On <INSubItem.subItemID, Equal <INItemSiteHistByDay.subItemID> >,
                                                                                                               InnerJoin <INSite, On <INSite.siteID, Equal <INItemSiteHistByDay.siteID> > > > >,
                                                                                         Where <INItemSiteHistByDay.inventoryID, Equal <Current <InventoryTranHistEnqFilter.inventoryID> >,
                                                                                                And <INItemSiteHistByDay.date, Equal <Required <INItemSiteHistByDay.date> >,
                                                                                                     And <Match <INSite, Current <AccessInfo.userName> > > > > >(this);

            if (!SubCDUtils.IsSubCDEmpty(filter.SubItemCD) && PXAccess.FeatureInstalled <FeaturesSet.subItem>())
            {
                cmd.WhereAnd <Where <INSubItem.subItemCD, Like <Current <InventoryTranHistEnqFilter.subItemCDWildcard> > > >();
                cmdBegBalanceNew.WhereAnd <Where <INSubItem.subItemCD, Like <Current <InventoryTranHistEnqFilter.subItemCDWildcard> > > >();
            }

            if (filter.SiteID != null && PXAccess.FeatureInstalled <FeaturesSet.warehouse>())
            {
                cmd.WhereAnd <Where <INTranSplit.siteID, Equal <Current <InventoryTranHistEnqFilter.siteID> > > >();
                cmdBegBalanceNew.WhereAnd <Where <INItemSiteHistByDay.siteID, Equal <Current <InventoryTranHistEnqFilter.siteID> > > >();
            }

            if ((filter.LocationID ?? -1) != -1 && PXAccess.FeatureInstalled <FeaturesSet.warehouseLocation>())        // there are cases when filter.LocationID = -1
            {
                cmd.WhereAnd <Where <INTranSplit.locationID, Equal <Current <InventoryTranHistEnqFilter.locationID> > > >();
                cmdBegBalanceNew.WhereAnd <Where <INItemSiteHistByDay.locationID, Equal <Current <InventoryTranHistEnqFilter.locationID> > > >();
            }

            if ((filter.LotSerialNbr ?? "") != "" && PXAccess.FeatureInstalled <FeaturesSet.lotSerialTracking>())
            {
                cmd.WhereAnd <Where <INTranSplit.lotSerialNbr, Like <Current <InventoryTranHistEnqFilter.lotSerialNbrWildcard> > > >();
            }

            if (!includeUnreleased)
            {
                cmd.WhereAnd <Where <INTranSplit.released, Equal <True> > >();
            }

            decimal cumulativeQty = 0m;

            if (filter.StartDate != null)
            {
                foreach (PXResult <INItemSiteHistByDay, INItemSiteHistDay> res in cmdBegBalanceNew.Select(filter.StartDate))
                {
                    INItemSiteHistByDay byday = res;
                    INItemSiteHistDay   hist  = res;

                    cumulativeQty +=
                        ((byday.LastActivityDate != null && byday.Date != null &&
                          byday.Date.Value.Date == byday.LastActivityDate.Value.Date)
                                            ? hist.BegQty
                                            : hist.EndQty) ?? 0m;
                }

                if (includeUnreleased)
                {
                    INSite site = INSite.PK.Find(this, filter.SiteID);

                    int calendarOrganizationID = PXAccess.GetParentOrganizationID(site?.BranchID) ?? FinPeriod.organizationID.MasterValue;

                    string   TranPeriodID;
                    DateTime?PeriodStartDate;

                    try
                    {
                        TranPeriodID    = FinPeriodRepository.GetPeriodIDFromDate(filter.StartDate, calendarOrganizationID);
                        PeriodStartDate = FinPeriodRepository.PeriodStartDate(TranPeriodID, calendarOrganizationID);
                    }
                    catch (PXFinPeriodException)
                    {
                        TranPeriodID    = null;
                        PeriodStartDate = filter.StartDate;
                    }

                    PXSelectBase <OrganizationFinPeriod> periodCmd =
                        new PXSelectGroupBy <OrganizationFinPeriod,
                                             Where <OrganizationFinPeriod.finPeriodID, LessEqual <Required <OrganizationFinPeriod.finPeriodID> >,
                                                    And <OrganizationFinPeriod.iNClosed, Equal <False>,
                                                         Or <OrganizationFinPeriod.finPeriodID, Equal <Required <OrganizationFinPeriod.finPeriodID> > > > >,
                                             Aggregate <GroupBy <OrganizationFinPeriod.finPeriodID> >,
                                             OrderBy <Asc <OrganizationFinPeriod.finPeriodID> > >(this);

                    List <object> periodCmdParams = new List <object>()
                    {
                        TranPeriodID, TranPeriodID
                    };


                    if (calendarOrganizationID != FinPeriod.organizationID.MasterValue)
                    {
                        periodCmd.WhereAnd <Where <OrganizationFinPeriod.organizationID, Equal <Required <OrganizationFinPeriod.organizationID> > > >();

                        periodCmdParams.Add(calendarOrganizationID);
                    }

                    OrganizationFinPeriod firstOpenOrCurrentClosedPeriod = periodCmd.SelectWindowed(0, 1, periodCmdParams.ToArray());

                    if (firstOpenOrCurrentClosedPeriod != null)
                    {
                        TranPeriodID    = firstOpenOrCurrentClosedPeriod.FinPeriodID;
                        PeriodStartDate = FinPeriodRepository.PeriodStartDate(firstOpenOrCurrentClosedPeriod.FinPeriodID, calendarOrganizationID);

                        PXView v2 = new PXView(this, true, cmd.View.BqlSelect
                                               .WhereAnd <Where <INTranSplit.tranDate, GreaterEqual <Required <INTranSplit.tranDate> > > >()
                                               .WhereAnd <Where <INTranSplit.tranDate, Less <Required <INTranSplit.tranDate> > > >()
                                               .WhereAnd <Where <INTranSplit.released, Equal <False> > >()
                                               .AggregateNew <Aggregate <
                                                                  GroupBy <INTranSplit.inventoryID, GroupBy <INTranSplit.invtMult, Sum <INTranSplit.baseQty> > > > >());

                        int splitStartRow  = 0;
                        int splitTotalRows = 0;

                        foreach (PXResult <INTranSplit> res in v2.Select(new object[0], new object[] { PeriodStartDate, filter.StartDate.Value }, new object[0],
                                                                         new string[0], new bool[0], new PXFilterRow[0], ref splitStartRow, 0, ref splitTotalRows))
                        {
                            INTranSplit tsRec = res;
                            cumulativeQty += (tsRec.InvtMult * tsRec.BaseQty) ?? 0m;
                        }
                    }
                }
            }

            if (filter.StartDate != null)
            {
                cmd.WhereAnd <Where <INTranSplit.tranDate, GreaterEqual <Current <InventoryTranHistEnqFilter.startDate> > > >();
            }

            if (filter.EndDate != null)
            {
                cmd.WhereAnd <Where <INTranSplit.tranDate, LessEqual <Current <InventoryTranHistEnqFilter.endDate> > > >();
            }

            AlterSortsAndFilters(out string[] newSortColumns, out bool[] newDescendings, out bool sortsChanged, out PXFilterRow[] newFilters, out bool filtersChanged);

            //if user clicks last, sorts will be inverted
            //as it is not possible to calculate beginning balance from the end
            //we will select without top from the start and then apply reverse order and select top n records
            //for next page we will ommit startrow to set beginning balance correctly
            //top (n, m) will be set in the outer search results since we do not reset PXView.StartRow to 0
            //Also, user can set a filter or sort by a column from result DAC (sortsChanged = true, filtersChanged = true) and need to get full result set.
            int  startRow           = 0;
            bool allowSelectWithTop = !sortsChanged && !filtersChanged && !PXView.ReverseOrder;
            int  maximumRows        = allowSelectWithTop ? PXView.StartRow + PXView.MaximumRows : 0;
            int  totalRows          = 0;

            PXView selectView = !summaryByDay
                            ? cmd.View
                            : new PXView(this, true,
                                         cmd.View.BqlSelect
                                         .AggregateNew <Aggregate <GroupBy <INTranSplit.tranDate, Sum <INTranSplit.qtyIn, Sum <INTranSplit.qtyOut> > > > >());

            List <object> intermediateResult = selectView.Select(PXView.Currents, new object[] { filter.StartDate },
                                                                 new string[newSortColumns.Length], newSortColumns, newDescendings, newFilters, ref startRow, maximumRows,
                                                                 ref totalRows);

            int gridLineNbr = 0;

            foreach (PXResult <INTranSplit, INTran, INSubItem> it in intermediateResult)
            {
                INTranSplit ts_rec = (INTranSplit)it;
                INTran      t_rec  = (INTran)it;

                if (summaryByDay)
                {
                    InventoryTranHistEnqResult item = new InventoryTranHistEnqResult();
                    item.BegQty      = cumulativeQty;
                    item.TranDate    = ts_rec.TranDate;
                    item.QtyIn       = ts_rec.QtyIn;
                    item.QtyOut      = ts_rec.QtyOut;
                    item.EndQty      = item.BegQty + ts_rec.QtyIn - ts_rec.QtyOut;
                    item.GridLineNbr = ++gridLineNbr;
                    resultList.Add(new PXResult <InventoryTranHistEnqResult, INTran, INTranSplit>(item, null, null));
                    cumulativeQty += (ts_rec.QtyIn - ts_rec.QtyOut) ?? 0m;
                }
                else
                {
                    InventoryTranHistEnqResult item = new InventoryTranHistEnqResult();
                    item.BegQty   = cumulativeQty;
                    item.TranDate = ts_rec.TranDate;
                    item.QtyIn    = ts_rec.QtyIn;
                    item.QtyOut   = ts_rec.QtyOut;
                    item.EndQty   = item.BegQty + ts_rec.QtyIn - ts_rec.QtyOut;

                    item.DocType      = ts_rec.DocType;
                    item.RefNbr       = ts_rec.RefNbr;
                    item.LineNbr      = ts_rec.LineNbr;
                    item.SplitLineNbr = ts_rec.SplitLineNbr;
                    item.GridLineNbr  = ++gridLineNbr;

                    decimal?unitcost;
                    if (filter.ShowAdjUnitCost ?? false)
                    {
                        unitcost = ts_rec.TotalQty != null && ts_rec.TotalQty != 0m ? (ts_rec.TotalCost + ts_rec.AdditionalCost) / ts_rec.TotalQty : 0m;
                    }
                    else
                    {
                        unitcost = ts_rec.TotalQty != null && ts_rec.TotalQty != 0m ? ts_rec.TotalCost / ts_rec.TotalQty : 0m;
                    }

                    item.UnitCost = unitcost;
                    resultList.Add(new PXResult <InventoryTranHistEnqResult, INTran, INTranSplit>(item, t_rec, ts_rec));
                    cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m;
                }
            }


            PXDelegateResult delegateResult = new PXDelegateResult();

            delegateResult.IsResultFiltered  = !filtersChanged;
            delegateResult.IsResultSorted    = !sortsChanged;
            delegateResult.IsResultTruncated = totalRows > resultList.Count;

            if (!PXView.ReverseOrder)
            {
                delegateResult.AddRange(resultList);
            }
            else
            {
                var sortedList = PXView.Sort(resultList);
                delegateResult.AddRange(sortedList.Cast <PXResult <InventoryTranHistEnqResult, INTran, INTranSplit> >());
                delegateResult.IsResultSorted = true;
            }

            return(delegateResult);
        }
Exemple #8
0
        protected virtual IEnumerable resultRecords()
        {
            InventoryTranHistEnqFilter filter = Filter.Current;

            bool summaryByDay      = filter.SummaryByDay ?? false;
            bool includeUnreleased = filter.IncludeUnreleased ?? false;

            PXCache intranCache      = this.Caches <INTran>();
            PXCache intranSplitCache = this.Caches <INTranSplit>();

            PXUIFieldAttribute.SetVisible <INTran.inventoryID>(intranCache, null, false);
            PXUIFieldAttribute.SetVisible <INTran.finPeriodID>(intranCache, null, false);    //???
            PXUIFieldAttribute.SetVisible <INTran.tranPeriodID>(intranCache, null, false);   //???


            PXUIFieldAttribute.SetVisible <INTran.tranType>(intranCache, null, !summaryByDay);
            PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.refNbr>(ResultRecords.Cache, null, !summaryByDay);
            PXUIFieldAttribute.SetVisible <INTranSplit.subItemID>(intranSplitCache, null, !summaryByDay);
            PXUIFieldAttribute.SetVisible <INTran.siteID>(intranCache, null, !summaryByDay);
            PXUIFieldAttribute.SetVisible <INTranSplit.locationID>(intranSplitCache, null, !summaryByDay);
            PXUIFieldAttribute.SetVisible <INTranSplit.lotSerialNbr>(intranSplitCache, null, !summaryByDay);
            PXUIFieldAttribute.SetVisible(Tran.Cache, null, !summaryByDay);

            int     startRow  = PXView.StartRow;
            int     totalRows = 0;
            decimal?beginQty  = null;

            if (PXView.MaximumRows == 1 && PXView.Searches != null && PXView.Searches.Length == 1)
            {
                InventoryTranHistEnqResult ither = new InventoryTranHistEnqResult();
                ither.GridLineNbr = (int?)PXView.Searches[0];
                ither             = (InventoryTranHistEnqResult)ResultRecords.Cache.Locate(ither);
                if (ither != null && ither.TranDate != null)
                {
                    PXDelegateResult oneRowResult = new PXDelegateResult();

                    oneRowResult.AddRange(new List <InventoryTranHistEnqResult>()
                    {
                        ither
                    });
                    oneRowResult.IsResultFiltered  = true;
                    oneRowResult.IsResultSorted    = true;
                    oneRowResult.IsResultTruncated = true;

                    return(oneRowResult);
                }
            }

            ResultRecords.Cache.Clear();
            List <object> list = InternalResultRecords.View.Select(PXView.Currents, PXView.Parameters, new object[PXView.SortColumns.Length], PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows);

            PXView.StartRow = 0;

            foreach (PXResult <InventoryTranHistEnqResult> item in list)
            {
                InventoryTranHistEnqResult it = (InventoryTranHistEnqResult)item;
                it.BegQty = beginQty = (beginQty ?? it.BegQty);
                decimal?QtyIn  = it.QtyIn;
                decimal?QtyOut = it.QtyOut;
                beginQty += (QtyIn ?? 0m) - (QtyOut ?? 0m);
                it.EndQty = beginQty;
                ResultRecords.Cache.SetStatus(it, PXEntryStatus.Held);
            }

            PXDelegateResult delegateResult = new PXDelegateResult();

            delegateResult.AddRange(list);
            delegateResult.IsResultFiltered  = true;
            delegateResult.IsResultSorted    = true;
            delegateResult.IsResultTruncated = totalRows > delegateResult.Count;

            return(delegateResult);
        }
        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);
        }