Fast Report - Get Data Directly from DB: Difference between revisions

From eStream Software
Line 7: Line 7:


==Simple Query==
==Simple Query==
===Steps===
===Example 1 - Get Shelf Field from Maintain Item===
Below is example using Sales Invoice to get Shelf field from Maintain Item
Below is Example are doing following actions
* At Sales Invoice to get '''Shelf''' field from '''Maintain Item'''


Last Script Update : 11 Nov 2015
====Steps====
[[File:FR-DirectDB-01.jpg|800 px|center]]
[[File:FR-DirectDB-01.jpg|800 px|center]]
:01. Click the Red A Icon.
:01. Click the Red A Icon.
Line 25: Line 29:
   V := MemDSCache.GetSQLValue(s, 'Code', <Document_Detail."ItemCode">, 'Shelf');                     
   V := MemDSCache.GetSQLValue(s, 'Code', <Document_Detail."ItemCode">, 'Shelf');                     
   if V <> null then                                         
   if V <> null then                                         
     Memo21.Text := V else
     Memo18.Text := V else
     Memo21.Text := '';
     Memo18.Text := '';
end;
end;
</syntaxhighlight>
</syntaxhighlight>
:10. Save the report.
:10. Save the report.


* More Coming Soon....
===Example 2 - Get RefCost Field from Maintain Item===
Below is Example are doing following actions
* Sales Invoice to get '''RefCost''' field from '''Maintain Item'''
* Use '''RefCost * Qty''' in Sales Invoice
 
Last Script Update : 11 Nov 2015
 
====Steps====
:01. Click the Red A Icon.
:02. Click on the place to be print/shown.
:03. Click on '''Events''' tab
:04. Double Click OnBeforePrint
:05. Enter below script
<syntaxhighlight lang="delphi">
procedure Memo18OnBeforePrint(Sender: TfrxComponent);
var s : string;
    V : Variant;                           
begin
  //Get RefCost*Qty
  s := Format('SELECT Code, RefCost FROM ST_ITEM_UOM WHERE Code=%s AND UOM=%s ',
              [QuotedStr(<Document_Detail."ItemCode">),
              QuotedStr(<Document_Detail."UOM">)]);
  V := MemDSCache.GetSQLValue(s, 'Code', <Document_Detail."ItemCode">, 'RefCost');
 
  if V <> null then
    V := V * <Document_Detail."Qty"> else
    V := 0;                     
  Memo18.Text := FormatFloat(<Option."AccountingValueDisplayFormat">, V);
end;
</syntaxhighlight>
:10. Save the report.


==See also==
==See also==

Revision as of 02:31, 11 November 2015

Introduction

Sometime in the report you might wanted some extra information but you not able to select in the report design. So you had to self query to get the extra information.

There are 2 ways to Get the data directly from Database

  • Simple Query
  • Advance Query

Simple Query

Example 1 - Get Shelf Field from Maintain Item

Below is Example are doing following actions

  • At Sales Invoice to get Shelf field from Maintain Item

Last Script Update : 11 Nov 2015

Steps

FR-DirectDB-01.jpg
01. Click the Red A Icon.
02. Click on the place to be print/shown.
03. Click on Events tab
04. Double Click OnBeforePrint
05. Enter below script
procedure Memo18OnBeforePrint(Sender: TfrxComponent);
var s : string;
    V : Variant;                            
begin
  //Get Shelf From ST_Item
  s := Format('SELECT Code, Shelf FROM ST_ITEM WHERE Code=%s ', [QuotedStr(<Document_Detail."ItemCode">)]);    
  V := MemDSCache.GetSQLValue(s, 'Code', <Document_Detail."ItemCode">, 'Shelf');                     
  if V <> null then                                        
    Memo18.Text := V else
    Memo18.Text := '';
end;
10. Save the report.

Example 2 - Get RefCost Field from Maintain Item

Below is Example are doing following actions

  • Sales Invoice to get RefCost field from Maintain Item
  • Use RefCost * Qty in Sales Invoice

Last Script Update : 11 Nov 2015

Steps

01. Click the Red A Icon.
02. Click on the place to be print/shown.
03. Click on Events tab
04. Double Click OnBeforePrint
05. Enter below script
procedure Memo18OnBeforePrint(Sender: TfrxComponent);
var s : string;
    V : Variant;                            
begin
  //Get RefCost*Qty
  s := Format('SELECT Code, RefCost FROM ST_ITEM_UOM WHERE Code=%s AND UOM=%s ',
              [QuotedStr(<Document_Detail."ItemCode">),
               QuotedStr(<Document_Detail."UOM">)]);
  V := MemDSCache.GetSQLValue(s, 'Code', <Document_Detail."ItemCode">, 'RefCost');
  
  if V <> null then
    V := V * <Document_Detail."Qty"> else
    V := 0;                      
  Memo18.Text := FormatFloat(<Option."AccountingValueDisplayFormat">, V);
end;
10. Save the report.

See also