处理多张发票并将它们全部显示在一个报告中,例如打印 Invoices/memos 报告在 Acumatica 中的工作方式

Process multiple invoices and show them all in a single report like How Print Invoices/memos report is working in Acumatica

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

为什么我们要创建新的操作按钮,这里我们需要为每张发票(SO 类型)打印不同的格式,这样当用户在网格中选择 3 条不同的记录时 举个例子 1. INV1234 等类型是 TS 然后我需要打印 xyz 报告 2. INV9875 这还没有通过 SO 创建然后我需要打印 ABC 报告 3. CRM4567 and SO type is TS (like above 1 option)

所以这里 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;
            }

提前致谢。

重定向到多个报告或将多个报告合并到一个文档中只能使用方法 PXReportRequiredException.CombineReport

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

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

  2. 在新选项卡中打开每个单独的报告 – ex.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;
}