Beispiel #1
0
        protected virtual IEnumerable <INItemSiteHistDay> GetLastRows(INSiteStatus siteStatus, decimal deadStockQty, INItemSiteHistDay currentRow)
        {
            const int MaxRows = 1000;

            var getRows = new SelectFrom <INItemSiteHistDay>
                          .Where <INItemSiteHistDay.siteID.IsEqual <@P.AsInt>
                                  .And <INItemSiteHistDay.inventoryID.IsEqual <@P.AsInt> >
                                  .And <INItemSiteHistDay.subItemID.IsEqual <@P.AsInt> >
                                  .And <INItemSiteHistDay.sDate.IsLess <@P.AsDateTime> >
                                  .And <INItemSiteHistDay.qtyDebit.IsGreater <decimal0> > >
                          .OrderBy <INItemSiteHistDay.sDate.Desc> .View.ReadOnly(this);

            DateTime?lastDate            = currentRow.SDate;
            decimal  deadStockQtyCounter = deadStockQty;

            yield return(currentRow);

            while (lastDate != null && deadStockQtyCounter > 0m)
            {
                // Acuminator disable once PX1015 IncorrectNumberOfSelectParameters It's acuminator issue: see jira ATR-600
                PXResultset <INItemSiteHistDay> rows = getRows.SelectWindowed(0, MaxRows,
                                                                              siteStatus.SiteID, siteStatus.InventoryID, siteStatus.SubItemID, lastDate);

                lastDate = null;

                foreach (var row in rows)
                {
                    INItemSiteHistDay newRow = row;
                    yield return(newRow);

                    lastDate = newRow.SDate;

                    deadStockQtyCounter -= newRow.QtyDebit ?? 0m;
                    if (deadStockQtyCounter <= 0m)
                    {
                        break;
                    }
                }
            }
        }