短答案是的,长答案....不容易。
要实现您要求的功能,必须执行以下步骤。
首先在 AR 发票屏幕上创建一个操作,该操作将生成报告、保存并将其附加到文档中。
public class ARInvoiceEntryExtension : PXGraphExtension<ARInvoiceEntry>
{
public PXAction<ARInvoice> exportReport;
[PXUIField(DisplayName = "Export Report")]
[PXButton]
public virtual IEnumerable ExportReport(PXAdapter adapter)
{
//Report Paramenters
Dictionary<String, String> parameters = new Dictionary<String, String>();
parameters["ARInvoice.DocType"] = Base.Document.Current.DocType;
parameters["ARInvoice.RefNbr"] = Base.Document.Current.RefNbr;
//Report Processing
PX.Reports.Controls.Report _report = PXReportTools.LoadReport("AR641000", null);
PXReportTools.InitReportParameters(_report, parameters,
SettingsProvider.Instance.Default);
ReportNode reportNode = ReportProcessor.ProcessReport(_report);
//Generation PDF
byte[] data = PX.Reports.Mail.Message.GenerateReport(reportNode,
ReportProcessor.FilterPdf).First();
PX.SM.FileInfo file = new PX.SM.FileInfo(reportNode.ExportFileName + ".pdf", null, data);
UploadFileMaintenance graph = new UploadFileMaintenance();
graph.SaveFile(file);
PXNoteAttribute.AttachFile(Base.Document.Cache, Base.Document.Current, file);
return adapter.Get();
}
}
其次,您必须创建一个利用 Contract API 的方法来查找发票、触发操作,然后检索附加到文档的文件。
class Program
{
static void Main(string[] args)
{
AcumaticaProcessor processor = new AcumaticaProcessor();
processor.Login();
File[] result = processor.RetrieveReport("Invoice", "001007");
}
}
public class AcumaticaProcessor
{
DefaultSoapClient client = new DefaultSoapClient();
public void Login()
{
client.Login("Username", "Password", "Company", "Branch", null);
}
public File[] RetrieveReport(string docType, string refNbr)
{
ARInvoice invoiceToFind = new ARInvoice()
{
Type = new StringSearch() { Value = docType },
ReferenceNbr = new StringSearch() { Value = refNbr }
};
invoiceToFind = client.Get(invoiceToFind) as ARInvoice;
InvokeResult result = client.Invoke(invoiceToFind, new ExportReport());
return client.GetFiles(invoiceToFind) as File[];
}
}