Fast Report - E-Mail Client (Batch) & E-Mail (Native): Difference between revisions
From eStream Software
Line 52: | Line 52: | ||
:02. Enter below Script at the '''First''' line | :02. Enter below Script at the '''First''' line | ||
{| class="mw-collapsible mw-collapsed wikitable" | {| class="mw-collapsible mw-collapsed wikitable" | ||
! E-Mail Script 1 (Last Script Update : | ! E-Mail Script 1 (Last Script Update : 21 Apr 2016) | ||
|- | |- | ||
| | | | ||
<syntaxhighlight lang="delphi"> | <syntaxhighlight lang="delphi"> | ||
//const MaxInt = 2147483647; | //const MaxInt = 2147483647; | ||
var lSQL : String; | var lSQL : String; | ||
Line 89: | Line 89: | ||
SearchStr := Copy(SearchStr, Offset + Length(Patt), MaxInt); | SearchStr := Copy(SearchStr, Offset + Length(Patt), MaxInt); | ||
end; | end; | ||
end; | end; | ||
procedure GetEMailTpl; | procedure GetEMailTpl; | ||
var D : TfrxDataSet; | var D : TfrxDataSet; | ||
Line 97: | Line 97: | ||
D.First; | D.First; | ||
While not D.Eof do begin | While not D.Eof do begin | ||
if Trim(D. | if Trim(D.Value('ReportName')) = Trim(Report.ReportOptions.Name) then | ||
Break; | Break; | ||
D.Next; | D.Next; | ||
Line 103: | Line 103: | ||
end; | end; | ||
function GetFldInfo(const AStr:String):String; | function GetFldInfo(const AStr:String):String; | ||
var D : TfrxDataSet; | var D : TfrxDataSet; | ||
nStr : String; | nStr : String; | ||
lSL : TStringList; | lSL,lPL : TStringList; | ||
i : integer; | i, j : integer; | ||
begin | begin | ||
nStr := AStr; | |||
nStr := AStr; | |||
lSL := TStringList.Create; | lSL := TStringList.Create; | ||
lPL := TStringList.Create; | |||
with lPL do begin //Available Pipeline | |||
Add('Main'); | |||
Add('Profile'); | |||
end; | |||
try | try | ||
D.GetFieldList(lSL); | for j:=0 to lPL.Count -1 do begin | ||
D := Report.GetDataSet(lPL[j]); | |||
D.GetFieldList(lSL); | |||
Result := nStr; | for i:=0 to lSL.Count -1 do | ||
nStr := StringReplace(nStr, '<'+ lPL[j] + '.' + lSL[i] + '>',D.Value(lSL[i])); | |||
end; | |||
Result := nStr; | |||
finally | finally | ||
lSL.Free; | lSL.Free; | ||
end; | lPL.Free; | ||
end; | end; | ||
end; | |||
//For E-Mail Client (Batch) | //For E-Mail Client (Batch) | ||
procedure OnGetEmailSettings(EmailSettings: TStrings); | procedure OnGetEmailSettings(EmailSettings: TStrings); | ||
Line 129: | Line 136: | ||
GetEMailTpl; | GetEMailTpl; | ||
vEmail := Trim(<Document_CompanyBranch."Email">); | vEmail := Trim(<Document_CompanyBranch."Email">); | ||
vName := Trim(<Main."CompanyName">); | vName := Trim(<Main."CompanyName">); | ||
Line 149: | Line 154: | ||
Result := ''; | Result := ''; | ||
vEmail := Trim(<Document_CompanyBranch."Email">); | vEmail := Trim(<Document_CompanyBranch."Email">); | ||
vName := Trim(<Main."CompanyName">); | vName := Trim(<Main."CompanyName">); | ||
Line 167: | Line 170: | ||
:04. Copy below script & paste it between the '''begin''' & '''end;''' in '''procedure SetUp''' | :04. Copy below script & paste it between the '''begin''' & '''end;''' in '''procedure SetUp''' | ||
<syntaxhighlight lang="delphi"> | <syntaxhighlight lang="delphi"> | ||
SQL := 'SELECT B.Description As ReportName, B.Description2 As Subject, B.Description3 As Body | SQL := 'SELECT B.Description As ReportName, B.Description2 As Subject, B.Description3 As Body '+ | ||
' | 'FROM SL_QT A ' + | ||
'INNER JOIN SL_QTDTL B ON (A.Dockey=B.Dockey) ' + | 'INNER JOIN SL_QTDTL B ON (A.Dockey=B.Dockey) ' + | ||
'WHERE A.DocNo=''EMAIL'' '; | 'WHERE A.DocNo=''EMAIL'' '; | ||
AddDataSet('plEMailTpl', ['ReportName', 'Subject', 'Body | AddDataSet('plEMailTpl', ['ReportName', 'Subject', 'Body']) | ||
.GetDBData(SQL); | .GetDBData(SQL); | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 02:41, 21 April 2016
Introduction
By default we got 3 types of Export to E Mail for Fast Report
E-Mail Client
- Pros
- User still can change the E-Mail address, Subject & body (E-Mail Content) before Sent
- Send E-Mail will keep in the Client E-Mail
- Support HTML format
- Can Attach more then 1 format
- Can use without E-Mail Script
- Cons
- Not easy to setup
- Only For Single Document E-Mail
- Attachment only Support pdf, Excel & HTML format
E-Mail Client (Batch)
- Pros
- Can use for Batch & Single Document E-Mail
- Send E-Mail will keep in the Client E-Mail
- Cons
- Not easy to setup
- Only support pdf attachment
- E-Mail Content only support plain text
- User can't change the E-Mail address, Subject & body (E-Mail Content) before Sent
- Must load the E-Mail Script
E-Mail (Native)
- Pros
- Easy to Setup
- Support many attachment format
- User still can change the E-Mail address, Subject & body (E-Mail Content) before Sent
- Can use without E-Mail Script
- Cons
- No record is keeped for Sended E-Mail
- Only For Single Document E-Mail
- E-Mail Content only support plain text
- Only support Single Attachment
Requirement
- Fast Report
- Client E-Mail (eg Mozilla Thunderbird) for E-Mail Client & E-Mail Client (Batch) Only
- An E-Mail Account (eg GMail)
- SQL Accounting Version 731 & above
Setting
Below is example using Sales Invoice
- 01. Click the Code Tab
- 02. Enter below Script at the First line
E-Mail Script 1 (Last Script Update : 21 Apr 2016) |
---|
//const MaxInt = 2147483647;
var lSQL : String;
function StringReplace(const S, OldPattern, NewPattern: string;
iReplaceAll: boolean=true; iIgnoreCase :boolean=true): string;
var
SearchStr, Patt, NewStr: string;
Offset: Integer;
begin
// Usage StringReplace(<Main."DOB">,'/','')
if iIgnoreCase then begin
SearchStr := UpperCase(S);
Patt := UpperCase(OldPattern);
end else begin
SearchStr := S;
Patt := OldPattern;
end;
NewStr := S;
Result := '';
while SearchStr <> '' do begin
Offset := Pos(Patt, SearchStr);
if Offset = 0 then begin
Result := Result + NewStr;
Break;
end;
Result := Result + Copy(NewStr, 1, Offset - 1) + NewPattern;
NewStr := Copy(NewStr, Offset + Length(OldPattern), MaxInt);
if not iReplaceAll then begin
Result := Result + NewStr;
Break;
end;
SearchStr := Copy(SearchStr, Offset + Length(Patt), MaxInt);
end;
end;
procedure GetEMailTpl;
var D : TfrxDataSet;
begin
D := Report.GetDataSet('plEMailTpl');
D.First;
While not D.Eof do begin
if Trim(D.Value('ReportName')) = Trim(Report.ReportOptions.Name) then
Break;
D.Next;
end;
end;
function GetFldInfo(const AStr:String):String;
var D : TfrxDataSet;
nStr : String;
lSL,lPL : TStringList;
i, j : integer;
begin
nStr := AStr;
lSL := TStringList.Create;
lPL := TStringList.Create;
with lPL do begin //Available Pipeline
Add('Main');
Add('Profile');
end;
try
for j:=0 to lPL.Count -1 do begin
D := Report.GetDataSet(lPL[j]);
D.GetFieldList(lSL);
for i:=0 to lSL.Count -1 do
nStr := StringReplace(nStr, '<'+ lPL[j] + '.' + lSL[i] + '>',D.Value(lSL[i]));
end;
Result := nStr;
finally
lSL.Free;
lPL.Free;
end;
end;
//For E-Mail Client (Batch)
procedure OnGetEmailSettings(EmailSettings: TStrings);
var vEmail, vName: Variant;
begin
GetEMailTpl;
vEmail := Trim(<Document_CompanyBranch."Email">);
vName := Trim(<Main."CompanyName">);
if (vName <> '' ) and (vEmail <> '') then begin
EmailSettings.Values['Recipients'] := vEmail;
EmailSettings.Values['Subject'] := GetFldInfo(<plEMailTpl."Subject">);
EmailSettings.Values['Body'] := GetFldInfo(RichTextToPlainText(<plEMailTpl."Body">));
end;
//ID uses for display on progress dialog
EmailSettings.Values['ID'] := vName;
end;
//For E-Mail (Native)
function SQL_Email_GetInfo(Info: Integer): string;
var vEmail, vName: Variant;
begin
GetEMailTpl;
Result := '';
vEmail := Trim(<Document_CompanyBranch."Email">);
vName := Trim(<Main."CompanyName">);
if (vName <> '' ) and (vEmail <> '') then begin
case Info of
SQL_Email_Address: Result := vEmail;
SQL_Email_Subject: Result := GetFldInfo(<plEMailTpl."Subject">);
SQL_Email_Content: Result := GetFldInfo(RichTextToPlainText(<plEMailTpl."Body">));
end;
end;
end;
|
- 03. Scroll down look for procedure SetUp
- 04. Copy below script & paste it between the begin & end; in procedure SetUp
SQL := 'SELECT B.Description As ReportName, B.Description2 As Subject, B.Description3 As Body '+
'FROM SL_QT A ' +
'INNER JOIN SL_QTDTL B ON (A.Dockey=B.Dockey) ' +
'WHERE A.DocNo=''EMAIL'' ';
AddDataSet('plEMailTpl', ['ReportName', 'Subject', 'Body'])
.GetDBData(SQL);
- 05. Click File | Save As... to save the file (eg Sales Invoice 7 (GST 2)-Email)
- 06. Click File | Exit to exit the report design
- 07. Click Design again in the report designer for the file just save on Steps 5 (eg Sales Invoice 7 (GST 2)-Email)
- 08. Click the Code Tab
- 09. Remove the // at the First line of the Script
- 10. Click File | Save to save the file
- 11. Click File | Exit to exit the report design
Quotation
Menu: Sales | Quotation...
SQL Accounting can E Mail by different Subject & E Mail Content by report name
- 01. Create New Quotation with DocNo EMAIL & enter the Detail fields as following
Field Name | Description |
---|---|
Description | Fast Report Name |
Description2 | E-Mail Subject |
Description3 (More Description) | E-Mail Content/Body |
Remark1 | Alternative E-Mail if not Found |
Steps
Below is example using Sales Invoice
Menu: Sales | Invoice...
- 01. Press F6
- 02. Select the Build-in/Customise Fast Report (eg Sales Invoice 7 (GST 2)-Email)
- 03. Click OK
- 04. Click the Arrow for Export (2nd Button from Left)
- 05. Select either 1 of other following from the list
- Export to E-Mail Client
- Export to E-Mail Client (Batch)
- Export to E-Mail (Native)
See also
- Report Designer
- Others Customisation