Commit d7e3aa71 by Mac Stephens

Still progressing, report is now loading rows dynamically

parent 0565250e
...@@ -82,7 +82,6 @@ type ...@@ -82,7 +82,6 @@ type
[async] procedure Search(searchOptions: string); [async] procedure Search(searchOptions: string);
[async] procedure GetOrders(searchOptions: string); [async] procedure GetOrders(searchOptions: string);
[async] procedure getUser(); [async] procedure getUser();
procedure GeneratePDF(OrderID: string);
[async] procedure GenerateReportPDF; [async] procedure GenerateReportPDF;
var var
PageNumber: integer; PageNumber: integer;
...@@ -125,8 +124,6 @@ begin ...@@ -125,8 +124,6 @@ begin
ShowMessage('PDF Report Generated Successfully'); ShowMessage('PDF Report Generated Successfully');
end; end;
procedure TFViewOrders.WebFormCreate(Sender: TObject); procedure TFViewOrders.WebFormCreate(Sender: TObject);
// Initializes important values: // Initializes important values:
// PageNumber: What page number the user is on IE 1: 1-10, 2: 11-20 etc // PageNumber: What page number the user is on IE 1: 1-10, 2: 11-20 etc
...@@ -578,24 +575,4 @@ begin ...@@ -578,24 +575,4 @@ begin
end; 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. end.
...@@ -98,7 +98,7 @@ begin ...@@ -98,7 +98,7 @@ begin
OrderIDList.Add('18993'); // Add more OrderIDs as needed OrderIDList.Add('18993'); // Add more OrderIDs as needed
// Generate the PDF Report with the list of OrderIDs // Generate the PDF Report with the list of OrderIDs
rptOrders.GenerateSimpleReport(350); // rptOrders.GenerateSimpleReport(350);
finally finally
OrderIDList.Free; // Free the TStringList OrderIDList.Free; // Free the TStringList
end; end;
......
...@@ -36,7 +36,6 @@ type ...@@ -36,7 +36,6 @@ type
function EditUser(const editOptions: string): string; function EditUser(const editOptions: string): string;
function Search(phoneNum: string): TOrderList; function Search(phoneNum: string): TOrderList;
procedure GenerateReportPDF(searchOptions: string); procedure GenerateReportPDF(searchOptions: string);
function BuildOrderQuery(searchOptions: string): string;
function AddUser(userInfo: string): string; function AddUser(userInfo: string): string;
function AddItem(itemInfo: string): string; function AddItem(itemInfo: string): string;
function DelUser(username: string): string; function DelUser(username: string): string;
...@@ -47,6 +46,7 @@ type ...@@ -47,6 +46,7 @@ type
function EditStatusSchedule(StatusType: string; order: TJSONObject; ORDER_ID: string): string; function EditStatusSchedule(StatusType: string; order: TJSONObject; ORDER_ID: string): string;
procedure AfterConstruction; override; procedure AfterConstruction; override;
procedure BeforeDestruction; override; procedure BeforeDestruction; override;
function BuildOrderQuery(searchOptions: string): string;
end; end;
implementation implementation
...@@ -167,24 +167,25 @@ end; ...@@ -167,24 +167,25 @@ end;
procedure TLookupService.GenerateReportPDF(searchOptions: string); procedure TLookupService.GenerateReportPDF(searchOptions: string);
var var
SQL: string; SQL: string;
rptOrders: TrptOrders; // Local instance of rptOrders rptOrders: TrptOrders;
begin begin
// Create instance of rptOrders
rptOrders := TrptOrders.Create(nil); rptOrders := TrptOrders.Create(nil);
try try
// Generate SQL dynamically using the existing GetOrders logic // Generate dynamic SQL based on searchOptions
SQL := BuildOrderQuery(searchOptions); SQL := BuildOrderQuery(searchOptions);
// Log the SQL for debugging
Logger.log(5, 'Generated SQL: ' + SQL);
// Prepare the report dataset // Prepare the report dataset
rptOrders.PrepareReport(SQL); rptOrders.PrepareReport(SQL);
// Generate the PDF report // Generate and save the PDF
rptOrders.GeneratePDF; rptOrders.GeneratePDF;
// Optionally, log success Logger.log(5, 'PDF generated successfully.');
Logger.log(5, 'PDF Report successfully generated for searchOptions: ' + searchOptions);
finally finally
rptOrders.Free; // Ensure proper cleanup rptOrders.Free;
end; end;
end; end;
...@@ -230,7 +231,7 @@ begin ...@@ -230,7 +231,7 @@ begin
end; end;
// Build the SELECT query with dynamically generated subqueries // 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 // Add dynamically generated subqueries
SQL := SQL + generateSubQuery(filterType, statusType, 'PROOF'); SQL := SQL + generateSubQuery(filterType, statusType, 'PROOF');
...@@ -240,7 +241,15 @@ begin ...@@ -240,7 +241,15 @@ begin
SQL := SQL + generateSubQuery(filterType, statusType, 'SHIP'); SQL := SQL + generateSubQuery(filterType, statusType, 'SHIP');
// Include additional static fields // 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 // FROM clause
SQL := SQL + 'FROM orders o ' + SQL := SQL + 'FROM orders o ' +
...@@ -263,13 +272,15 @@ begin ...@@ -263,13 +272,15 @@ begin
' OFFSET ' + IntToStr((PageNum - 1) * PageSize); ' OFFSET ' + IntToStr((PageNum - 1) * PageSize);
Result := SQL; Result := SQL;
Logger.log(5, 'Generated SQL in Build order Query: ' + SQL); Logger.log(5, 'Generated SQL in BuildOrderQuery: ' + SQL);
finally finally
params.Free; params.Free;
end; end;
end; end;
function TLookupService.generateSelectSQL(filterType, startDate, endDate: string): string; function TLookupService.generateSelectSQL(filterType, startDate, endDate: string): string;
begin begin
......
...@@ -5,21 +5,36 @@ interface ...@@ -5,21 +5,36 @@ interface
uses uses
System.SysUtils, System.Classes, frxClass, frxExportBaseDialog, frxExportPDF, System.SysUtils, System.Classes, frxClass, frxExportBaseDialog, frxExportPDF,
Data.DB, DBAccess, Uni, UniProvider, MySQLUniProvider, System.IniFiles, Vcl.Forms, 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 type
TrptOrders = class(TDataModule) TrptOrders = class(TDataModule)
frxOrders: TfrxReport; frxOrders: TfrxReport;
frxPDFExport1: TfrxPDFExport; frxPDFExport1: TfrxPDFExport;
ucKG: TUniConnection; ucKG: TUniConnection;
uqOrders: TUniQuery;
frxReportTableObject1: TfrxReportTableObject;
frxDBOrders: TfrxDBDataset; 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); procedure DataModuleCreate(Sender: TObject);
private
public public
procedure GenerateSimpleReport(OrderID: Integer);
procedure PrepareReport(const SQL: string); procedure PrepareReport(const SQL: string);
procedure GeneratePDF; procedure GeneratePDF;
end; end;
...@@ -37,7 +52,6 @@ procedure TrptOrders.DataModuleCreate(Sender: TObject); ...@@ -37,7 +52,6 @@ procedure TrptOrders.DataModuleCreate(Sender: TObject);
var var
iniFile: TIniFile; iniFile: TIniFile;
begin begin
// Load database connection settings from INI file
iniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini'); iniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini');
try try
ucKG.Server := iniFile.ReadString('Database', 'Server', ''); ucKG.Server := iniFile.ReadString('Database', 'Server', '');
...@@ -47,38 +61,9 @@ begin ...@@ -47,38 +61,9 @@ begin
end; end;
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); procedure TrptOrders.PrepareReport(const SQL: string);
begin begin
// Prepare and load data into the query // Prepare and open the query
uqOrders.Close; uqOrders.Close;
uqOrders.SQL.Text := SQL; uqOrders.SQL.Text := SQL;
uqOrders.Open; uqOrders.Open;
...@@ -86,26 +71,22 @@ end; ...@@ -86,26 +71,22 @@ end;
procedure TrptOrders.GeneratePDF; procedure TrptOrders.GeneratePDF;
var var
ReportDir, ReportFileName: string; ReportFileName: string;
begin begin
ReportDir := 'C:\Projects\KGOrders\Reports'; ReportFileName := TPath.Combine('C:\Projects\KGOrders\Reports',
// Define output file 'OrderReport_' + FormatDateTime('yyyymmdd_hhnnss', Now) + '.pdf');
ReportFileName := TPath.Combine(ReportDir, '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; frxOrders.PrepareReport;
frxPDFExport1.FileName := ReportFileName; frxPDFExport1.FileName := ReportFileName;
frxPDFExport1.ShowDialog := False; frxPDFExport1.ShowDialog := False;
frxOrders.Export(frxPDFExport1); frxOrders.Export(frxPDFExport1);
frxOrders.ShowPreparedReport; Logger.log(5, 'PDF saved to: ' + ReportFileName);
Logger.Log(5, 'PDF saved to: ' + ReportFileName);
end; end;
end. end.
end.
[Settings] [Settings]
MemoLogLevel=5 MemoLogLevel=5
FileLogLevel=5 FileLogLevel=5
LogFileNum=69 LogFileNum=115
webClientVersion=1.0.0 webClientVersion=1.0.0
[Database] [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