Delivery note + proforma invoice on the same document

Hello everyone! While I was working with Docentric reports, some doubts have arisen.

Customer requirement is to print a delivery note or both a delivery note and a proforma invoice, based on the value of the mode of delivery of the shipment (condition configured through print management setup).

Our idea is to print two different reports, based on the value of mode of delivery:

  • The first report contains only the delivery note.
  • The second one collapses in a single document both delivery note and pro forma invoice.

My question is: is it possible to create through Docentric a single report that contains both delivery note and pro forma invoice for a shipment?

Thanks for the help,

Flavia

Hi Flavia,
It is possible through Docentric. I assume that you want to include the appropriate delivery note report when printing the proforma sales invoice. Here are suggested steps for doing that:

  1. Save the delivery note report (in PDF format) in the attachment of the related sales order. You can add this manually or use the Docentric feature save to attachment under the file print destination settings. For more information on printing reports in attachments see this link
  2. Subscribe to delegate generateReportContent which is executed whenever the report content is generated using any Docentric print destination, no matter if you are using a SSRS report design or a Docentric template. Here implement your logic for merging proforma invoice as it is shown in this article (topic “the coding part”).

It is possible to skip step 1 (save delivery note report to attachments). This way, in the delegate method, you need to run a delivery note report via code and get a container of the report. Next, merge it with the proforma invoice. Here is a POC showing the merge of sales invoice and project invoice.

class DocMergeSalesInvoiceWithPSAProjInvoice
{
    [SubscribesTo(classStr(DocReportRunDelegates), delegateStr(DocReportRunDelegates, generateReportContent))]
    public static void DocReportRunDelegates_generateReportContent(DocPrintReportSettings _printReportSettings,
        DocPrintedReport _printedReport, DocEventHandlerResult _result)
    {
        // If this is not the SalesInvoice report, return.
        if (_printReportSettings.parmReportId() != ssrsReportStr(SalesInvoice, Report))
            return;
        
        // If report output format is not PDF, return.
        if (_printedReport.outputFileFormat() != DocFileFormat::PDF)
            return;
                
        //if (some condition) -> generate PSAProjInvoice
        container psaProjInvoiceContainer = DocMergeSalesInvoiceWithPSAProjInvoice::printPSAProjInvoiceReportToContainer(_printReportSettings);
        
        // Merge Sales Invoice and PSA Proj Invoice.
        if (psaProjInvoiceContainer)
        {
            System.Byte[] additionalReportPSAProjInvoice = DocGlobalHelper::convertContainerToBytes(psaProjInvoiceContainer);
            System.Byte[] mainReportSalesInvoice = _printedReport.getReportContentByteArray();

            List mergingReportsList = new List(Types::AnyType);

            mergingReportsList.addStart(mainReportSalesInvoice);
            mergingReportsList.addEnd(additionalReportPSAProjInvoice);
        
            // Create the merged PDF file from the document contents saved in the list
            using (System.IO.MemoryStream mergedPDFStream = DocDocumentHelper::mergePdfDocuments(mergingReportsList))
            {
                // Uncomment next line to download the resulting PDF file to the browser
                //DocFileMngHelper::sendFileToUser(mergedPDFStream, 'SalesInvoiceWithProjectInvoice.pdf');

                _printedReport.setReportContentMemoryStream(mergedPDFStream);
            }
        }
    }

    public static container printPSAProjInvoiceReportToContainer(DocPrintReportSettings _printReportSettings)
    {
        PSAProjAndContractInvoiceController controller;
        Args  args;
        ProjInvoiceJour projInvoiceJour;
        
        controller = new PSAProjAndContractInvoiceController();
        args       = new Args();
        
        // Use _printReportSettings.parmArchiveContract() to fetch the corresponding project invoice.
        projInvoiceJour = ProjInvoiceJour::findRecId(5637146255);

        args.record(projInvoiceJour);
        args.parmEnumType(enumNum(PrintCopyOriginal));
        args.parmEnum(PrintCopyOriginal::Original);

        controller.parmArgs(args);
        controller.parmReportName(PrintMgmtDocType::construct(PrintMgmtDocumentType::ProjectInvoice).getDefaultReportFormat());
        
        DocSrsReportGenerator reportGenerator = new DocSrsReportGenerator(controller);

        // TODO: If you want to print PSAProjInvoice using SSRS Report design, uncomment the following line.
        //reportGenerator.setPrintDestinationSettings_SsrsReport(SRSReportFileFormat::PDF);
         
        // TODO: Set settings for generation of the Docentric report using the default Docentric template or provide a specific one.
        reportGenerator.setPrintDestinationSettings_DocentricReport(DocOutputFileFormat::PDF);

        PSAProjPrintInvoice psaProjPrintInvoice = PSAProjPrintInvoice::construct();
        psaProjPrintInvoice.updatePrinterSettingsPrintInvoice(controller.parmReportContract().parmPrintSettings().pack());
        args.caller(psaProjPrintInvoice);

        // Call the initArgs() method via reflection, because it's a protected method.
        new DictClass(classNum(PSAProjAndContractInvoiceController)).callObject(methodStr(PSAProjAndContractInvoiceController, initArgs), controller, args);

        container generatedInvoice = reportGenerator.generateReport();
        
        return generatedInvoice;
    }

}

Please let us know if this helps.
Thank you,
Jovica.

1 Like