Table of Contents

Custom Event

Partners have the possibility to fill the DATEV Exported Attachments table themselves. An event is used for this purpose. This was also programmed with the document attachments as an example to show how a partner has to fill the table fields.

::: Attention In case of incorrect usage, SIEVERS-GROUP does not give any warranty for an error-free DATEV export. :::

/// <summary>
    /// Custom Event for DATEV Attachment files.
    /// Only Tables Database::"Purch. Inv. Header", Database::"Purch. Cr. Memo Hdr.",
    /// Database::"Sales Invoice Header", Database::"Sales Cr.Memo Header",
    /// Database::"Service Invoice Header", Database::"Service Cr.Memo Header"
    /// are allowed for adding document pictures.
    /// Only the following document types are allowed:
    /// "Posted Purchase Invoice", "Posted Purchase Credit Memo",
    /// "Posted Sales Invoice", "Posted Sales Credit Memo",
    /// "Posted Service Invoice", "Posted Service Credit Memo".
    /// You have to fill the following fields:
    ///  "File Name", "File Extension", Content.
    /// Only fill the named fields. Do not insert the entry. There are some checks made on our side to prevent multiple entries.
    /// Only one entry is allowed.
    /// </summary>
    /// <param name="DATEVSetupNo"></param>
    /// <param name="SNCDATEVEntry"></param>
    /// <param name="SNCDATEVExportedAttachment"></param>
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"SNC DATEV Export Attachm. Mgt", 'OnCreateCreateExportAttachmentForCustomSource', '', false, false)]
    local procedure OnCreateCreateExportAttachmentForCustomSourceInDatevExportAttachmentMgt(
        DATEVSetupNo: Code[10];
        SNCDATEVEntry: Record "SNC Datev Entry";
        var SNCDATEVExportedAttachment: Record "SNC DATEV Exported Attachment";
        var IsHandled: Boolean
    )
    var
        SalesInvoiceHeader: Record "Sales Invoice Header";
        DocumentAttachment: Record "Document Attachment";
        DocumentOutStream: OutStream;
    begin
        case SNCDATEVEntry."Attachment Document Type" of
            SNCDATEVEntry."Attachment Document Type"::"Posted Purchase Invoice":
                begin

                end;
            SNCDATEVEntry."Attachment Document Type"::"Posted Purchase Credit Memo":
                begin

                end;
            SNCDATEVEntry."Attachment Document Type"::"Posted Sales Invoice":
                begin
                    // Check if you get the posted document.
                    if not SalesInvoiceHeader.Get(SNCDATEVEntry."Original Document No.") then
                        exit;

                    DocumentAttachment.SetRange("File Type", DocumentAttachment."File Type"::PDF);
                    DocumentAttachment.SetRange("No.", SalesInvoiceHeader."No.");
                    if not DocumentAttachment.FindFirst() then
                        exit;

                    SNCDATEVExportedAttachment.Validate("File Name", DocumentAttachment."File Name");
                    SNCDATEVExportedAttachment.Validate("File Extension", DocumentAttachment."File Extension");
                    SNCDATEVExportedAttachment.Content.CreateOutStream(DocumentOutStream);
                    DocumentAttachment."Document Reference ID".ExportStream(DocumentOutStream);
                    // Do not Insert the entry!
                    IsHandled := true;
                end;
            SNCDATEVEntry."Attachment Document Type"::"Posted Sales Credit Memo":
                begin

                end;
            SNCDATEVEntry."Attachment Document Type"::"Posted Service Invoice":
                begin

                end;
            SNCDATEVEntry."Attachment Document Type"::"Posted Service Credit Memo":
                begin

                end;
        end;
    end;

All three required fields must be filled:

  • File Name (Text[25])
  • File Extension (Text[30])
  • Content (Blob)

No insert must be performed.