【问题标题】:Invoice and Memos screen Email Invoice/Memo Action in Acumatica发票和备忘录屏幕 Acumatica 中的电子邮件发票/备忘录操作
【发布时间】:2021-03-14 07:08:21
【问题描述】:

我们创建了一些自定义报告,这些报告将根据销售订单类型在详细信息选项卡中打开。当我们使用操作菜单中的电子邮件发票/备忘录操作时,我们希望根据订单类型发送报告。

我们试图覆盖代码,但我们仍然看到默认报告是通过电子邮件发送的。我怎样才能解决这个问题?我的代码如下:

        [PXOverride]
        public PXAction<ARInvoice> sendARInvoiceMemo;
        [PXUIField(DisplayName = "Send AR Invoice/Memo", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
        [PXLookupButton]
        public IEnumerable SendARInvoiceMemo(PXAdapter adapter, String reportID)
        {
            PXReportRequiredException ex = null;

            foreach (ARInvoice doc in adapter.Get<ARInvoice>())
            {
                var parameters = new Dictionary<string, string>();

                ARTran TranData = PXSelectReadonly<ARTran, Where<ARTran.tranType, Equal<Required<ARTran.tranType>>,
                    And<ARTran.refNbr, Equal<Required<ARTran.refNbr>>>>>.Select(Base, doc.DocType, doc.RefNbr);
                if (TranData != null)
                {
                    if (TranData.SOOrderType == "WS" || TranData.SOOrderType == "WO" || TranData.SOOrderType == "TS" || TranData.SOOrderType == "IM")
                    {
                        if (reportID == null) reportID = "KR501011";
                        Dictionary<string, string> mailParams = new Dictionary<string, string>();
                        if (reportID == "KR501011")
                        {
                            mailParams["DocType"] = doc.DocType;
                            mailParams["RefNbr"] = doc.RefNbr;
                            if (!ReportNotificationGenerator.Send(reportID, mailParams).Any())
                            {
                                throw new PXException(ErrorMessages.MailSendFailed);
                            }
                        }
                        Base.Clear();
                        Base.Document.Current = Base.Document.Search<ARInvoice.refNbr>(doc.RefNbr, doc.DocType);
                    }

                    if (TranData.SOOrderType == "RS" || TranData.SOOrderType == "RO" || TranData.SOOrderType == "PS" || TranData.SOOrderType == "QT")
                    {
                        if (reportID == null) reportID = "KR501012";
                        Dictionary<string, string> mailParams = new Dictionary<string, string>();
                        if (reportID == "KR501012")
                        {
                            mailParams["DocType"] = doc.DocType;
                            mailParams["RefNbr"] = doc.RefNbr;
                            if (!ReportNotificationGenerator.Send(reportID, mailParams).Any())
                            {
                                throw new PXException(ErrorMessages.MailSendFailed);
                            }
                        }
                        Base.Clear();
                        Base.Document.Current = Base.Document.Search<ARInvoice.refNbr>(doc.RefNbr, doc.DocType);
                    }
                }
            }           

            if (ex != null) throw ex;

            return adapter.Get();
        }

【问题讨论】:

  • 如果reportID 为空,您似乎只是在分配自定义reportID。您确定此时 reportID 为空吗?

标签: acumatica


【解决方案1】:

注意,没有指定版本,所以我的工作是针对 2020r2 完成的。

SendARInvoiceMemo 不会被“电子邮件发票/备忘录”操作调用。相反,Notification 是该操作的代表。

请注意,通知实际上并不是调用报告 ID,而是依赖于通知 CD 和您的邮件设置来确定要运行的报告。我修改了代码以更改为我创建的名为 INVOICEALT 的新通知 CD。这配置为我的备用报告 ID。

    [PXOverride()]
    [PXUIField(DisplayName = "Notifications", Visible = false)]
    [PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntryF)]
    public virtual IEnumerable Notification(PXAdapter adapter,
    [PXString]
    string notificationCD)
    {
        foreach (ARInvoice doc in adapter.Get().RowCast<ARInvoice>())
        {
            Base.Document.Current = doc;

            Dictionary<string, string> parameters = new Dictionary<string, string>
            {
                ["DocType"] = doc.DocType,
                ["RefNbr"] = doc.RefNbr
            };

            using (var ts = new PXTransactionScope())
            {
                if (ProjectDefaultAttribute.IsProject(Base, doc.ProjectID) && Base.Activity.IsProjectSourceActive(doc.ProjectID, notificationCD))
                {
                    Base.Activity.SendNotification(PMNotificationSource.Project, notificationCD, doc.BranchID, parameters);
                }
                else
                {
                    //Base.Activity.SendNotification(ARNotificationSource.Customer, notificationCD, doc.BranchID, parameters); //This is what was there
                    //Inserted switch based on Sales Order Type >>

                    ARTran TranData = PXSelectReadonly<ARTran, Where<ARTran.tranType, Equal<Required<ARTran.tranType>>,
                        And<ARTran.refNbr, Equal<Required<ARTran.refNbr>>>>>.Select(Base, doc.DocType, doc.RefNbr);
                    switch (TranData.SOOrderType)
                    {
                        case "IN":
                            Base.Activity.SendNotification(ARNotificationSource.Customer, "INVOICEALT", doc.BranchID, parameters);
                            break;
                        default:
                            Base.Activity.SendNotification(ARNotificationSource.Customer, notificationCD, doc.BranchID, parameters);
                            break;
                    }
                    //<< Inserted switch based on Sales Order Type
                }
                Base.Save.Press();

                ts.Complete();
            }

            yield return doc;
        }
    }

作为上述的替代方案,如果您只是在谈论用户运行该操作,您可以隐藏电子邮件发票/备忘录操作并放置一个新操作。

    public PXAction<ARInvoice> sendARInvoiceMemoAlt;
    [PXUIField(DisplayName = "Alt Email Invoice/Memo", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
    [PXLookupButton]
    public IEnumerable SendARInvoiceMemoAlt(PXAdapter adapter, String reportID)
    {
        PXReportRequiredException ex = null;

        foreach (ARInvoice doc in adapter.Get<ARInvoice>())
        {
            var parameters = new Dictionary<string, string>();

            ARTran TranData = PXSelectReadonly<ARTran, Where<ARTran.tranType, Equal<Required<ARTran.tranType>>,
                And<ARTran.refNbr, Equal<Required<ARTran.refNbr>>>>>.Select(Base, doc.DocType, doc.RefNbr);
            if (TranData != null)
            {
                if (TranData.SOOrderType == "SO")// || TranData.SOOrderType == "WS" || TranData.SOOrderType == "WO" || TranData.SOOrderType == "TS" || TranData.SOOrderType == "IM")
                {
                    if (reportID == null) reportID = "AR641000";
                    Dictionary<string, string> mailParams = new Dictionary<string, string>();
                    if (reportID == "AR641000")
                    {
                        mailParams["DocType"] = doc.DocType;
                        mailParams["RefNbr"] = doc.RefNbr;
                        if (!ReportNotificationGenerator.Send(reportID, mailParams).Any())
                        {
                            throw new PXException(ErrorMessages.MailSendFailed);
                        }
                    }
                    Base.Clear();
                    Base.Document.Current = Base.Document.Search<ARInvoice.refNbr>(doc.RefNbr, doc.DocType);
                }

                if (TranData.SOOrderType == "IN")// || TranData.SOOrderType == "RS" || TranData.SOOrderType == "RO" || TranData.SOOrderType == "PS" || TranData.SOOrderType == "QT")
                {
                    if (reportID == null) reportID = "AR641001";
                    Dictionary<string, string> mailParams = new Dictionary<string, string>();
                    if (reportID == "AR641001")
                    {
                        mailParams["DocType"] = doc.DocType;
                        mailParams["RefNbr"] = doc.RefNbr;
                        if (!ReportNotificationGenerator.Send(reportID, mailParams).Any())
                        {
                            throw new PXException(ErrorMessages.MailSendFailed);
                        }
                    }
                    Base.Clear();
                    Base.Document.Current = Base.Document.Search<ARInvoice.refNbr>(doc.RefNbr, doc.DocType);
                }
            }
        }

        if (ex != null) throw ex;

        return adapter.Get();
    }

    public override void Initialize()
    {
        base.Initialize();

        Base.ActionsMenuItem.AddMenuAction(sendARInvoiceMemoAlt);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-12
    • 1970-01-01
    相关资源
    最近更新 更多