[EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Line", 'OnAfterRunWithoutCheck', '', false, false)]
local procedure OnAfterRunWithoutCheck(var GenJnlLine: Record "Gen. Journal Line")
var
Email: Codeunit Email;
EmailMessage: Codeunit "Email Message";
AttachmentInstream: InStream;
ReportSelection: record "Report Selections";
IntDocHeader: Record "Int Document Header";
SalesOrder: Record "Sales Header";
ReportSelectionCustomerRcpt: Record "Report Selections";
AttachmentTempBlob: Codeunit "Temp Blob";
ServerAttachmentFilePath: Text[250];
ReportSelectionUsage: Enum "Report Selection Usage";
RecVar: Variant;
RecordRf: RecordRef;
ToEmailAddress: Text[250];
ToEmailSubject: Text[250];
ToEmailBody: Text[250];
//Convert Quote to Order
SalesQuote: Record "Sales Header";
SalesQuoteToOrder: Codeunit "Sales-Quote to Order";
//API
APIManagement: Codeunit "BWA API Management";
UtopiaAPISetup: Record UtopiaAPISetup;
//Convert Quote to Order
Customer: Record customer;
//IntegrationDocumentLink
IntBusinessProcess: Codeunit "Int Business Process";
CustomerLedgEntries: Record "Cust. Ledger Entry";
begin
//Dummy report to print, to update when new report is ready.
ToEmailAddress := ReportSelection.GetEmailAddressExt(ReportSelectionUsage::"Customer payment receipt".AsInteger(), RecordRf, GenJnlLine."Account No.", ReportSelectionCustomerRcpt);
ToEmailBody := 'Dear Customer, please find attached an acknowledgment of payment receipt';
if ToEmailAddress <> '' then begin
ToEmailSubject := GenJnlLine."Account No." + ' - ' + GenJnlLine.UtopianJobDocNo + ' - ' + FORMAT(ReportSelectionUsage::"Customer payment receipt");
RecordRf.Get(GenJnlLine.RecordId);
RecordRf.SetTable(GenJnlLine);
ReportSelection.BWAGetPdfReportForCust(AttachmentTempBlob, ReportSelectionUsage::"Customer payment receipt", RecordRf, GenJnlLine."Account No.");
EmailMessage.Create(ToEmailAddress, ToEmailSubject, ToEmailBody);
AttachmentTempBlob.CreateInStream(AttachmentInstream);
EmailMessage.AddAttachment('Payment Receipt.pdf', 'pdf', AttachmentInstream);
Email.Send(EmailMessage, Enum::"Email Scenario"::"Customer payment receipt");
end;
end;
end;