protected virtual IEnumerable history()
        {
            this.History.Cache.Clear();

            ARStatementHistoryParameters header = Filter.Current;

            if (header == null)
            {
                yield break;
            }

            int?          prevCustomerID = null;
            string        prevCuryID     = null;
            HistoryResult prevRec        = null;

            PXResultset <ARStatement> res;
            List <object>             stored = new List <object>();

            PXSelectBase <ARStatement> select = new PXSelectJoin <ARStatement,
                                                                  LeftJoin <ARStatementCycle, On <ARStatementCycle.statementCycleId, Equal <ARStatement.statementCycleId> >,
                                                                            LeftJoin <Customer, On <Customer.bAccountID, Equal <ARStatement.statementCustomerID> > > >,
                                                                  Where <ARStatement.statementCustomerID, Equal <ARStatement.customerID>,
                                                                         And <ARStatement.statementDate, GreaterEqual <Required <ARStatement.statementDate> >,
                                                                              And <ARStatement.statementDate, LessEqual <Required <ARStatement.statementDate> >,
                                                                                   And <Where <ARStatement.statementCycleId, Equal <Required <ARStatement.statementCycleId> >,
                                                                                               Or <Required <ARStatement.statementCycleId>, IsNull> > > > > >,
                                                                  OrderBy <Asc <ARStatement.statementCycleId,
                                                                                Asc <ARStatement.statementDate,
                                                                                     Asc <ARStatement.customerID,
                                                                                          Asc <ARStatement.curyID> > > > > >(this);

            using (new PXFieldScope(select.View,
                                    typeof(ARStatement.branchID),
                                    typeof(ARStatement.statementCycleId),
                                    typeof(ARStatement.statementDate),
                                    typeof(ARStatement.customerID),
                                    typeof(ARStatement.statementCustomerID),
                                    typeof(ARStatement.curyID),
                                    typeof(ARStatement.dontPrint),
                                    typeof(ARStatement.dontEmail),
                                    typeof(ARStatement.printed),
                                    typeof(ARStatement.emailed),

                                    typeof(ARStatementCycle.descr),
                                    typeof(Customer.printCuryStatements)))
            {
                res = select.Select(header.StartDate, header.EndDate, header.StatementCycleId, header.StatementCycleId);
            }

            foreach (PXResult <ARStatement, ARStatementCycle, Customer> item in res)
            {
                stored.Add(item);

                ARStatement      st    = item;
                ARStatementCycle cycle = item;
                Customer         cust  = item;
                HistoryResult    rec   = new HistoryResult
                {
                    StatementCycleId = st.StatementCycleId,
                    StatementDate    = st.StatementDate,
                    Descr            = cycle.Descr,
                    DontPrintCount   = 0,
                    DontEmailCount   = 0,
                    PrintedCount     = 0,
                    EmailedCount     = 0,
                    NoActionCount    = 0
                };

                rec = (HistoryResult)this.History.Cache.Locate(rec) ?? this.History.Insert(rec);
                if (rec != null)
                {
                    if (prevRec != rec)
                    {
                        prevCustomerID = null; prevCuryID = null;
                    }
                    if (prevCustomerID != st.CustomerID || (cust.PrintCuryStatements == true && prevCuryID != st.CuryID))
                    {
                        rec.NumberOfDocuments += 1;
                        rec.DontPrintCount    += st.DontPrint == true ? 1 : 0;
                        rec.DontEmailCount    += st.DontEmail == true ? 1 : 0;
                        rec.NoActionCount     += st.DontEmail == true && st.DontPrint == true ? 1 : 0;
                        rec.PrintedCount      += st.Printed == true ? 1 : 0;
                        rec.EmailedCount      += st.Emailed == true ? 1 : 0;
                    }

                    prevRec        = rec;
                    prevCustomerID = st.CustomerID;
                    prevCuryID     = st.CuryID;
                }
            }

            select.StoreCached(new PXCommandKey(new object[] { header.StartDate, header.EndDate, header.StatementCycleId, header.StatementCycleId }), stored);

            this.History.Cache.IsDirty = false;
            foreach (HistoryResult ret in this.History.Cache.Inserted)
            {
                yield return(ret);
            }
        }