Commit e92fbc25 by Elias Sarraf

merge

parent a7e54751
......@@ -82,6 +82,7 @@ type
[async] procedure Search(searchOptions: string);
[async] procedure GetOrders(searchOptions: string);
[async] procedure getUser();
procedure GeneratePDF(OrderID: string);
[async] procedure GenerateReportPDF;
var
PageNumber: integer;
......@@ -124,10 +125,7 @@ begin
ShowMessage('PDF Report Generated Successfully');
end;
<<<<<<< HEAD
=======
>>>>>>> f1a2333 (clean up code)
procedure TFViewOrders.WebFormCreate(Sender: TObject);
// Initializes important values:
// PageNumber: What page number the user is on IE 1: 1-10, 2: 11-20 etc
......@@ -591,8 +589,6 @@ begin
end;
<<<<<<< HEAD
=======
procedure TFViewOrders.GeneratePDF(OrderID: string);
var
XDCResponse: TXDataClientResponse;
......@@ -612,5 +608,4 @@ begin
end;
>>>>>>> f1a2333 (clean up code)
end.
......@@ -99,7 +99,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,6 +36,7 @@ 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;
......@@ -46,7 +47,6 @@ 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,25 +167,24 @@ end;
procedure TLookupService.GenerateReportPDF(searchOptions: string);
var
SQL: string;
rptOrders: TrptOrders;
rptOrders: TrptOrders; // Local instance of rptOrders
begin
// Create instance of rptOrders
rptOrders := TrptOrders.Create(nil);
try
// Generate dynamic SQL based on searchOptions
// Generate SQL dynamically using the existing GetOrders logic
SQL := BuildOrderQuery(searchOptions);
// Log the SQL for debugging
Logger.log(5, 'Generated SQL: ' + SQL);
// Prepare the report dataset
rptOrders.PrepareReport(SQL);
// Generate and save the PDF
// Generate the PDF report
rptOrders.GeneratePDF;
Logger.log(5, 'PDF generated successfully.');
// Optionally, log success
Logger.log(5, 'PDF Report successfully generated for searchOptions: ' + searchOptions);
finally
rptOrders.Free;
rptOrders.Free; // Ensure proper cleanup
end;
end;
......@@ -231,7 +230,7 @@ begin
end;
// Build the SELECT query with dynamically generated subqueries
SQL := 'SELECT o.ORDER_ID, o.LOCATION, c.NAME AS COMPANY_NAME, o.JOB_NAME, o.ORDER_DATE, o.ORDER_TYPE, ';
SQL := 'SELECT o.ORDER_ID, c.NAME AS COMPANY_NAME, o.JOB_NAME, o.ORDER_DATE, o.ORDER_TYPE, ';
// Add dynamically generated subqueries
SQL := SQL + generateSubQuery(filterType, statusType, 'PROOF');
......@@ -241,15 +240,7 @@ begin
SQL := SQL + generateSubQuery(filterType, statusType, 'SHIP');
// Include additional static fields
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 ';
SQL := SQL + 'o.PRICE, qb.QB_REF_NUM ';
// FROM clause
SQL := SQL + 'FROM orders o ' +
......@@ -272,15 +263,13 @@ begin
' OFFSET ' + IntToStr((PageNum - 1) * PageSize);
Result := SQL;
Logger.log(5, 'Generated SQL in BuildOrderQuery: ' + SQL);
Logger.log(5, 'Generated SQL in Build order Query: ' + SQL);
finally
params.Free;
end;
end;
function TLookupService.generateSelectSQL(filterType, startDate, endDate: string): string;
begin
......
......@@ -5,42 +5,22 @@ interface
uses
System.SysUtils, System.Classes, frxClass, frxExportBaseDialog, frxExportPDF,
Data.DB, DBAccess, Uni, UniProvider, MySQLUniProvider, System.IniFiles, Vcl.Forms,
MemDS, frxDBSet, System.IOUtils, Common.Logging, frxTableObject, frCoreClasses;
MemDS, frxDBSet, frxTableObject, frCoreClasses, Common.Logging, System.IOUtils;
type
TrptOrders = class(TDataModule)
frxOrders: TfrxReport;
frxPDFExport1: TfrxPDFExport;
ucKG: TUniConnection;
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;
frxReportTableObject1: TfrxReportTableObject;
frxDBOrders: TfrxDBDataset;
procedure DataModuleCreate(Sender: TObject);
<<<<<<< HEAD
=======
private
>>>>>>> f1a2333 (clean up code)
public
procedure GenerateSimpleReport(OrderID: Integer);
procedure PrepareReport(const SQL: string);
procedure GeneratePDF;
end;
......@@ -59,12 +39,8 @@ uses
procedure TrptOrders.DataModuleCreate(Sender: TObject);
begin
<<<<<<< HEAD
iniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini');
=======
Logger.Log( 3, 'TAuthDatabase.DataModuleCreate' );
LoadDatabaseSettings( ucKG, 'kgOrdersServer.ini' );
>>>>>>> f1a2333 (clean up code)
try
ucKG.Connect;
except
......@@ -75,9 +51,38 @@ 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 open the query
// Prepare and load data into the query
uqOrders.Close;
uqOrders.SQL.Text := SQL;
uqOrders.Open;
......@@ -85,26 +90,22 @@ end;
procedure TrptOrders.GeneratePDF;
var
ReportFileName: string;
ReportDir, ReportFileName: string;
begin
ReportFileName := TPath.Combine('C:\Projects\KGOrders\Reports',
'OrderReport_' + FormatDateTime('yyyymmdd_hhnnss', Now) + '.pdf');
ReportDir := 'C:\Projects\KGOrders\Reports';
// Define output file
ReportFileName := TPath.Combine(ReportDir, 'OrderReport_' + FormatDateTime('yyyymmdd_hhnnss', Now) + '.pdf');
if not DirectoryExists(ExtractFilePath(ReportFileName)) then
ForceDirectories(ExtractFilePath(ReportFileName));
// Generate the report
// Prepare and export the report
frxOrders.PrepareReport;
frxPDFExport1.FileName := ReportFileName;
frxPDFExport1.ShowDialog := False;
frxOrders.Export(frxPDFExport1);
Logger.log(5, 'PDF saved to: ' + ReportFileName);
frxOrders.ShowPreparedReport;
Logger.Log(5, 'PDF saved to: ' + ReportFileName);
end;
<<<<<<< HEAD
=======
>>>>>>> f1a2333 (clean up code)
end.
end.
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