Commit d7e3aa71 by Mac Stephens

Still progressing, report is now loading rows dynamically

parent 0565250e
......@@ -82,7 +82,6 @@ type
[async] procedure Search(searchOptions: string);
[async] procedure GetOrders(searchOptions: string);
[async] procedure getUser();
procedure GeneratePDF(OrderID: string);
[async] procedure GenerateReportPDF;
var
PageNumber: integer;
......@@ -125,8 +124,6 @@ begin
ShowMessage('PDF Report Generated Successfully');
end;
procedure TFViewOrders.WebFormCreate(Sender: TObject);
// Initializes important values:
// PageNumber: What page number the user is on IE 1: 1-10, 2: 11-20 etc
......@@ -578,24 +575,4 @@ begin
end;
procedure TFViewOrders.GeneratePDF(OrderID: string);
var
XDCResponse: TXDataClientResponse;
PDFBase64: string;
PDFBlob: TJSUint8Array;
PDFLink: TJSHTMLElement;
begin
// XDCResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GenerateOrderPDF', [OrderID]));
// PDFBase64 := string(XDCResponse.Result);
//
// // Convert Base64 to binary and create a link to download it
// PDFBlob := TJSUint8Array.new(TJSBase64.decodeBase64(PDFBase64));
// PDFLink := TJSHTMLElement(document.createElement('a'));
// PDFLink.setAttribute('href', 'data:application/pdf;base64,' + PDFBase64);
// PDFLink.setAttribute('download', 'Order_' + OrderID + '.pdf');
// PDFLink.click;
end;
end.
......@@ -98,7 +98,7 @@ begin
OrderIDList.Add('18993'); // Add more OrderIDs as needed
// Generate the PDF Report with the list of OrderIDs
rptOrders.GenerateSimpleReport(350);
// rptOrders.GenerateSimpleReport(350);
finally
OrderIDList.Free; // Free the TStringList
end;
......
......@@ -36,7 +36,6 @@ type
function EditUser(const editOptions: string): string;
function Search(phoneNum: string): TOrderList;
procedure GenerateReportPDF(searchOptions: string);
function BuildOrderQuery(searchOptions: string): string;
function AddUser(userInfo: string): string;
function AddItem(itemInfo: string): string;
function DelUser(username: string): string;
......@@ -47,6 +46,7 @@ type
function EditStatusSchedule(StatusType: string; order: TJSONObject; ORDER_ID: string): string;
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
function BuildOrderQuery(searchOptions: string): string;
end;
implementation
......@@ -167,24 +167,25 @@ end;
procedure TLookupService.GenerateReportPDF(searchOptions: string);
var
SQL: string;
rptOrders: TrptOrders; // Local instance of rptOrders
rptOrders: TrptOrders;
begin
// Create instance of rptOrders
rptOrders := TrptOrders.Create(nil);
try
// Generate SQL dynamically using the existing GetOrders logic
// Generate dynamic SQL based on searchOptions
SQL := BuildOrderQuery(searchOptions);
// Log the SQL for debugging
Logger.log(5, 'Generated SQL: ' + SQL);
// Prepare the report dataset
rptOrders.PrepareReport(SQL);
// Generate the PDF report
// Generate and save the PDF
rptOrders.GeneratePDF;
// Optionally, log success
Logger.log(5, 'PDF Report successfully generated for searchOptions: ' + searchOptions);
Logger.log(5, 'PDF generated successfully.');
finally
rptOrders.Free; // Ensure proper cleanup
rptOrders.Free;
end;
end;
......@@ -230,7 +231,7 @@ begin
end;
// Build the SELECT query with dynamically generated subqueries
SQL := 'SELECT o.ORDER_ID, c.NAME AS COMPANY_NAME, o.JOB_NAME, o.ORDER_DATE, o.ORDER_TYPE, ';
SQL := 'SELECT o.ORDER_ID, o.LOCATION, c.NAME AS COMPANY_NAME, o.JOB_NAME, o.ORDER_DATE, o.ORDER_TYPE, ';
// Add dynamically generated subqueries
SQL := SQL + generateSubQuery(filterType, statusType, 'PROOF');
......@@ -240,7 +241,15 @@ begin
SQL := SQL + generateSubQuery(filterType, statusType, 'SHIP');
// Include additional static fields
SQL := SQL + 'o.PRICE, qb.QB_REF_NUM ';
SQL := SQL + 'o.PRICE, qb.QB_REF_NUM, ';
// Dynamically determine colors field based on ORDER_TYPE
SQL := SQL +
'(CASE ' +
'WHEN o.ORDER_TYPE = ''web_plate'' THEN ' +
'(SELECT quantity_and_colors_qty_colors FROM web_plate_orders WHERE order_id = o.ORDER_ID) ' +
'ELSE (SELECT colors_colors FROM corrugated_plate_orders WHERE order_id = o.ORDER_ID) ' +
'END) AS COLORS ';
// FROM clause
SQL := SQL + 'FROM orders o ' +
......@@ -263,13 +272,15 @@ begin
' OFFSET ' + IntToStr((PageNum - 1) * PageSize);
Result := SQL;
Logger.log(5, 'Generated SQL in Build order Query: ' + SQL);
Logger.log(5, 'Generated SQL in BuildOrderQuery: ' + SQL);
finally
params.Free;
end;
end;
function TLookupService.generateSelectSQL(filterType, startDate, endDate: string): string;
begin
......
......@@ -5,21 +5,36 @@ interface
uses
System.SysUtils, System.Classes, frxClass, frxExportBaseDialog, frxExportPDF,
Data.DB, DBAccess, Uni, UniProvider, MySQLUniProvider, System.IniFiles, Vcl.Forms,
MemDS, frxDBSet, frxTableObject, frCoreClasses, Common.Logging, System.IOUtils;
MemDS, frxDBSet, System.IOUtils, Common.Logging, frxTableObject, frCoreClasses;
type
TrptOrders = class(TDataModule)
frxOrders: TfrxReport;
frxPDFExport1: TfrxPDFExport;
ucKG: TUniConnection;
uqOrders: TUniQuery;
frxReportTableObject1: TfrxReportTableObject;
frxDBOrders: TfrxDBDataset;
uqOrders: TUniQuery;
uqOrdersORDER_ID: TIntegerField;
uqOrdersLOCATION: TStringField;
uqOrdersCOMPANY_NAME: TStringField;
uqOrdersJOB_NAME: TStringField;
uqOrdersORDER_DATE: TDateField;
uqOrdersORDER_TYPE: TStringField;
uqOrdersPROOF_DUE: TDateField;
uqOrdersPROOF_DONE: TDateTimeField;
uqOrdersART_DUE: TDateField;
uqOrdersART_DONE: TDateTimeField;
uqOrdersPLATE_DUE: TDateField;
uqOrdersPLATE_DONE: TDateTimeField;
uqOrdersMOUNT_DUE: TDateField;
uqOrdersMOUNT_DONE: TDateTimeField;
uqOrdersSHIP_DUE: TDateField;
uqOrdersSHIP_DONE: TDateTimeField;
uqOrdersPRICE: TFloatField;
uqOrdersQB_REF_NUM: TStringField;
uqOrdersCOLORS: TStringField;
procedure DataModuleCreate(Sender: TObject);
private
public
procedure GenerateSimpleReport(OrderID: Integer);
procedure PrepareReport(const SQL: string);
procedure GeneratePDF;
end;
......@@ -37,7 +52,6 @@ procedure TrptOrders.DataModuleCreate(Sender: TObject);
var
iniFile: TIniFile;
begin
// Load database connection settings from INI file
iniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini');
try
ucKG.Server := iniFile.ReadString('Database', 'Server', '');
......@@ -47,38 +61,9 @@ begin
end;
end;
procedure TrptOrders.GenerateSimpleReport(OrderID: Integer);
begin
try
Logger.Log(5, 'Generating Report for Order ID: ' + OrderID.ToString);
uqOrders.Close;
uqOrders.SQL.Text := 'SELECT ORDER_ID FROM corrugated_plate_orders WHERE ORDER_ID = :OrderID';
uqOrders.ParamByName('OrderID').AsInteger := OrderID;
try
uqOrders.Open;
except
on E: Exception do
begin
Logger.Log(1, 'Error executing query: ' + E.Message);
Exit;
end;
end;
frxOrders.PrepareReport;
frxOrders.ShowReport;
finally
uqOrders.Close;
frxOrders.Clear;
Logger.Log(5, 'Report generation complete for Order ID: ' + OrderID.ToString);
end;
end;
procedure TrptOrders.PrepareReport(const SQL: string);
begin
// Prepare and load data into the query
// Prepare and open the query
uqOrders.Close;
uqOrders.SQL.Text := SQL;
uqOrders.Open;
......@@ -86,26 +71,22 @@ end;
procedure TrptOrders.GeneratePDF;
var
ReportDir, ReportFileName: string;
ReportFileName: string;
begin
ReportDir := 'C:\Projects\KGOrders\Reports';
// Define output file
ReportFileName := TPath.Combine(ReportDir, 'OrderReport_' + FormatDateTime('yyyymmdd_hhnnss', Now) + '.pdf');
ReportFileName := TPath.Combine('C:\Projects\KGOrders\Reports',
'OrderReport_' + FormatDateTime('yyyymmdd_hhnnss', Now) + '.pdf');
if not DirectoryExists(ExtractFilePath(ReportFileName)) then
ForceDirectories(ExtractFilePath(ReportFileName));
// Prepare and export the report
// Generate the report
frxOrders.PrepareReport;
frxPDFExport1.FileName := ReportFileName;
frxPDFExport1.ShowDialog := False;
frxOrders.Export(frxPDFExport1);
frxOrders.ShowPreparedReport;
Logger.Log(5, 'PDF saved to: ' + ReportFileName);
Logger.log(5, 'PDF saved to: ' + ReportFileName);
end;
end.
end.
[Settings]
MemoLogLevel=5
FileLogLevel=5
LogFileNum=69
LogFileNum=115
webClientVersion=1.0.0
[Database]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment