【问题标题】:Process multiple invoices and show them all in a single report like How Print Invoices/memos report is working in Acumatica处理多张发票并将它们全部显示在一个报告中,例如打印发票/备忘录报告在 Acumatica 中的工作方式
【发布时间】:2020-03-12 18:45:34
【问题描述】:

基本上我想在打印发票和备忘录屏幕上创建一个新的操作按钮,以打印所选发票的报告。

为什么我们要创建新的操作按钮,在这里我们需要为每个发票(SO 类型)打印不同的格式,所以当用户在网格中选择 3 个不同的记录时 举个例子 1. INV1234 等类型是 TS 然后我需要打印 xyz 报告 2. INV9875 这不是通过 SO 创建的,那么我需要打印 ABC 报告 3. CRM4567 和 SO 类型为 TS(如上 1 个选项)

所以这里 1 和 3 应该打印在一页中(就像处理按钮在默认 acumatica 中的工作方式一样) 2 选项报告应在新选项卡中打印。

如果我得到一个示例代码,可以在单页中打印相同的报告,而在另一个选项卡中打印另一个则很好。

下面是代码

public PXAction<PrintInvoicesFilter> PrintReport;
        [PXUIField(DisplayName = "Print Sales Invoice with Price", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
        [PXLookupButton]
        public virtual IEnumerable printReport(PXAdapter adapter, [PXString] string reportID)
        {
            PXReportRequiredException ex = null;

            foreach (ARInvoice doc in Base.ARDocumentList.Cache.Cached)
            {
                var parameters = new Dictionary<string, string>();
                if (doc.Selected == true)
                {
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";

                            if (reportID == "KR501011")
                            {
                                parameters["DocType"] = doc.DocType;
                                parameters["RefNbr"] = doc.RefNbr;
                            }
                            ex = PXReportRequiredException.CombineReport(ex, "KR501011", parameters,false);
                        }
if (TranData.SOOrderType == "RX")
                        {
                            if (reportID == null) reportID = "KR501016";

                            if (reportID == "KR501016")
                            {
                                parameters["DocType"] = doc.DocType;
                                parameters["RefNbr"] = doc.RefNbr;
                            }
                            ex = PXReportRequiredException.CombineReport(ex, "KR501016", parameters,false);
                        }

                        if (string.IsNullOrEmpty(TranData.SOOrderType))
                        {
                            if (reportID == null) reportID = "KR501038";

                            if (reportID == "KR501038")
                            {
                                parameters["DocType"] = doc.DocType;
                                parameters["RefNbr"] = doc.RefNbr;
                            }
                            ex = PXReportRequiredException.CombineReport(ex, "KR501038", parameters,false);
                        }
                    }
                }
            }
if (ex != null)
            {
                ex.Mode = PXBaseRedirectException.WindowMode.New;
                ex.SeparateWindows = false;
                throw ex;
            }

提前致谢。

【问题讨论】:

  • 有人可以帮我一键打印多个报告ID

标签: acumatica acumatica-kb


【解决方案1】:

只能通过PXReportRequiredException.CombineReport方法实现重定向到多个报表或将多个报表合并到一个文档中。

重定向异常有两个选项来控制报告的组合方式:

  1. 将所有报告打印为单个 PDF 文件 - ex.SeparateWindows = false;

  2. 在新选项卡中打开每个单独的报告 – 例如,SeparateWindows = true;

您的要求同时要求 1 和 2,这是不可能的。您只能选择选项 1 或 2。要同时获得这两个选项,您需要两个操作按钮来启动报告。

限制的原因是因为要重定向到报告,您必须抛出异常。一旦抛出异常,您将无法再执行代码来启动新报告。可以打印多个报告,但有一个例外,如下所述,但您必须在同一选项卡(同一文档)中的所有报告或每个选项卡一个报告(每个报告一个文档)之间进行选择。

博客来源:https://asiablog.acumatica.com/2017/03/launch-multiple-reports-with-one-exception.html

来自该博客来源的代码示例:

PXReportRequiredException ex = null;

if(row.ARRefNumber != null)
{
  Dictionary<string, string> dictionary = new Dictionary<string, string>();
  dictionary["DocType"] = row.ARDocType;
  dictionary["RefNbr"] = row.ARRefNumber;
  ex = PXReportRequiredException.CombineReport(ex, row.ARBatchNumber == null ? "AR610500" : "AR622000", dictionary, false);
}

if (row.APRefNumber != null)
{
  APInvoice inv = PXSelectorAttribute.Select<DocHeader.aPRefNumber>(Document.Cache, row) as APInvoice;
  Dictionary<string, string> dictionary = new Dictionary<string, string>();
  dictionary["DocType"] = row.APDocType;
  dictionary["RefNbr"] = row.APRefNumber;
  dictionary["PeriodTo"] = PX.Objects.GL.OpenPeriodAttribute.FormatForDisplay(inv.FinPeriodID);
  dictionary["PeriodFrom"] = PX.Objects.GL.OpenPeriodAttribute.FormatForDisplay(inv.FinPeriodID);
  ex = PXReportRequiredException.CombineReport(ex, row.APBatchNumber == null ? "AP610500" : "AP622000", dictionary, false);
}

if (ex != null)
{
  ex.Mode = PXBaseRedirectException.WindowMode.New;
  ex.SeparateWindows = true;
  throw ex;
}

【讨论】:

  • 我也试过了,但它不适合我,请检查我的代码。
  • 请解释什么不起作用。屏幕上或跟踪窗口中是否有任何错误消息。
  • 我的问题是,我在网格中选择了 4 条记录,然后单击了所选发票中的打印报告新操作 1 属于“KR501011”reportID 2&3 属于“KR501038”reportID,4 属于“KR501011” " reportID,但报告仅打印 1&4 reportID,其余报告值打印空白,其他报告 ID 报告未打印,请帮助我如何使用“KR501038”reportID 在不同选项卡中打印其他 2 个发票。
  • @BhavyaSri 你找到解决方案了吗?很想知道这是否可以解决。
  • 如果报告打印空白,可能是因为传递的参数值。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-14
  • 2011-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-16
相关资源
最近更新 更多