Commit f22ff51b by cam

corrugated pdf generation is now fully functional.

Only thing left is to finalize the design of the pdf
parent 4b7a8e35
......@@ -926,17 +926,6 @@ object FOrderEntryCorrugated: TFOrderEntryCorrugated
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object btnEdit: TWebButton
Left = 870
Top = 560
Width = 96
Height = 25
Caption = 'Edit'
ChildOrder = 79
ElementID = 'btnedit'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object btnCancel: TWebButton
Left = 764
Top = 560
......@@ -996,6 +985,18 @@ object FOrderEntryCorrugated: TFOrderEntryCorrugated
DataField = 'plates_thickness'
DataSource = WebDataSource1
end
object btnPDF: TWebButton
Left = 877
Top = 560
Width = 96
Height = 25
Caption = 'PDF'
ChildOrder = 77
ElementID = 'btnedit'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = btnPDFClick
end
object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection
Left = 160
......
......@@ -186,7 +186,6 @@ type
WebDBComboBox1: TWebDBComboBox;
cbEmail: TWebCheckBox;
XDataWebDataSet1supplied_by_customer_order_date: TStringField;
btnEdit: TWebButton;
btnCancel: TWebButton;
WebDBComboBox2: TWebDBComboBox;
wdsQBItem: TWebDataSource;
......@@ -194,6 +193,7 @@ type
xdwdsQBItemname: TStringField;
WebDBComboBox3: TWebDBComboBox;
WebDBComboBox4: TWebDBComboBox;
btnPDF: TWebButton;
procedure WebFormCreate(Sender: TObject);
procedure HideNotification();
procedure ShowNotification(Notification: string);
......@@ -205,7 +205,9 @@ type
procedure addColorRow(num, Color, LPI, Size: string);
procedure btnConfirmClick(Sender: TObject);
[async] procedure AddCorrugatedOrder(orderJSON: TJSONObject);
[async] procedure GenerateReportPDF;
procedure btnCancelClick(Sender: TObject);
procedure btnPDFClick(Sender: TObject);
private
FAgencyCode: string;
FCurrentReportType: string;
......@@ -366,6 +368,30 @@ begin
FViewMain.ViewOrders('Success:Order Successfully Added');
end;
procedure TFOrderEntryCorrugated.btnPDFClick(Sender: TObject);
begin
GenerateReportPDF
end;
[async] procedure TFOrderEntryCorrugated.GenerateReportPDF;
// sends the search to the server which then sends back a pdf of the results
var
xdcResponse: TXDataClientResponse;
searchOptions, pdfURL: string;
jsObject: TJSObject;
begin
// Call the server method to generate the PDF
console.log(orderID);
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GenerateOrderCorrugatedPDF', [orderID]));
jsObject := JS.TJSObject(xdcResponse.Result);
pdfURL := JS.toString(jsObject.Properties['value']);
// Open the PDF in a new browser tab without needing a different form
// This method is much faster too, even for large datasets
window.open(pdfURL, '_blank');
end;
procedure TFOrderEntryCorrugated.AddCorrugatedOrder(orderJSON: TJSONObject);
// sends the order JSON object to the server
var
......
......@@ -139,7 +139,7 @@ begin
searchOptions := GenerateSearchOptions;
// Call the server method to generate the PDF
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GenerateReportPDF', [searchOptions]));
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GenerateOrderListPDF', [searchOptions]));
jsObject := JS.TJSObject(xdcResponse.Result);
pdfURL := JS.toString(jsObject.Properties['value']);
......
......@@ -33,8 +33,8 @@ object ApiDatabase: TApiDatabase
Connection = ucKG
SQL.Strings = (
'select * from corrugated_plate_orders')
Left = 263
Top = 156
Left = 257
Top = 148
object uqOrdersORDER_ID: TIntegerField
FieldName = 'ORDER_ID'
end
......
......@@ -168,7 +168,7 @@ begin
rptOrderCorrugated := TrptOrderCorrugated.Create(nil);
try
// Generate SQL query for a single order
SQL := 'SELECT * FROM orders WHERE ORDER_ID = ' + QuotedStr(orderID);
SQL := 'SELECT * FROM corrugated_plate_orders WHERE ORDER_ID = ' + orderID;
// Prepare the report with the query
Result := rptOrderCorrugated.PrepareReport(SQL);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,14 +4,39 @@ interface
uses
System.SysUtils, System.Classes, Data.DB, MemDS, DBAccess, Uni, Common.Logging,
frxClass, frxExportBaseDialog, frxExportPDF, frCoreClasses, frxDBSet;
frxClass, frxExportBaseDialog, frxExportPDF, frCoreClasses, frxDBSet, JS, JSON,
frxTableObject, frxUtils;
type
TrptOrderCorrugated = class(TDataModule)
uqOrderCorrugated: TUniQuery;
ucKG: TUniConnection;
frxPDFExport1: TfrxPDFExport;
frxDBOrderCorrugated: TfrxDBDataset;
frxOrderCorrugated: TfrxReport;
uqColors: TUniQuery;
uqColorshash1: TStringField;
uqColorshash2: TStringField;
uqColorshash3: TStringField;
uqColorshash4: TStringField;
uqColorshash5: TStringField;
uqColorshash6: TStringField;
uqColorshash7: TStringField;
uqColorscolor1: TStringField;
uqColorscolor2: TStringField;
uqColorscolor3: TStringField;
uqColorscolor4: TStringField;
uqColorscolor5: TStringField;
uqColorscolor6: TStringField;
uqColorscolor7: TStringField;
uqColorslpi1: TStringField;
uqColorslpi2: TStringField;
uqColorslpi3: TStringField;
uqColorslpi4: TStringField;
uqColorslpi5: TStringField;
uqColorslpi6: TStringField;
uqColorslpi7: TStringField;
uqColorssize1: TStringField;
uqOrderCorrugated: TUniQuery;
uqOrderCorrugatedORDER_ID: TIntegerField;
uqOrderCorrugatedCOMPANY_ID: TIntegerField;
uqOrderCorrugatedUSER_ID: TIntegerField;
......@@ -99,12 +124,12 @@ type
uqOrderCorrugatedstaff_fields_quantity: TStringField;
uqOrderCorrugatedlayout_rsc_style: TStringField;
uqOrderCorrugatedstaff_fields_art_location: TStringField;
uqOrderCorrugatedCOMPANY_NAME: TStringField;
frxOrderCorrugated: TfrxReport;
private
{ Private declarations }
public
function PrepareReport(SQL: string): string;
function GeneratePDF: string;
procedure PopulateColorTable();
end;
var
......@@ -116,19 +141,105 @@ implementation
{$R *.dfm}
uses
uLibrary, Common.Config;
procedure TrptOrderCorrugated.PopulateColorTable;
var
frxTable: TfrxTableObject;
row: TfrxCustomTableRow;
colorArray: TJSONArray;
colorsObject, colorObject: TJSONObject;
colorsString: string;
i, rowIndex: Integer;
temp: TObject;
begin
logger.Log(1, 'Adding Color Rows');
frxTable := frxOrderCorrugated.FindObject('ColorTable') as TfrxTableObject;
colorsString := uqOrderCorrugated.FieldByName('colors_colors').AsString;
colorsObject := TJSONObject.ParseJSONValue(colorsString) as TJSONObject;
colorArray := TJSONArray(colorsObject.GetValue<TJSONArray>('items'));
for i := 0 to colorArray.Count - 1 do
begin
row := frxOrderCorrugated.FindObject('ColorRow' + IntToStr(i + 1)) as TfrxCustomTableRow;
colorObject := colorArray.Items[i] as TJSONObject;
{row.Cells[5].DataField := colorObject.GetValue<string>('#');
row.Cells[6].DataField := colorObject.GetValue<string>('Color');
row.Cells[7].DataField := colorObject.GetValue<string>('LPI');
row.Cells[8].DataField := colorObject.GetValue<string>('Size');
}
row.Cells[4].Text := colorObject.GetValue<string>('#');
row.Cells[5].Text := colorObject.GetValue<string>('Color');
row.Cells[6].Text := colorObject.GetValue<string>('LPI');
row.Cells[7].Text := colorObject.GetValue<string>('Size');
end;
end;
function TrptOrderCorrugated.PrepareReport(SQL: string): string;
var
orderList : TJSObject;
i: integer;
data: TJSArray;
order: TJSObject;
callListLength: integer;
tempString, strColorList: string;
colorObject: TJSONObject;
colorList: TJSArray;
colorLength: integer;
color: TJSObject;
colorJSON: TJSONObject;
colorListJSON: TJSONArray;
items: TJSObject;
begin
Logger.Log(3, 'Generated SQL for Prepare Report: ' + SQL);
//SQL := 'select * from corrugated_plate_orders where ORDER_ID = 18381';
doQuery(uqOrderCorrugated, SQL);
if ( string( uqOrderCorrugated.FieldByName('colors_colors').AsString ) ) <> '' then
begin
PopulateColorTable();
end;
uqOrderCorrugated.Close;
uqOrderCorrugated.SQL.Text := SQL;
uqOrderCorrugated.Open;
// result := GeneratePDF;
result := GeneratePDF;
Logger.Log(3, 'Report preparation complete.');
end;
function TrptOrderCorrugated.GeneratePDF: string;
var
ReportDir, ReportFileName: string;
reportURL: string;
begin
ReportDir := ServerConfig.reportsFolder;
if not DirectoryExists(ReportDir) then
begin
ForceDirectories(ReportDir);
Logger.Log(5, 'Reports directory created: ' + ReportDir);
end;
reportURL := 'reports\' + FormatDateTime('yyyymmdd_hhnnss', Now) + '.pdf';
ReportFileName := reportDir + reportUrl;
frxPDFExport1.FileName := ReportFileName;
frxPDFExport1.ShowDialog := False;
try
frxOrderCorrugated.PrepareReport;
frxOrderCorrugated.Export(frxPDFExport1);
//frxOrders.ShowPreparedReport;
finally
frxOrderCorrugated.Clear; // Clears the report to avoid memory bloat
end;
Logger.Log(5, 'PDF saved to: ' + ReportFileName);
result := reportURL;
end;
end.
[Settings]
MemoLogLevel=4
FileLogLevel=5
LogFileNum=150
LogFileNum=187
webClientVersion=1.0.0
[Database]
--Server=192.168.159.132
Server=192.168.102.130
Server=192.168.159.132
--Server=192.168.102.130
--Server=192.168.75.133
--Database=
--Username=
......
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