//---
action("Send Email")
{
Image = Email;
trigger OnAction()
begin
CurrPage.Update;
noofemails := 0;
emailNote.Reset;
emailNote.SetRange("Price Date", rec."Gas Price Period");
//emailNote.SETRANGE("Email Count",0,salessetup."email count"+5);
emailNote.SETRANGE("Send Email", TRUE);
//emailNote.SETFILTER("Customer No",'BG-CS-10032');
if emailNote.FindSet then begin
repeat
Consmaster.Reset;
Consmaster.SetFilter("Consumer Id", emailNote."Consumer Id");
// Consmaster.SETRANGE(Active,TRUE);
if Consmaster.Find('-') then begin
if Consmaster."E-Mail" <> '' then begin
Clear(cu501);
Message('At gas Price' + emailNote."Consumer Id" + ' Email ' + Consmaster."E-Mail");
SendSalesShipment(emailNote, emailNote."Order No", emailNote."Customer No", emailNote."Price Date", emailNote.Segment, emailNote."Consumer Id");
noofemails := noofemails + 1;
emailNote."Email Count" := emailNote."Email Count" + 1;
emailNote."Email Date" := WorkDate;
emailNote.Modify;
end;
end;
// emailNote.MODIFY;
until emailNote.Next = 0;
end else begin
Error('No Records to send');
end;
Message('Number of Emails Sent ' + Format(noofemails));
end;
}
//---------------
/procedures
//---------
procedure SendSalesShipment(SalesShipmentHeader: Record "BGS_Email Notices"; OrderNo: Code[20]; CustNo: Code[20]; srundate: Date; seg1: Code[20]; ConsNo: Code[20]): Boolean
var
Customer: Record "BGS_Consumer Master2";
EmailBodyFilePath: Text;
FileManagement: Codeunit "File Management";
ReportID: Integer;
BodyLayoutCode: Code[20];
emailrec: Record "BGS_Email Notices";
fromDt: Date;
todt: Date;
begin
Customer.Reset;
Customer.SetFilter("Consumer Id", ConsNo);
if Customer.FindSet then begin
end else begin
exit;
end;
TempEmailItem."Send to" := Customer."CC Email";
TempEmailItem."Send CC" := Customer."CC Email 2";
TempEmailItem."Send BCC" := '';
TempEmailItem."Send to" := Customer."E-Mail";
if Customer."CC Email" <> '' then
TempEmailItem."Send CC" := Customer."CC Email";
if Customer."CC Email 2" <> '' then
TempEmailItem."Send BCC" := Customer."CC Email 2";
ConsName := SalesShipmentHeader."Customer Name";
Consmaster.Reset;
Consmaster.SetFilter("Consumer Id", ConsNo);
if Consmaster.FindSet then
ConsName := Consmaster."Consumer Name";
TempEmailItem.Subject := StrSubstNo(ConsName + ' - Monthly Price Revision for month of ' + Format(srundate, 0, '<Month Text,3> <Year4>'));
fromDt := CalcDate('<-1M>', srundate);
fromDt := CalcDate('-CM', CalcDate('<-1M>', srundate));
emailrec.Reset;
emailrec.SetFilter("Customer No", CustNo);
emailrec.SetFilter("Order No", OrderNo);
emailrec.SetRange("Price Date", srundate);
if emailrec.FindSet then begin
Message('At Code Unit' + emailrec."Consumer Id" + ' Email ' + Consmaster."E-Mail");
if emailrec.Segment = 'BULK' then begin
GetReportIDandLayoutCode(ReportID, BodyLayoutCode, emailrec.Segment);
// "Attachment File Path" := GenerateDocumentEmailAttachment(emailrec, 50001, srundate, OrderNo, CustNo, seg1);
end else begin
GetReportIDandLayoutCode(ReportID, BodyLayoutCode, emailrec.Segment);
// "Attachment File Path" := GenerateDocumentEmailAttachment(emailrec, 50000, srundate, OrderNo, CustNo, seg1);
end;
//"Attachment File Path" := GenerateDocumentEmailAttachment(emailrec,ReportID,srundate,OrderNo,CustNo,seg1);
// "Attachment Name" := StrSubstNo('Monthly Price Note %1', ConsName + '.PDF');
Clear(Rep50000);
if emailrec.Segment <> 'BULK' then begin
Clear(Rep50000);
Rep50000.GetArgs(ConsNo, OrderNo, fromDt, srundate, seg1);
end else begin
Clear(Rep50001);
Rep50001.GetArgs(ConsNo, OrderNo, fromDt, srundate, seg1);
end;
if emailrec.Segment <> 'BULK' then
GenerateShipmentEmailBody(emailrec, 50000, EmailBodyFilePath, BodyLayoutCode, OrderNo, CustNo, srundate, emailrec.Segment)
else
GenerateShipmentEmailBody(emailrec, 50001, EmailBodyFilePath, BodyLayoutCode, OrderNo, CustNo, srundate, emailrec.Segment);
TempEmailItem.Validate(TempEmailItem."Plaintext Formatted", false);
end;
end;
local procedure GenerateShipmentEmailBody(DocumentVariant: Record "BGS_Email Notices"; ReportID: Integer; var BodyFilePath: Text; LayoutCode: Code[20]; Korderno: Code[20]; Kcustno: Code[20]; Krundate: Date; BulkorMMBS: Code[20])
var
FileManagement: Codeunit "File Management";
ReportLayoutSelection: Record "Report Layout Selection";
bemailrec: Record "BGS_Email Notices";
bfromDt: Date;
btodt: Date;
TempBlob_lRec: Codeunit "Temp Blob";
Out: OutStream;
RecRef: RecordRef;
attachment1:File;
//-----------
TempBlob: Codeunit "Temp Blob";
OutStr: OutStream;
InStrm: InStream;
Base64EncodedString: Text;
Base64: Codeunit "Base64 Convert";
//-----------
begin
ReportLayoutSelection.SetTempLayoutSelected(LayoutCode);
bfromDt := CalcDate('<-1M>', Krundate);
Clear(Rep50000);
if BulkorMMBS <> 'BULK' then
Rep50000.GetArgs(Kcustno, Korderno, bfromDt, Krundate, BulkorMMBS)
else
Rep50001.GetArgs(Kcustno, Korderno, bfromDt, Krundate, BulkorMMBS);
bemailrec.Reset;
bemailrec.SetFilter("Customer No", Kcustno);
bemailrec.SetFilter("Order No", Korderno);
bemailrec.SetRange("Price Date", bfromDt, Krundate);
//----------------
TempBlob.CreateOutStream(OutStr);
TempBlob.CreateInStream(InStrm);
//----------------
if bemailrec.FindSet then begin
Message('Here Gas Prices -1');
REPORT.SAVEAS(ReportID, '', REPORTFORMAT::Pdf, Out, RecRef);
Base64EncodedString := Base64.ToBase64('My Message in Gas Prices 50100 ');
end
end;
local procedure GenerateDocumentEmailAttachment(DocumentVariant: Record "BGS_Email Notices"; ReportID: Integer; zdate: Date; zorder: Code[20]; zcust: Code[20]; BM3: Code[20]): Text
var
FileManagement: Codeunit "File Management";
FilePath: Text;
Zemailrec: Record "BGS_Email Notices";
zfromDt: Date;
TempBlob_lRec: Codeunit "Temp Blob";
Out: OutStream;
RecRef: RecordRef;
FileManagement_lCdu: Codeunit "File Management";
begin
// FilePath := CopyStr(FileManagement.ServerTempFileName('pdf'), 1, 250);
zfromDt := CalcDate('<-1M>', zdate);
Zemailrec.Reset;
Zemailrec.SetFilter("Customer No", zcust);
Zemailrec.SetFilter("Order No", zorder);
Zemailrec.SetRange("Price Date", zfromDt, zdate);
if Zemailrec.FindSet then begin
Message('Here Gas Prices');
if Zemailrec.Segment <> 'BULK' then
REPORT.SAVEAS(ReportID, '', REPORTFORMAT::Pdf, Out, RecRef) // save report in TempBlob di recRef
else
REPORT.SAVEAS(ReportID, '', REPORTFORMAT::Pdf, Out, RecRef); // save report in TempBlob di recRef
exit(FilePath);
end;
end;
local procedure GetReportIDandLayoutCode(var ReportID: Integer; var LayoutCode: Code[20]; bulkMMBS: Code[20])
var
ReportSelections: Record "Report Selections";
begin
ReportSelections.SetRange(Usage, ReportSelections.Usage::"C.Statement");
if ReportSelections.FindFirst then
if bulkMMBS <> 'BULK' then begin
ReportID := 50100;
LayoutCode := '50000-000001';
end else begin
ReportID := 50101;
LayoutCode := '50001-000001';
end;
ReportSelections.SetRange("Use for Email Body", true);
// IF ReportSelections.FINDFIRST THEN
// LayoutCode := ReportSelections."Email Body Layout Code";
end;
}
//--------
please help