-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignSalesShipment.Codeunit.al
More file actions
69 lines (59 loc) · 2.89 KB
/
SignSalesShipment.Codeunit.al
File metadata and controls
69 lines (59 loc) · 2.89 KB
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
codeunit 50251 "ABC Sign Sales Shipment" implements "BYD PDF SIG IHandler"
// Your custom interface implementation
// Handles loading PDFs from Sales Shipment reports and saving signed PDFs to Document Attachment
{
var
SalesShipmentHeader: Record "Sales Shipment Header";
TempBlob: Codeunit "Temp Blob";
IsInitialized: Boolean;
HandlerNotInitializedErr: Label 'Sales Shipment Handler is not initialized. Please set the Sales Shipment Header record first.';
HeaderNotExistErr: Label 'Sales Shipment Header %1 does not exist.', Comment = '%1 = Sales Shipment No.';
PDFGenerateErr: Label 'Failed to generate PDF from Sales Shipment report for shipment %1. Error: %2', Comment = '%1 = Sales Shipment No., %2 = Error Text';
SignedFilenameTxt: Label 'Sales_Shipment_%1_Signed.pdf', Comment = '%1 = Sales Shipment No.';
procedure LoadPDF(var PDFStream: InStream): Boolean
var
ReportSelection: Record "Report Selections";
OutStream: OutStream;
begin
Clear(TempBlob);
if not IsInitialized then
Error(HandlerNotInitializedErr);
if not SalesShipmentHeader.Get(SalesShipmentHeader."No.") then
Error(HeaderNotExistErr, SalesShipmentHeader."No.");
SalesShipmentHeader.SetRecFilter();
// Create temporary blob to store the PDF
TempBlob.CreateInStream(PDFStream, TextEncoding::Windows);
TempBlob.CreateOutStream(OutStream, TextEncoding::Windows);
ReportSelection.GetPdfReportForCust(TempBlob, Enum::"Report Selection Usage"::"S.Shipment", SalesShipmentHeader, SalesShipmentHeader."Sell-to Customer No.");
if not TempBlob.HasValue() then
Error(PDFGenerateErr, SalesShipmentHeader."No.", GetLastErrorText());
exit(true);
end;
procedure SavePDF(var PDFStream: InStream): Boolean
var
FileName: Text;
begin
if not IsInitialized then
Error(HandlerNotInitializedErr);
if PDFStream.Length = 0 then
exit(false);
// Generate filename
FileName := StrSubstNo(SignedFilenameTxt, SalesShipmentHeader."No.");
// Save to Document Attachment table
SalesShipmentHeader.Get(SalesShipmentHeader.RecordId());
SalesShipmentHeader."ABC My Signed Document".ImportStream(PDFStream, FileName, 'application/pdf');
SalesShipmentHeader.Modify();
exit(SalesShipmentHeader."ABC My Signed Document".HasValue());
end;
procedure SetSalesShipmentHeader(Rec: Record "Sales Shipment Header")
begin
SalesShipmentHeader := Rec;
IsInitialized := true;
end;
procedure GetSignedFileName(SalesShipmentNo: Code[20]): Text
var
StringConversionManagement: Codeunit StringConversionManagement;
begin
exit(StrSubstNo(SignedFilenameTxt, StringConversionManagement.RemoveNonAlphaNumericCharacters(SalesShipmentNo)));
end;
}