Skip to content

Extending Reports with the QR Pay

This documentation explains how to extend a report in Business Central with a QR Pay QR-CODE. The QR-Code is automatically generated and added during the report printing or when booking or converting a document.

Procedure

There are two approaches to achieve this:

  1. Custom Reports:
    In custom reports, you can directly integrate the required code into the report.

  2. Standard Reports:
    For standard reports, you can create a report extension that implements the appropriate code.

Please note that there are differences between Word Reports and RDLC Reports that need to be considered during implementation.

Requirements

Before you begin, ensure that the following prerequisites are met:

  • CORE must be referenced in the extension.
  • QR Pay must be referenced in the extension.
  • QR Pay must be activated in the corresponding module setup.

Learn more about creating a Word Layout report in Microsoft Business Central.

Learn more about creating an RDLC Layout report in Microsoft Business Central.

Setup in QR Pay

To ensure correct functionality, the following configurations must be made for the created/extended report in QR Pay:

  • The Report ID and Table Id for the QR Pay Setup Record must be set up.
  • In the QR Pay Module Setup all necessary field should be configured

Modify the Amount value in the QR-Code generation

  1. In this section, we will change the QR-Code Amount with a EventSubscriber.
  2. Create a new .al-file in Visual Studio Code or open an existing .al-file.
  3. Add the following code to the opened file:

    AL
    1
    2
    3
    4
    5
    6
    7
    8
    9
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"SIM_QRP Generation Mgt", 'OnBeforeCalculateAmountEPC', '', false, false)]
    procedure SubOnBeforeCalculateAmountEPC(ParamRecordRef: RecordRef; var ParamAmountDecimal: Decimal; var ParamIshandledBoolean: Boolean)
    var
        NewValue: Decimal;
    begin
        // Calculate custom amount logic here
        ParamAmountDecimal := NewValue;
        ParamIshandledBoolean := true;
    end;
    
    4. Use the RecordRef to calculate the new Amount 5. Set the ParamIshandledBoolean to true if this value should be used

Extending RDLC Reports

  1. In this section, we will add a QR Pay QR-Code to a report of your choice.
  2. Create a new .al-file in Visual Studio Code or open an existing .al-file that extends the desired report.
  3. Add the following code to the opened file:

    AL
    reportextension 5227509 "SIM_QRP Test" extends XXX
    {
        dataset
        {
            add(Header)
            {
                column(SIM_QRPGlobal_Barcode2; GlobalWordRecordSIMCORETempTable."SIM_QRP QR Code")
                { }
                column(SIM_QRPGlobal_BarcodeRDLCText; GlobalBarcodeRDLCText)
                { }
            }
            modify(Header)
            {
                trigger OnAfterAfterGetRecord()
                begin
                    GlobalBarcodeRDLCText := GlobalCodeunitSIMQRPGenerationMgt.FillTempBlobForReport(Header.RecordId, CopyStr(CurrReport.OBJECTID(false), 7), GlobalWordRecordSIMCORETempTable);
                end;
            }
        }
        var
            GlobalWordRecordSIMCORETempTable: Record "SIM_CORE Temp Table";
            GlobalCodeunitSIMQRPGenerationMgt: Codeunit "SIM_QRP Generation Mgt";
            GlobalBarcodeRDLCText: Text;
    }
    
  4. Replace "XXX" with the ID of the report you want to extend (Report 1306 "Standard Sales - Invoice and 117 Reminder are extended in the standard of QR Pay already).

  5. Publish the extension.
  6. Open Report Layouts in Business Central.
  7. Find the layout you want to extend and click "Update and Download Layout".
  8. Open the downloaded layout file.
  9. Add an image by selecting "Insert" -> "Picture".
  10. Position the added image where you want the barcode to appear.
  11. Right-click on the image and select "Image Properties".
  12. Make the following adjustments in the "Image Properties" dialog:
    • General:
      • Name: Barcode
      • Image Source: Database
      • Field to Use: =System.Convert.FromBase64String(Fields!SIM_QRPGlobal_BarcodeRDLCText.Value)
      • MIME Type: image/bmp
    • Size:
      • Display: Resize proportionally
    • Visibility:
      • Expression: =IsNothing(Fields!SIM_QRPGlobal_BarcodeRDLCText.Value) OR (Globals!PageNumber>1)
  13. Save the edited .rdl file.
  14. Go back to Report Layouts in Business Central and add the edited layout:
    • Select "New" to add a new layout, and upload the edited file.
    • Alternatively, you can replace the existing layout with the edited file.
  15. Link the report to the newly created layout.
  16. When you print the report, the barcode should be displayed correctly.

Extending Word Reports

  1. In this section, we will add a QR Pay QR-Code to a report of your choice.
  2. Create a new .al-file in Visual Studio Code or open an existing .al-file that extends the desired report.
  3. Add the following code to the opened file:

    AL
    reportextension 5227509 "SIM_QRP Test" extends XXX
    {
        dataset
        {
            add(Header)
            {
                column(SIM_QRPGlobal_Barcode2; GlobalWordRecordSIMCORETempTable."SIM_QRP QR Code")
                { }
                column(SIM_QRPGlobal_BarcodeRDLCText; GlobalBarcodeRDLCText)
                { }
            }
            modify(Header)
            {
                trigger OnAfterAfterGetRecord()
                begin
                    GlobalBarcodeRDLCText := GlobalCodeunitSIMQRPGenerationMgt.FillTempBlobForReport(Header.RecordId, CopyStr(CurrReport.OBJECTID(false), 7), GlobalWordRecordSIMCORETempTable);
                end;
            }
        }
        var
            GlobalWordRecordSIMCORETempTable: Record "SIM_CORE Temp Table";
            GlobalCodeunitSIMQRPGenerationMgt: Codeunit "SIM_QRP Generation Mgt";
            GlobalBarcodeRDLCText: Text;
    }
    
  4. Replace "XXX" with the ID of the report you want to extend (Report 1306 "Standard Sales - Invoice and 117 Reminder are extended in the standard of QR Pay already).

  5. Publish the extension.
  6. Open the Word file of the report.
  7. Navigate to the "Developer" tab in the Word document and select "XML Mapping Pane".
    1. Right-click on "Global_Barcode".
    2. Select "Insert Content Control" and then "Picture".
  8. Position the picture where you want the barcode to appear in the document.
  9. Save the Word file.
  10. Go back to Business Central and upload the Word file as a layout.
  11. Link the edited layout to the corresponding report.
  12. When printing this report, the barcode will now be output.

See also