If you need to generate a SSRS report as a byte array, you can use a utility X++ class DocSrsReportGenerator, which is delivered with Docentric Free Edition. Learn more >>
However, this class cannot be used for proforma scenario. Printing Sales invoice proforma can be done via the SalesFormLetter class. To generate a proforma as byte array, we will use Docentric Memory print destination and the DocReportRunDelegates.printToMemoryEnd delegate. Please note that you can also use any other Docentric print destination instead if needed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
class DocExamplePrintSalesInvoiceProforma { public static void main(Args _args) { DocExamplePrintSalesInvoiceProforma::printSalesInvoiceProforma(); } public static void printSalesInvoiceProforma() { SalesFormLetter salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice); SalesParmLine parmLine; SalesLine salesline; SalesTable salesTable; SRSPrintDestinationSettings pds; salesTable = SalesTable::find('000985'); salesFormLetter.salesTable(salesTable); salesFormLetter.transDate(systemDateGet()); salesFormLetter.specQty(SalesUpdate::All); salesFormLetter.proforma(true); salesFormLetter.printFormLetter(true); salesFormLetter.usePrintManagement(false); // To generate a proforma as byte array, you can use Docentric Memory print destination. // Note that you can use any other print destination as well, e.g. Docentric Printer, which will // result in distributing proforma report to this destination, e.g. to the selected network printer. pds = new SRSPrintDestinationSettings(); pds.printMediumType(SRSPrintMediumType::Memory_DC); // Use the default Docentric design. pds.parmMemoryPrintDestSettings_DC().parmUseSsrsBuiltInDesign(false); pds.parmSrsPrintReportSettings_DC().setProperty_PrintSrsOriginalDesign(false); pds.parmMemoryPrintDestSettings_DC().parmOutputFileFormat(DocOutputFileFormat::PDF); /* Uncomment this code if you want to use the original SSRS design instead */ //pds.parmMemoryPrintDestSettings_DC().parmOutputFileFormatSrs(SRSReportFileFormat::PDF); //pds.parmMemoryPrintDestSettings_DC().parmUseSsrsBuiltInDesign(true); //pds.parmSrsPrintReportSettings_DC().setProperty_PrintSrsOriginalDesign(true); salesFormLetter.updatePrinterSettingsFormLetter(pds.pack()); salesFormLetter.initParmSalesTable(salesTable); salesFormLetter.initParameters(salesFormLetter.salesParmUpdate(), Printout::Current); salesFormLetter.initLinesQuery(); salesFormLetter.run(); } // Use the following delegate to get the report content as byte array when printing to Docentric Memory print destination. [SubscribesTo(classStr(DocReportRunDelegates), delegateStr(DocReportRunDelegates, printToMemoryEnd))] public static void DocReportRunDelegates_printToMemoryEnd(DocPrintReportSettings _printReportSettings, DocPrintDestSettingsMemory _memoryPrintDestSettings, DocPrintReportToMemoryExecutionInfo _memoryExecutionInfo, DocEventHandlerResult _result) { // Check if the printing report is Sales invoice. if (_printReportSettings.parmReportId() == ssrsReportStr(SalesInvoice, Report)) { // Check if this is a proforma. SalesInvoiceContract reportContract = _printReportSettings.parmSrsReportContract().parmRdpContract(); RecId journalRecId = reportContract.parmRecordId(); if (!CustInvoiceJour::findRecId(journalRecId)) { // Check if the document has been successfully generated. if (_memoryExecutionInfo.isExecutionSuccessful()) { // Use the generated document as byte array or memory stream as needed. // We'll just send the file for download in browser. str invoiceId = _printReportSettings.parmArchiveContract().parmDocumentId(); str filename = strFmt('%1 %2.%3', 'SalesInvoiceProforma', invoiceId, _memoryPrintDestSettings.getResolvedOutputFileType()); DocFileMngHelper::sendFileToUser(_memoryExecutionInfo.getReportContentAsMemoryStream(), filename); } } } } // Use the following delegate to get the report content as byte array when printing to any print destination. [SubscribesTo(classStr(DocReportRunDelegates), delegateStr(DocReportRunDelegates, generateReportContent))] public static void DocReportRunDelegates_generateReportContent(DocPrintReportSettings _printReportSettings, DocPrintedReport _printedReport, DocEventHandlerResult _result) { // Check if the executing report is Sales invoice printed to Docentric Memory print destination. if (_printReportSettings.parmPrintDestination() == DocPrintDestination::Memory && _printReportSettings.parmReportId() == ssrsReportStr(SalesInvoice, Report)) { // Check if this is a proforma. SalesInvoiceContract reportContract = _printReportSettings.parmSrsReportContract().parmRdpContract(); RecId journalRecId = reportContract.parmRecordId(); if (!CustInvoiceJour::findRecId(journalRecId)) { // Use the generated document as byte array or memory stream as needed. // We'll just send the file for download in browser. str invoiceId = _printReportSettings.parmArchiveContract().parmDocumentId(); str filename = strFmt('%1 %2.%3', 'SalesInvoiceProforma', invoiceId, _printedReport.getOutputFileFormat()); DocFileMngHelper::sendFileToUser(_printedReport.getReportContentMemoryStream(), filename); } } } } |