//Where<CustomerPaymentMethod.expirationDate, GreaterEqual<Current<ARExpiringCardFilter.beginDate>>,
        //And<CustomerPaymentMethod.expirationDate, LessEqual<Current<ARExpiringCardFilter.endDate>>,
        //And<CustomerPaymentMethod.isActive, Equal<BQLConstants.BitOn>,
        ////Or<Current<ARExpiringCardFilter.activeOnly>,Equal<BQLConstants.BitOff>>>,
        //And<Where<Customer.customerClassID,Equal<Current<ARExpiringCardFilter.customerClassID>>,
        //Or<Current<ARExpiringCardFilter.customerClassID>, IsNull>>>>>>> Cards;

        public virtual IEnumerable cards()
        {
            ARExpiringCardFilter filter = this.Filter.Current;

            if (filter != null)
            {
                PXSelectBase <CustomerPaymentMethod> select = new PXSelectJoin <CustomerPaymentMethod,
                                                                                InnerJoin <Customer, On <Customer.bAccountID, Equal <CustomerPaymentMethod.bAccountID> >,
                                                                                           LeftJoin <CR.Contact, On <CR.Contact.bAccountID, Equal <Customer.bAccountID>,
                                                                                                                     And <CR.Contact.contactID, Equal <Customer.defBillContactID> > > > >,
                                                                                Where <CustomerPaymentMethod.expirationDate, GreaterEqual <Required <CustomerPaymentMethod.expirationDate> >,
                                                                                       And <CustomerPaymentMethod.expirationDate, LessEqual <Required <CustomerPaymentMethod.expirationDate> > > > >(this);

                if (!string.IsNullOrEmpty(filter.CustomerClassID))
                {
                    select.WhereAnd <Where <Customer.customerClassID, Equal <Required <Customer.customerClassID> > > >();
                }

                if ((bool)filter.ActiveOnly)
                {
                    select.WhereAnd <Where <CustomerPaymentMethod.isActive, Equal <BQLConstants.BitOn> > >();
                }

                return(select.Select(filter.BeginDate, filter.EndDate, filter.CustomerClassID));
            }
            return(null);
        }
        public virtual IEnumerable cards()
        {
            ARExpiringCardFilter filter = this.Filter.Current;

            if (filter != null)
            {
                PXSelectBase <CustomerPaymentMethod> select = null;
                select = new PXSelectJoin <CustomerPaymentMethod,
                                           InnerJoin <Customer, On <Customer.bAccountID, Equal <CustomerPaymentMethod.bAccountID>,
                                                                    And <Customer.status, NotEqual <BAccount.status.inactive> > >,
                                                      LeftJoin <CR.Contact, On <CR.Contact.bAccountID, Equal <CustomerPaymentMethod.bAccountID>,
                                                                                And <Where2 <Where <CustomerPaymentMethod.billContactID, IsNull,
                                                                                                    And <CR.Contact.contactID, Equal <Customer.defBillContactID> > >,
                                                                                             Or <Where <CustomerPaymentMethod.billContactID, IsNotNull,
                                                                                                        And <CustomerPaymentMethod.billContactID, Equal <CR.Contact.contactID> > > > > > > > >,
                                           Where <CustomerPaymentMethod.expirationDate, GreaterEqual <Required <CustomerPaymentMethod.expirationDate> >,
                                                  And <CustomerPaymentMethod.expirationDate, LessEqual <Required <CustomerPaymentMethod.expirationDate> > > > >(this);

                if (!string.IsNullOrEmpty(filter.CustomerClassID))
                {
                    select.WhereAnd <Where <Customer.customerClassID, Equal <Required <Customer.customerClassID> > > >();
                }

                if (filter.DefaultOnly == true)
                {
                    select.WhereAnd <Where <CustomerPaymentMethod.pMInstanceID, Equal <Customer.defPMInstanceID> > >();
                }
                if ((bool)filter.ActiveOnly)
                {
                    select.WhereAnd <Where <CustomerPaymentMethod.isActive, Equal <BQLConstants.BitOn> > >();
                }
                foreach (PXResult <CustomerPaymentMethod, Customer, Contact> it in select.Select(filter.BeginDate, filter.EndDate, filter.CustomerClassID, filter.ActiveOnly))
                {
                    CustomerPaymentMethod cpm = (CustomerPaymentMethod)it;
                    if (cpm.LastNotificationDate.HasValue && cpm.ExpirationDate.HasValue)
                    {
                        TimeSpan diff = cpm.ExpirationDate.Value - cpm.LastNotificationDate.Value;
                        if (diff.TotalDays > 0)
                        {
                            if (diff.TotalDays < filter.NoteLeftLimit)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (Math.Abs(diff.TotalDays) < filter.NoteRightLimit)
                            {
                                continue;
                            }
                        }
                    }

                    yield return(it);
                }
            }
            yield break;
        }
        public virtual void ARExpiringCardFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            ARExpiringCardFilter row = e.Row as ARExpiringCardFilter;

            if (row == null)
            {
                return;
            }
            PXUIFieldAttribute.SetEnabled <CustomerPaymentMethod.selected>(this.Cards.Cache, null, true);
            if (row.TokenizedPMs == null)
            {
                string pmString = CCProcessingHelper.GetTokenizedPMsString(this);
                sender.SetValue <ARExpiringCardFilter.tokenizedPMs>(row, pmString);
            }
            else
            {
                if (row.TokenizedPMs != String.Empty)
                {
                    Filter.Cache.RaiseExceptionHandling <ARExpiringCardFilter.customerClassID>(e.Row, ((ARExpiringCardFilter)e.Row).CustomerClassID,
                                                                                               new PXSetPropertyException(Messages.NotAllCardsShown,
                                                                                                                          PXErrorLevel.Warning, row.TokenizedPMs));
                }
            }
        }