private void ApplyFilters(PXSelectBase <CCProcTran> query)
        {
            CCPaymentFilter filter = this.Filter.Current;

            if (!string.IsNullOrEmpty(filter.ProcessingCenterID))
            {
                query.WhereAnd <Where <CCProcTran.processingCenterID, Equal <Current <CCPaymentFilter.processingCenterID> > > >();
            }

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

            if (filter.CustomerID.HasValue)
            {
                query.WhereAnd <Where <Customer.bAccountID, Equal <Current <CCPaymentFilter.customerID> > > >();
            }

            if (filter.DisplayType == DisplayTypes.Failed)
            {
                query.Join <LeftJoin <CCProcTranH, On <CCProcTranH.docType, Equal <CCProcTran.docType>,
                                                       And <CCProcTranH.refNbr, Equal <CCProcTran.refNbr>,
                                                            And <CCProcTranH.tranNbr, Greater <CCProcTran.tranNbr> > > > > >();
                query.WhereAnd <Where <CCProcTranH.tranNbr, IsNull,
                                       And <Where <CCProcTran.tranStatus, NotEqual <CCTranStatusCode.approved>,
                                                   Or <CCProcTran.tranStatus, IsNull> > > > >();
            }
        }
        protected virtual void CCPaymentFilter_EndDate_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            CCPaymentFilter row = (CCPaymentFilter)e.Row;

            if (row.BeginDate.HasValue && row.EndDate.HasValue && row.EndDate.Value < row.BeginDate.Value)
            {
                row.BeginDate = row.EndDate;
            }
        }
        public virtual IEnumerable paymentTrans()
        {
            CCPaymentFilter filter = this.Filter.Current;

            if (filter != null)
            {
                PXSelectBase <CCProcTran> qCpmExists = new PXSelectJoin <CCProcTran,
                                                                         InnerJoin <CustomerPaymentMethod, On <CustomerPaymentMethod.pMInstanceID, Equal <CCProcTran.pMInstanceID> >,
                                                                                    LeftJoin <ARRegister, On <CCProcTran.refNbr, Equal <ARRegister.refNbr>,
                                                                                                              And <CCProcTran.docType, Equal <ARRegister.docType> > >,
                                                                                              InnerJoin <Customer, On <Customer.bAccountID, Equal <CustomerPaymentMethod.bAccountID> > > > >,
                                                                         Where <CCProcTran.startTime, GreaterEqual <Required <CCPaymentFilter.beginDate> >,
                                                                                And <CCProcTran.startTime, LessEqual <Required <CCPaymentFilter.endDate> > > > >(this);

                PXSelectBase <CCProcTran> qCpmNotExists = new PXSelectJoin <CCProcTran,
                                                                            LeftJoin <CustomerPaymentMethod, On <CustomerPaymentMethod.pMInstanceID, Equal <CCProcTran.pMInstanceID> >,
                                                                                      InnerJoin <ARRegister, On <CCProcTran.refNbr, Equal <ARRegister.refNbr>,
                                                                                                                 And <CCProcTran.docType, Equal <ARRegister.docType> > >,
                                                                                                 InnerJoin <Customer, On <Customer.bAccountID, Equal <ARRegister.customerID> > > > >,
                                                                            Where <CCProcTran.startTime, GreaterEqual <Required <CCPaymentFilter.beginDate> >,
                                                                                   And <CCProcTran.startTime, LessEqual <Required <CCPaymentFilter.endDate> >,
                                                                                        And <CCProcTran.pMInstanceID, Equal <PaymentTranExtTypes.NewPaymentProfile> > > > >(this);

                ApplyFilters(qCpmExists);
                ApplyFilters(qCpmNotExists);

                if (filter.EndDate != null)
                {
                    var result = qCpmExists.Select(filter.BeginDate, filter.EndDate.Value.AddDays(1));
                    result.AddRange(qCpmNotExists.Select(filter.BeginDate, filter.EndDate.Value.AddDays(1)));
                    foreach (PXResult <CCProcTran, CustomerPaymentMethod, ARRegister, Customer> it in result)
                    {
                        ARRegister doc    = it;
                        CCProcTran ccTran = it;
                        if (ccTran.TranType == CCTranTypeCode.Credit || ccTran.TranType == CCTranTypeCode.VoidTran)
                        {
                            ARRegister voiding = PXSelect <ARRegister, Where <ARRegister.refNbr, Equal <Required <ARRegister.refNbr> >,
                                                                              And <ARRegister.docType, Equal <ARDocType.voidPayment> > > > .Select(this, doc.RefNbr);

                            if (voiding != null)
                            {
                                doc.DocType = ARDocType.VoidPayment;
                            }
                        }
                        yield return(it);
                    }
                }
            }
            yield break;
        }
        public virtual IEnumerable paymentTrans()
        {
            CCPaymentFilter filter = this.Filter.Current;

            if (filter != null)
            {
                PXSelectBase <CCProcTran> select = new PXSelectJoin <CCProcTran,
                                                                     InnerJoin <CustomerPaymentMethod, On <CustomerPaymentMethod.pMInstanceID, Equal <CCProcTran.pMInstanceID> >,
                                                                                InnerJoin <Customer, On <Customer.bAccountID, Equal <CustomerPaymentMethod.bAccountID> >,
                                                                                           LeftJoin <ARPayment, On <CCProcTran.refNbr, Equal <ARPayment.refNbr>,
                                                                                                                    And <CCProcTran.docType, Equal <ARPayment.docType> > >,
                                                                                                     //LeftJoin<Customer, On<ARPayment.customerID, Equal<Customer.bAccountID>>,
                                                                                                     LeftJoin <CCProcTranH, On <CCProcTranH.docType, Equal <CCProcTran.docType>,
                                                                                                                                And <CCProcTranH.refNbr, Equal <CCProcTran.refNbr>,
                                                                                                                                     And <CCProcTranH.tranNbr, Greater <CCProcTran.tranNbr> > > > > > > >,
                                                                     Where <CCProcTran.startTime, GreaterEqual <Required <CCPaymentFilter.beginDate> >,
                                                                            And <CCProcTran.startTime, LessEqual <Required <CCPaymentFilter.endDate> > > >,
                                                                     OrderBy <Desc <ARPayment.refNbr> > >(this);

                if (!string.IsNullOrEmpty(filter.ProcessingCenterID))
                {
                    select.WhereAnd <Where <CCProcTran.processingCenterID, Equal <Current <CCPaymentFilter.processingCenterID> > > >();
                }

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

                if (filter.CustomerID.HasValue)
                {
                    select.WhereAnd <Where <Customer.bAccountID, Equal <Current <CCPaymentFilter.customerID> > > >();
                }

                if (filter.DisplayType == DisplayTypes.Failed)
                {
                    select.WhereAnd <Where <CCProcTranH.tranNbr, IsNull,
                                            And <Where <CCProcTran.tranStatus, NotEqual <CCTranStatusCode.approved>,
                                                        Or <CCProcTran.tranStatus, IsNull> > > > >();
                }
                if (filter.EndDate != null)
                {
                    foreach (PXResult <CCProcTran, CustomerPaymentMethod, Customer, ARPayment, CCProcTranH> it in select.Select(filter.BeginDate, filter.EndDate.Value.AddDays(1)))
                    {
                        ARPayment  payment = it;
                        CCProcTran ccTran  = it;
                        if (ccTran.TranType == CCTranTypeCode.Credit || ccTran.TranType == CCTranTypeCode.VoidTran)
                        {
                            ARPayment voiding = PXSelect <ARPayment, Where <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> >,
                                                                            And <ARPayment.docType, Equal <ARDocType.voidPayment> > > > .Select(this, payment.RefNbr);

                            if (voiding != null)
                            {
                                ((ARPayment)it).DocType = ARDocType.VoidPayment;
                            }
                        }
                        yield return(it);
                    }
                }
            }
            yield break;
        }