var
_CurrentDate: Date;
_CurrentDatePlusthirtyDays: Date;
_CurrentDatePlusFiteenDays: Date;
_CurrentDatePlusTenDays: Date;
_CurrentDtePlusSavenDays: Date;
_CurrentDatePlusOneDay: Date;
_Today: Date;
_employee: Record Employee;
_subject: Text;
_body: Text;
begin
_subject := 'Item Expiration';
_body := 'Dear all recipients, <br>Attached items are about to be expired in 1, 7, 10, 15, or 30 days.';
_CurrentDate := System.Today();
CLEAR(Mail);
i := 1;
EmailSetup.SetFilter(EmployeeId, _employee."No.");
if EmailSetup.FindSet() then begin
repeat
if (EmailSetup."Company E-Mail" <> '') then begin
ToAddr.Add(EmailSetup."Company E-Mail");
end;
until EmailSetup.Next() = 0;
end;
SmtpConf.GET();
Mail.CreateMessage('Business Central Mailing System', SmtpConf."User ID", ToAddr, _subject, _body);
Evaluate(_CurrentDatePlusthirtyDays, Format((_CurrentDate) + 30)); // For thirty days
Evaluate(_CurrentDatePlusFiteenDays, Format((_CurrentDate) + 15)); // For fifteen days
Evaluate(_CurrentDatePlusTenDays, Format((_CurrentDate) + 10)); // For ten days
Evaluate(_CurrentDtePlusSavenDays, Format((_CurrentDate) + 7)); // For 7 days
Evaluate(_CurrentDatePlusOneDay, Format((_CurrentDate) + 1)); // For 1 day
_Today := System.Today;
ItemExp(_CurrentDatePlusthirtyDays, 30);
ItemExp(_CurrentDatePlusFiteenDays, 15);
ItemExp(_CurrentDatePlusTenDays, 10);
ItemExp(_CurrentDtePlusSavenDays, 7);
ItemExp(_CurrentDatePlusOneDay, 1);
ItemExp(_Today, 0);
// For mail send
Mail.Send();
end;
local procedure ItemExp(var transactionDate: Date; Days: Integer)
begin
tbl_item.SetFilter("Grace Time", '%1', transactionDate);
if tbl_item.FindSet() then begin
Clear(Name);
FullName[i] := 'C:\Temp\DDCExpreIn ' + Format(Days) + '.pdf';
Message(FullName[i]);
TempBlob.CreateOutStream(outStreamReportAtc[i], TEXTENCODING::UTF8);
TempBlob.CreateInStream(inStreamReportAtc[i], TEXTENCODING::UTF8);
// Use the Report.SaveAs method to save the report as a PDF file
if Exists('C:\Temp\DDCExpreIn 30.pdf') then
Erase('C:\Temp\DDCExpreIn 30.pdf');
if Exists('C:\Temp\DDCExpreIn 15.pdf') then
Erase('C:\Temp\DDCExpreIn 15.pdf');
if Exists('C:\Temp\DDCExpreIn 10.pdf') then
Erase('C:\Temp\DDCExpreIn 10.pdf');
if Exists('C:\Temp\DDCExpreIn 7.pdf') then
Erase('C:\Temp\DDCExpreIn 7.pdf');
if Exists('C:\Temp\DDCExpreIn 1.pdf') then
Erase('C:\Temp\DDCExpreIn 1.pdf');
if Exists('C:\Temp\DDCExpreIn 0.pdf') then
Erase('C:\Temp\DDCExpreIn 0.pdf');
Content.Create('TestFile' + tbl_item.Description + '.pdf');
Content.CreateOutStream(outStreamReport);
Clear(Rpt_CheckItemExpiration);
Rpt_CheckItemExpiration.SetTableView(tbl_item);
Rpt_CheckItemExpiration.SaveAsPdf(FullName[i]);
Content.Close;
//Clear(Mail);
Mail.AddAttachmentStream(inStreamReportAtc[i], FullName[i]);
i := i + 1;
end;
end;
var
Rpt_CheckItemExpiration: Report CheckItemExpiration;
tbl_item: Record Item;
RecdRef: RecordRef;
Name: Text;
FullName: Array[10] of Text;
outStreamReport: OutStream;
inStreamReport: InStream;
Parameters: Text;
tempBlob: Codeunit "Temp Blob";
// TempBlobb: Record TempBlob temporary;
Base64EncodedString: Text;
Mail: Codeunit "SMTP Mail";
SmtpConf: Record "SMTP Mail Setup";
_CurrentDate: Date;
_CurrentDatePlusthirtyDays: Date;
_CurrentDatePlusFiteenDays: Date;
_CurrentDatePlusTenDays: Date;
XmlParameters: Text;
Content: File;
TempFile: File;
EmailID: Text;
ToAddr: List of [Text];
i: Integer;
ii: Integer;
outStreamReportAtc: Array[10] of OutStream;
inStreamReportAtc: Array[10] of InStream;
txt: Text;