public virtual void SOInvoiceFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            SOInvoiceFilter filter = e.Row as SOInvoiceFilter;

            if (filter != null && !String.IsNullOrEmpty(filter.Action))
            {
                Dictionary <string, object> parameters = Filter.Cache.ToDictionary(filter);
                SOInvoiceList.SetProcessTarget(null, null, null, filter.Action, parameters);

                string actionID = (string)SOInvoiceList.GetTargetFill(null, null, null, Filter.Current.Action, "@ActionName");
                PXUIFieldAttribute.SetVisible <SOInvoiceFilter.showFailedCCCapture>(sender, e.Row, actionID == "CaptureCCPayment");

                bool showPrintSettings = PXAccess.FeatureInstalled <FeaturesSet.deviceHub>() &&
                                         (filter != null && !String.IsNullOrEmpty(filter.Action) && SOReports.GetReportIDByName(SOInvoiceList, filter.Action) == SOReports.PrintInvoiceReport);

                PXUIFieldAttribute.SetVisible <SOInvoiceFilter.printWithDeviceHub>(sender, filter, showPrintSettings);
                PXUIFieldAttribute.SetVisible <SOInvoiceFilter.definePrinterManually>(sender, filter, showPrintSettings);
                PXUIFieldAttribute.SetVisible <SOInvoiceFilter.printerName>(sender, filter, showPrintSettings);

                PXUIFieldAttribute.SetEnabled <SOInvoiceFilter.definePrinterManually>(sender, filter, filter.PrintWithDeviceHub == true);
                PXUIFieldAttribute.SetEnabled <SOInvoiceFilter.printerName>(sender, filter, filter.PrintWithDeviceHub == true && filter.DefinePrinterManually == true);

                if (filter.PrintWithDeviceHub != true || filter.DefinePrinterManually != true)
                {
                    filter.PrinterName = null;
                }
            }
        }
        public virtual void SOInvoiceFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            SOInvoiceFilter filter = e.Row as SOInvoiceFilter;

            if (filter != null && !String.IsNullOrEmpty(filter.Action))
            {
                Dictionary <string, object> parameters = Filter.Cache.ToDictionary(filter);
                SOInvoiceList.SetProcessTarget(null, null, null, filter.Action, parameters);

                string actionID = (string)SOInvoiceList.GetTargetFill(null, null, null, Filter.Current.Action, "@ActionName");
                PXUIFieldAttribute.SetVisible <SOInvoiceFilter.showFailedCCCapture>(sender, e.Row, actionID == "CaptureCCPayment");
                bool showPrintSettings = IsPrintingAllowed(filter);

                PXUIFieldAttribute.SetVisible <SOInvoiceFilter.printWithDeviceHub>(sender, filter, showPrintSettings);
                PXUIFieldAttribute.SetVisible <SOInvoiceFilter.definePrinterManually>(sender, filter, showPrintSettings);
                PXUIFieldAttribute.SetVisible <SOInvoiceFilter.printerID>(sender, filter, showPrintSettings);
                PXUIFieldAttribute.SetVisible <SOInvoiceFilter.numberOfCopies>(sender, filter, showPrintSettings);

                PXUIFieldAttribute.SetEnabled <SOInvoiceFilter.definePrinterManually>(sender, filter, filter.PrintWithDeviceHub == true);
                PXUIFieldAttribute.SetEnabled <SOInvoiceFilter.numberOfCopies>(sender, filter, filter.PrintWithDeviceHub == true);
                PXUIFieldAttribute.SetEnabled <SOInvoiceFilter.printerID>(sender, filter, filter.PrintWithDeviceHub == true && filter.DefinePrinterManually == true);

                if (filter.PrintWithDeviceHub != true || filter.DefinePrinterManually != true)
                {
                    filter.PrinterID = null;
                }
            }
        }
        protected virtual void SOInvoiceFilter_PrinterName_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            SOInvoiceFilter row = (SOInvoiceFilter)e.Row;

            if (row != null)
            {
                if (!IsPrintingAllowed(row))
                {
                    e.NewValue = null;
                }
            }
        }
        public virtual void SOInvoiceFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            SOInvoiceFilter filter = e.Row as SOInvoiceFilter;

            if (filter != null && !String.IsNullOrEmpty(filter.Action))
            {
                Dictionary <string, object> parameters = Filter.Cache.ToDictionary(filter);
                SOInvoiceList.SetProcessTarget(null, null, null, filter.Action, parameters);

                string actionID = (string)SOInvoiceList.GetTargetFill(null, null, null, Filter.Current.Action, "@ActionName");
                PXUIFieldAttribute.SetVisible <SOInvoiceFilter.showFailedCCCapture>(sender, e.Row, actionID == "CaptureCCPayment");
            }
        }
        public virtual IEnumerable soInvoiceList()
        {
            if (Filter.Current.Action == "<SELECT>")
            {
                yield break;
            }

            SOInvoiceFilter filter = Filter.Current;


            string actionID = (string)SOInvoiceList.GetTargetFill(null, null, null, Filter.Current.Action, "@ActionName");

            if (_ActionChanged)
            {
                SOInvoiceList.Cache.Clear();
            }

            foreach (ARInvoice item in SOInvoiceList.Cache.Updated)
            {
                yield return(item);
            }

            PXSelectBase <ARInvoice> cmd;

            switch (actionID)
            {
            case "Release":
                cmd = new PXSelectJoin <ARInvoice,
                                        InnerJoin <SOInvoice, On <SOInvoice.docType, Equal <ARInvoice.docType>, And <SOInvoice.refNbr, Equal <ARInvoice.refNbr> > > >,
                                        Where <ARInvoice.hold, Equal <boolFalse>, And <ARInvoice.released, Equal <boolFalse> > > >(this);
                break;

            case "Post":
                cmd = new PXSelectJoinGroupBy <ARInvoice,
                                               InnerJoin <SOInvoice, On <SOInvoice.docType, Equal <ARInvoice.docType>, And <SOInvoice.refNbr, Equal <ARInvoice.refNbr> > >,
                                                          InnerJoin <SOOrderShipment, On <SOOrderShipment.invoiceType, Equal <ARInvoice.docType>, And <SOOrderShipment.invoiceNbr, Equal <ARInvoice.refNbr> > >,
                                                                     InnerJoin <SOOrderType, On <SOOrderType.orderType, Equal <SOOrderShipment.orderType> >,
                                                                                InnerJoin <ARTran, On <ARTran.tranType, Equal <ARInvoice.docType>, And <ARTran.refNbr, Equal <ARInvoice.refNbr> > >,
                                                                                           LeftJoin <INTran, On <INTran.aRDocType, Equal <ARTran.tranType>, And <INTran.aRRefNbr, Equal <ARTran.refNbr>, And <INTran.aRLineNbr, Equal <ARTran.lineNbr> > > > > > > > >,
                                               Where <ARInvoice.released, Equal <boolTrue>, And <SOOrderType.iNDocType, NotEqual <INTranType.noUpdate>, And <SOOrderShipment.invtRefNbr, IsNull, And <ARTran.lineType, Equal <SOLineType.inventory>, And <INTran.refNbr, IsNull> > > > >,
                                               Aggregate <
                                                   GroupBy <ARInvoice.docType,
                                                            GroupBy <ARInvoice.refNbr,
                                                                     GroupBy <ARInvoice.released> > > > >(this);
                break;

            case "CaptureCCPayment":
                cmd = new PXSelectJoin <ARInvoice,
                                        InnerJoin <SOInvoice, On <SOInvoice.docType, Equal <ARInvoice.docType>, And <SOInvoice.refNbr, Equal <ARInvoice.refNbr> > >,
                                                   InnerJoin <CustomerPaymentMethod, On <CustomerPaymentMethod.pMInstanceID, Equal <SOInvoice.pMInstanceID> >,
                                                              InnerJoin <PaymentMethod, On <PaymentMethod.paymentMethodID, Equal <CustomerPaymentMethod.paymentMethodID>,
                                                                                            And <PaymentMethod.paymentType, Equal <PaymentMethodType.creditCard>,
                                                                                                 And <PaymentMethod.aRIsProcessingRequired, Equal <True> > > > > > >,
                                        Where <SOInvoice.isCCCaptureFailed, Equal <Current <SOInvoiceFilter.showFailedCCCapture> > > >(this);
                break;

            case "CreditHold":
                cmd = new PXSelectJoin <ARInvoice,
                                        InnerJoin <SOInvoice, On <SOInvoice.docType, Equal <ARInvoice.docType>, And <SOInvoice.refNbr, Equal <ARInvoice.refNbr> > >,
                                                   LeftJoin <CustomerPaymentMethod, On <CustomerPaymentMethod.pMInstanceID, Equal <SOInvoice.pMInstanceID> >,
                                                             LeftJoin <PaymentMethod, On <PaymentMethod.paymentMethodID, Equal <CustomerPaymentMethod.paymentMethodID>,
                                                                                          And <PaymentMethod.paymentType, Equal <PaymentMethodType.creditCard>,
                                                                                               And <PaymentMethod.aRIsProcessingRequired, Equal <True> > > > > > >,
                                        Where <PaymentMethod.paymentMethodID, IsNull> >(this);
                break;

            default:
                cmd = new PXSelectJoin <ARInvoice,
                                        InnerJoin <SOInvoice, On <SOInvoice.docType, Equal <ARInvoice.docType>, And <SOInvoice.refNbr, Equal <ARInvoice.refNbr> > > > >(this);
                break;
            }

            cmd.WhereAnd <Where <ARInvoice.docDate, LessEqual <Current <SOInvoiceFilter.endDate> > > >();

            if (filter.StartDate != null)
            {
                cmd.WhereAnd <Where <ARInvoice.docDate, GreaterEqual <Current <SOInvoiceFilter.startDate> > > >();
            }

            if (filter.CustomerID != null)
            {
                cmd.WhereAnd <Where <ARInvoice.customerID, Equal <Current <SOInvoiceFilter.customerID> > > >();
            }

            int startRow  = PXView.StartRow;
            int totalRows = 0;

            foreach (PXResult <ARInvoice, SOInvoice> res in cmd.View.Select(PXView.Currents, null, PXView.Searches, PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows))
            {
                ARInvoice item = res;
                SOInvoice ext  = res;

                object paymentmethod;
                if ((paymentmethod = res[typeof(PaymentMethod)]) != null)
                {
                    item.IsCCPayment = ((PaymentMethod)paymentmethod).ARIsProcessingRequired != null;
                }
                else
                {
                    item.IsCCPayment = false;
                }

                if ((item = (ARInvoice)SOInvoiceList.Cache.Locate(item)) == null || SOInvoiceList.Cache.GetStatus(item) == PXEntryStatus.Notchanged)
                {
                    yield return((ARInvoice)res);
                }

                PXView.StartRow = 0;
            }
        }
        public virtual IEnumerable soInvoiceList()
        {
            if (Filter.Current.Action == "<SELECT>")
            {
                yield break;
            }

            SOInvoiceFilter filter = Filter.Current;


            string actionID = (string)SOInvoiceList.GetTargetFill(null, null, null, Filter.Current.Action, "@ActionName");

            if (_ActionChanged)
            {
                SOInvoiceList.Cache.Clear();
            }

            PXSelectBase <ARInvoice> cmd;

            switch (actionID)
            {
            case "Release":
                cmd = new PXSelectJoin <ARInvoice,
                                        InnerJoinSingleTable <Customer, On <ARInvoice.customerID, Equal <Customer.bAccountID> > >,
                                        Where <ARInvoice.hold, Equal <boolFalse>, And <ARInvoice.origModule, Equal <BatchModule.moduleSO>, And <ARInvoice.released, Equal <boolFalse>, And <Match <Customer, Current <AccessInfo.userName> > > > > > >(this);
                break;

            case "Post":                        // the case is obsolete along with the SOInvoiceEntry.Post action
                cmd = new PXSelectJoinGroupBy <ARInvoice,
                                               InnerJoin <SOOrderShipment, On <SOOrderShipment.invoiceType, Equal <ARInvoice.docType>, And <SOOrderShipment.invoiceNbr, Equal <ARInvoice.refNbr> > >,
                                                          InnerJoin <SOOrderType, On <SOOrderType.orderType, Equal <SOOrderShipment.orderType> >,
                                                                     InnerJoinSingleTable <Customer, On <ARInvoice.customerID, Equal <Customer.bAccountID> > > > >,
                                               Where <ARInvoice.released, Equal <boolTrue>, And <SOOrderType.iNDocType, NotEqual <INTranType.noUpdate>,
                                                                                                 And <ARInvoice.origModule, Equal <BatchModule.moduleSO>,
                                                                                                      And <SOOrderShipment.invtRefNbr, IsNull, And <SOOrderShipment.createINDoc, Equal <boolTrue>,
                                                                                                                                                    And <Match <Customer, Current <AccessInfo.userName> > > > > > > >,
                                               Aggregate <
                                                   GroupBy <ARInvoice.docType,
                                                            GroupBy <ARInvoice.refNbr,
                                                                     GroupBy <ARInvoice.released> > > > >(this);
                break;

            case "CaptureCCPayment":
                cmd = new PXSelectJoin <ARInvoice,
                                        InnerJoin <SOInvoice, On <SOInvoice.docType, Equal <ARInvoice.docType>, And <SOInvoice.refNbr, Equal <ARInvoice.refNbr> > >,
                                                   InnerJoin <CustomerPaymentMethod, On <CustomerPaymentMethod.pMInstanceID, Equal <SOInvoice.pMInstanceID> >,
                                                              InnerJoin <PaymentMethod, On <PaymentMethod.paymentMethodID, Equal <CustomerPaymentMethod.paymentMethodID>,
                                                                                            And <PaymentMethod.paymentType, Equal <PaymentMethodType.creditCard>,
                                                                                                 And <PaymentMethod.aRIsProcessingRequired, Equal <True> > > >,
                                                                         InnerJoinSingleTable <Customer, On <ARInvoice.customerID, Equal <Customer.bAccountID> > > > > >,
                                        Where <SOInvoice.isCCCaptureFailed, Equal <Current <SOInvoiceFilter.showFailedCCCapture> >,
                                               And <SOInvoice.paymentAmt, Greater <decimal0>,
                                                    And <ARInvoice.docType, NotEqual <ARDocType.creditMemo>,
                                                         And2 <Where <SOInvoice.isCCCaptured, NotEqual <True>, Or <Current <SOInvoiceFilter.showFailedCCCapture>, Equal <True> > >,
                                                               And <Match <Customer, Current <AccessInfo.userName> > > > > > > >(this);
                break;

            case "CreditHold":
                cmd = new PXSelectJoin <ARInvoice,
                                        InnerJoin <SOInvoice, On <SOInvoice.docType, Equal <ARInvoice.docType>, And <SOInvoice.refNbr, Equal <ARInvoice.refNbr> > >,
                                                   LeftJoin <CustomerPaymentMethod, On <CustomerPaymentMethod.pMInstanceID, Equal <SOInvoice.pMInstanceID> >,
                                                             LeftJoin <PaymentMethod, On <PaymentMethod.paymentMethodID, Equal <CustomerPaymentMethod.paymentMethodID>,
                                                                                          And <PaymentMethod.paymentType, Equal <PaymentMethodType.creditCard>,
                                                                                               And <PaymentMethod.aRIsProcessingRequired, Equal <True> > > >,
                                                                       InnerJoinSingleTable <Customer, On <ARInvoice.customerID, Equal <Customer.bAccountID> > > > > >,
                                        Where <PaymentMethod.paymentMethodID, IsNull,
                                               And <Match <Customer, Current <AccessInfo.userName> > > > >(this);
                break;

            case "EmailInvoice":
                cmd = new PXSelectJoin <ARInvoice,
                                        InnerJoinSingleTable <Customer, On <ARInvoice.customerID, Equal <Customer.bAccountID> > >,
                                        Where <ARInvoice.dontEmail, Equal <boolFalse>, And <ARInvoice.emailed, Equal <boolFalse>, And <ARInvoice.creditHold, Equal <boolFalse>,
                                                                                                                                       And <ARInvoice.origModule, Equal <BatchModule.moduleSO>,
                                                                                                                                            And <Match <Customer, Current <AccessInfo.userName> > > > > > > >(this);
                break;

            default:
                cmd = new PXSelectJoin <ARInvoice,
                                        InnerJoin <SOInvoice, On <SOInvoice.docType, Equal <ARInvoice.docType>, And <SOInvoice.refNbr, Equal <ARInvoice.refNbr> > >,
                                                   InnerJoinSingleTable <Customer, On <ARInvoice.customerID, Equal <Customer.bAccountID> > > >,
                                        Where <Match <Customer, Current <AccessInfo.userName> > > >(this);
                break;
            }

            cmd.WhereAnd <Where <ARInvoice.docDate, LessEqual <Current <SOInvoiceFilter.endDate> > > >();

            if (filter.StartDate != null)
            {
                cmd.WhereAnd <Where <ARInvoice.docDate, GreaterEqual <Current <SOInvoiceFilter.startDate> > > >();
            }

            if (filter.CustomerID != null)
            {
                cmd.WhereAnd <Where <ARInvoice.customerID, Equal <Current <SOInvoiceFilter.customerID> > > >();
            }

            int startRow  = PXView.StartRow;
            int totalRows = 0;

            CommandPreparing.AddHandler <ARInvoice.docType>(ARInvoiceDocTypeCommandPreparing);
            CommandPreparing.AddHandler <ARInvoice.refNbr>(ARInvoiceRefNbrCommandPreparing);

            foreach (PXResult <ARInvoice> res in cmd.View.Select(PXView.Currents, null, PXView.Searches, PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows))
            {
                ARInvoice item = res;

                object paymentmethod;
                if ((paymentmethod = res[typeof(PaymentMethod)]) != null)
                {
                    item.IsCCPayment = ((PaymentMethod)paymentmethod).ARIsProcessingRequired != null;
                }
                else
                {
                    item.IsCCPayment = false;
                }

                ARInvoice cached = (ARInvoice)SOInvoiceList.Cache.Locate(item);
                if (cached != null)
                {
                    item.Selected = cached.Selected;
                }
                yield return(item);

                PXView.StartRow = 0;
            }

            CommandPreparing.RemoveHandler <ARInvoice.docType>(ARInvoiceDocTypeCommandPreparing);
            CommandPreparing.RemoveHandler <ARInvoice.refNbr>(ARInvoiceRefNbrCommandPreparing);
        }
 public virtual bool IsPrintingAllowed(SOInvoiceFilter filter)
 {
     return(PXAccess.FeatureInstalled <FeaturesSet.deviceHub>() &&
            (filter != null && !String.IsNullOrEmpty(filter.Action) && SOReports.GetReportIDByName(SOInvoiceList, filter.Action) == SOReports.PrintInvoiceReport));
 }