Commit d9a45297 by Elias Sarraf

Merge remote-tracking branch 'origin/cam2'

parents d39dc485 650efac4
...@@ -118,7 +118,7 @@ var ...@@ -118,7 +118,7 @@ var
implementation implementation
uses uses
XData.Model.Classes, View.Main, View.AddOrder, View.Search; XData.Model.Classes, View.Main, View.AddOrder, View.Search, View.PDF;
{$R *.dfm} {$R *.dfm}
...@@ -129,13 +129,27 @@ end; ...@@ -129,13 +129,27 @@ end;
[async] procedure TFViewOrders.GenerateReportPDF; [async] procedure TFViewOrders.GenerateReportPDF;
var var
searchOptions: string; xdcResponse: TXDataClientResponse;
searchOptions, pdfURL: string;
jsObject: TJSObject;
ShowPDFForm: TFViewPDF;
procedure AfterCreate(AForm: TObject);
begin
ShowPDFForm.LoadPDF(pdfUrl);
ShowPDFForm.ShowModal;
end;
begin begin
searchOptions := GenerateSearchOptions; searchOptions := GenerateSearchOptions;
// Call the server method to generate the PDF // Call the server method to generate the PDF
await(XDataWebClient1.RawInvokeAsync('ILookupService.GenerateReportPDF', [searchOptions])); xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GenerateReportPDF', [searchOptions]));
ShowMessage('PDF Report Generated Successfully'); jsObject := JS.TJSObject(xdcResponse.Result);
pdfUrl := JS.toString(jsObject.Properties['value']);
//ShowMessage('PDF Report Generated Successfully');
console.log(pdfURL);
//application.Navigate( pdfUrl, ntblank );
ShowPDFForm := TFViewPDF.CreateNew(@AfterCreate);
end; end;
...@@ -641,22 +655,45 @@ begin ...@@ -641,22 +655,45 @@ begin
'&orderby=' + OrderBy + '&orderby=' + OrderBy +
//Status 1 //Status 1
'&startDate1=' + startDate1 + '&filterType1=' + filterType1;
'&endDate1=' + endDate1 + if ( (filterType1 <> '') and (filterType1 <> 'NONE') ) then
'&filterType1=' + filterType1 + begin
'&null1=' + BoolToStr(null1) + searchOptions := searchOptions +
'&null1=' + BoolToStr(null1);
if (not (null1)) then
begin
searchOptions := searchOptions +
'&startDate1=' + startDate1 +
'&endDate1=' + endDate1;
end;
end;
// Status2 // Status2
'&startDate2=' + startDate2 + searchOptions := searchOptions +
'&endDate2=' + endDate2 + '&filterType2=' + filterType2;
'&filterType2=' + filterType2 + if ( (filterType2 <> '') and (filterType2 <> 'NONE') ) then
'&null2=' + BoolToStr(null2) + begin
searchOptions := searchOptions + '&null2=' + BoolToStr(null2);
'&orderType=' + orderType + if (not (null2)) then
'&jobName=' + jobName + begin
'&companyID=' + companyID + searchOptions := searchOptions +
'&orderID=' + orderID; '&startDate2=' + startDate2 +
'&endDate2=' + endDate2;
end;
end;
if ( ( orderType <> '' ) AND ( orderType <> 'ANY' ) ) then
searchOptions := searchOptions + '&orderType=' + orderType;
if jobName <> '' then
searchOptions := searchOptions + '&jobName=' + jobName;
if companyID <> '' then
searchOptions := searchOptions + '&companyID=' + companyID;
if orderID <> '' then
searchOptions := searchOptions + '&orderID=' + orderID;
Result := searchOptions; Result := searchOptions;
end; end;
......
object FViewPDF: TFViewPDF
Width = 1062
Height = 780
object wbcPDFPreview: TWebBrowserControl
Left = 0
Top = 0
Width = 1062
Height = 780
Align = alClient
Sandbox = []
ExplicitTop = 39
ExplicitWidth = 640
ExplicitHeight = 588
end
object btnClose: TWebButton
Left = 826
Top = 17
Width = 96
Height = 25
Margins.Top = 10
Anchors = [akTop, akRight]
Caption = 'Close'
ChildOrder = 1
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = btnCloseClick
end
end
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>TMS Web Project</title>
<style>
</style>
</head>
<body>
</body>
</html>
\ No newline at end of file
unit View.PDF;
interface
uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, WEBLib.WebCtrls, Vcl.StdCtrls,
WEBLib.StdCtrls;
type
TFViewPDF = class(TWebForm)
wbcPDFPreview: TWebBrowserControl;
btnClose: TWebButton;
procedure btnCloseClick(Sender: TObject);
private
{ Private declarations }
public
procedure LoadPDF(const AUrl: string);
end;
var
FViewPDF: TFViewPDF;
implementation
{$R *.dfm}
procedure TFViewPDF.btnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TFViewPDF.LoadPDF(const AUrl: string);
begin
if Assigned(wbcPDFPreview) then
wbcPDFPreview.URL := AUrl
else
ShowMessage('wbcPDFPreview is not initialized');
end;
end.
\ No newline at end of file
...@@ -204,6 +204,21 @@ object FSearch: TFSearch ...@@ -204,6 +204,21 @@ object FSearch: TFSearch
ParentFont = False ParentFont = False
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
end end
object WebLabel5: TWebLabel
Left = 338
Top = 56
Width = 89
Height = 14
Caption = 'Company Name:'
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Style = [fsBold]
HeightPercent = 100.000000000000000000
ParentFont = False
WidthPercent = 100.000000000000000000
end
object pnlMessage: TWebPanel object pnlMessage: TWebPanel
Left = 92 Left = 92
Top = 637 Top = 637
...@@ -315,7 +330,6 @@ object FSearch: TFSearch ...@@ -315,7 +330,6 @@ object FSearch: TFSearch
Top = 462 Top = 462
Width = 127 Width = 127
Height = 22 Height = 22
ElementClassName = 'custom-select'
HeightStyle = ssAuto HeightStyle = ssAuto
BorderStyle = bsSingle BorderStyle = bsSingle
ChildOrder = 7 ChildOrder = 7
...@@ -338,7 +352,6 @@ object FSearch: TFSearch ...@@ -338,7 +352,6 @@ object FSearch: TFSearch
Top = 462 Top = 462
Width = 135 Width = 135
Height = 22 Height = 22
ElementClassName = 'custom-select'
HeightStyle = ssAuto HeightStyle = ssAuto
BorderStyle = bsSingle BorderStyle = bsSingle
ChildOrder = 7 ChildOrder = 7
...@@ -365,6 +378,7 @@ object FSearch: TFSearch ...@@ -365,6 +378,7 @@ object FSearch: TFSearch
ChildOrder = 6 ChildOrder = 6
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
OnClick = cbNull1Click
end end
object wcbOrderType: TWebComboBox object wcbOrderType: TWebComboBox
Left = 174 Left = 174
...@@ -411,7 +425,6 @@ object FSearch: TFSearch ...@@ -411,7 +425,6 @@ object FSearch: TFSearch
Top = 536 Top = 536
Width = 127 Width = 127
Height = 22 Height = 22
ElementClassName = 'custom-select'
HeightStyle = ssAuto HeightStyle = ssAuto
BorderStyle = bsSingle BorderStyle = bsSingle
ChildOrder = 7 ChildOrder = 7
...@@ -428,7 +441,6 @@ object FSearch: TFSearch ...@@ -428,7 +441,6 @@ object FSearch: TFSearch
Top = 536 Top = 536
Width = 135 Width = 135
Height = 22 Height = 22
ElementClassName = 'custom-select'
HeightStyle = ssAuto HeightStyle = ssAuto
BorderStyle = bsSingle BorderStyle = bsSingle
ChildOrder = 7 ChildOrder = 7
...@@ -449,11 +461,12 @@ object FSearch: TFSearch ...@@ -449,11 +461,12 @@ object FSearch: TFSearch
ChildOrder = 6 ChildOrder = 6
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
OnClick = cbNull2Click
end end
object TMSFNCGrid1: TTMSFNCGrid object TMSFNCGrid1: TTMSFNCGrid
Left = 20 Left = 20
Top = 112 Top = 112
Width = 865 Width = 620
Height = 233 Height = 233
ParentDoubleBuffered = False ParentDoubleBuffered = False
DoubleBuffered = True DoubleBuffered = True
...@@ -484,7 +497,7 @@ object FSearch: TFSearch ...@@ -484,7 +497,7 @@ object FSearch: TFSearch
Font.Name = 'Segoe UI' Font.Name = 'Segoe UI'
Font.Style = [] Font.Style = []
ID = '' ID = ''
Width = 70.000000000000000000 Width = 40.000000000000000000
end end
item item
BorderWidth = 1 BorderWidth = 1
...@@ -499,7 +512,7 @@ object FSearch: TFSearch ...@@ -499,7 +512,7 @@ object FSearch: TFSearch
Font.Name = 'Segoe UI' Font.Name = 'Segoe UI'
Font.Style = [] Font.Style = []
ID = '' ID = ''
Width = 250.000000000000000000 Width = 120.000000000000000000
end end
item item
BorderWidth = 1 BorderWidth = 1
...@@ -514,7 +527,7 @@ object FSearch: TFSearch ...@@ -514,7 +527,7 @@ object FSearch: TFSearch
Font.Name = 'Segoe UI' Font.Name = 'Segoe UI'
Font.Style = [] Font.Style = []
ID = '' ID = ''
Width = 100.000000000000000000 Width = 200.000000000000000000
end end
item item
BorderWidth = 1 BorderWidth = 1
...@@ -529,7 +542,7 @@ object FSearch: TFSearch ...@@ -529,7 +542,7 @@ object FSearch: TFSearch
Font.Name = 'Segoe UI' Font.Name = 'Segoe UI'
Font.Style = [] Font.Style = []
ID = '' ID = ''
Width = 426.000000000000000000 Width = 241.000000000000000000
end end
item item
BorderWidth = 1 BorderWidth = 1
...@@ -703,6 +716,28 @@ object FSearch: TFSearch ...@@ -703,6 +716,28 @@ object FSearch: TFSearch
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
OnClick = btnClearClick OnClick = btnClearClick
end end
object edtCompanyName: TWebEdit
Left = 338
Top = 76
Width = 239
Height = 22
HelpType = htKeyword
TabStop = False
ChildOrder = 8
ElementClassName = 'form-control'
ElementFont = efCSS
Enabled = False
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -8
Font.Name = 'Arial'
Font.Style = []
HeightPercent = 100.000000000000000000
HideSelection = False
ParentFont = False
TabOrder = 1
WidthPercent = 100.000000000000000000
end
object XDataWebClient1: TXDataWebClient object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection Connection = DMConnection.ApiConnection
Left = 738 Left = 738
...@@ -710,8 +745,8 @@ object FSearch: TFSearch ...@@ -710,8 +745,8 @@ object FSearch: TFSearch
end end
object xdwdsCustomers: TXDataWebDataSet object xdwdsCustomers: TXDataWebDataSet
Connection = DMConnection.ApiConnection Connection = DMConnection.ApiConnection
Left = 608 Left = 666
Top = 63 Top = 73
object xdwdsCustomersID: TIntegerField object xdwdsCustomersID: TIntegerField
FieldName = 'ID' FieldName = 'ID'
end end
...@@ -721,14 +756,13 @@ object FSearch: TFSearch ...@@ -721,14 +756,13 @@ object FSearch: TFSearch
object xdwdsCustomersSHORT_NAME: TStringField object xdwdsCustomersSHORT_NAME: TStringField
FieldName = 'SHORT_NAME' FieldName = 'SHORT_NAME'
end end
object xdwdsCustomersADDRESS: TStringField object xdwdsCustomersstaff_fields_invoice_to: TStringField
FieldName = 'ADDRESS' FieldName = 'staff_fields_invoice_to'
Size = 100
end end
end end
object wdsCustomers: TWebDataSource object wdsCustomers: TWebDataSource
DataSet = xdwdsCustomers DataSet = xdwdsCustomers
Left = 476 Left = 650
Top = 61 Top = 23
end end
end end
...@@ -48,19 +48,23 @@ type ...@@ -48,19 +48,23 @@ type
xdwdsCustomersID: TIntegerField; xdwdsCustomersID: TIntegerField;
xdwdsCustomersNAME: TStringField; xdwdsCustomersNAME: TStringField;
xdwdsCustomersSHORT_NAME: TStringField; xdwdsCustomersSHORT_NAME: TStringField;
xdwdsCustomersADDRESS: TStringField;
wdsCustomers: TWebDataSource; wdsCustomers: TWebDataSource;
WebLabel3: TWebLabel; WebLabel3: TWebLabel;
edtJobName: TWebEdit; edtJobName: TWebEdit;
WebLabel4: TWebLabel; WebLabel4: TWebLabel;
btnCancel: TWebButton; btnCancel: TWebButton;
btnClear: TWebButton; btnClear: TWebButton;
xdwdsCustomersstaff_fields_invoice_to: TStringField;
WebLabel5: TWebLabel;
edtCompanyName: TWebEdit;
procedure btnConfirmClick(Sender: TObject); procedure btnConfirmClick(Sender: TObject);
procedure WebFormShow(Sender: TObject); procedure WebFormShow(Sender: TObject);
procedure btnCancelClick(Sender: TObject); procedure btnCancelClick(Sender: TObject);
procedure edtSearchChange(Sender: TObject); procedure edtSearchChange(Sender: TObject);
procedure TMSFNCGrid1CellClick(Sender: TObject; ACol, ARow: Integer); procedure TMSFNCGrid1CellClick(Sender: TObject; ACol, ARow: Integer);
procedure btnClearClick(Sender: TObject); procedure btnClearClick(Sender: TObject);
procedure cbNull1Click(Sender: TObject);
procedure cbNull2Click(Sender: TObject);
private private
//FJSONProc: TJSONProc; //FJSONProc: TJSONProc;
[async] procedure getCustomers; [async] procedure getCustomers;
...@@ -139,7 +143,14 @@ begin ...@@ -139,7 +143,14 @@ begin
dtpEndDate1.Date := StrToDateTime(params.Values['endDate1'], DateFormatSettings); dtpEndDate1.Date := StrToDateTime(params.Values['endDate1'], DateFormatSettings);
if params.values['null1'] <> '' then if params.values['null1'] <> '' then
begin
cbNull1.Checked := StrToBool(params.Values['null1']); cbNull1.Checked := StrToBool(params.Values['null1']);
if StrToBool(params.Values['null1']) then
begin
dtpStartDate1.Visible := false;
dtpEndDate1.Visible := false;
end;
end;
// Status 2 // Status 2
if params.Values['filterType2'] <> '' then if params.Values['filterType2'] <> '' then
...@@ -147,18 +158,26 @@ begin ...@@ -147,18 +158,26 @@ begin
else else
wcbFilterType2.Text := 'NONE'; wcbFilterType2.Text := 'NONE';
if params.Values['startDate2'] = '1899/12/30' then console.log(params.Values['startDate2']);
if params.Values['startDate2'] = '' then
dtpStartDate2.Date := 0 dtpStartDate2.Date := 0
else else
dtpStartDate2.Date := StrToDateTime(params.Values['startDate2'], DateFormatSettings); dtpStartDate2.Date := StrToDateTime(params.Values['startDate2'], DateFormatSettings);
if params.Values['endDate2'] = '1899/12/30' then if params.Values['endDate2'] = '' then
dtpEndDate2.Date := 0 dtpEndDate2.Date := 0
else else
dtpEndDate2.Date := StrToDateTime(params.Values['endDate2'], DateFormatSettings); dtpEndDate2.Date := StrToDateTime(params.Values['endDate2'], DateFormatSettings);
if params.values['null2'] <> '' then if params.values['null2'] <> '' then
begin
cbNull1.Checked := StrToBool(params.Values['null2']); cbNull1.Checked := StrToBool(params.Values['null2']);
if StrToBool(params.Values['null2']) then
begin
dtpStartDate2.Visible := false;
dtpEndDate2.Visible := false;
end;
end;
params.Free; params.Free;
...@@ -193,6 +212,34 @@ begin ...@@ -193,6 +212,34 @@ begin
Close; Close;
end; end;
procedure TFSearch.cbNull1Click(Sender: TObject);
begin
if cbNull1.Checked then
begin
dtpStartDate1.Visible := false;
dtpEndDate1.Visible := false;
end
else
begin
dtpStartDate1.Visible := true;
dtpEndDate1.Visible := true;
end;
end;
procedure TFSearch.cbNull2Click(Sender: TObject);
begin
if cbNull2.Checked then
begin
dtpStartDate2.Visible := false;
dtpEndDate2.Visible := false;
end
else
begin
dtpStartDate2.Visible := true;
dtpEndDate2.Visible := true;
end;
end;
[async] procedure TFSearch.getCustomers(); [async] procedure TFSearch.getCustomers();
var var
xdcResponse: TXDataClientResponse; xdcResponse: TXDataClientResponse;
...@@ -214,6 +261,7 @@ end; ...@@ -214,6 +261,7 @@ end;
procedure TFSearch.TMSFNCGrid1CellClick(Sender: TObject; ACol, ARow: Integer); procedure TFSearch.TMSFNCGrid1CellClick(Sender: TObject; ACol, ARow: Integer);
begin begin
edtCompanyID.Text := TMSFNCGrid1.Cells[0, ARow]; edtCompanyID.Text := TMSFNCGrid1.Cells[0, ARow];
edtCompanyName.Text := TMSFNCGrid1.Cells[2, ARow];
end; end;
procedure TFSearch.PopulateGridManually; procedure TFSearch.PopulateGridManually;
...@@ -247,7 +295,7 @@ begin ...@@ -247,7 +295,7 @@ begin
TMSFNCGrid1.Cells[0, RowIndex] := xdwdsCustomers.FieldByName('ID').AsString; TMSFNCGrid1.Cells[0, RowIndex] := xdwdsCustomers.FieldByName('ID').AsString;
TMSFNCGrid1.Cells[1, RowIndex] := xdwdsCustomers.FieldByName('SHORT_NAME').AsString; TMSFNCGrid1.Cells[1, RowIndex] := xdwdsCustomers.FieldByName('SHORT_NAME').AsString;
TMSFNCGrid1.Cells[2, RowIndex] := xdwdsCustomers.FieldByName('NAME').AsString; TMSFNCGrid1.Cells[2, RowIndex] := xdwdsCustomers.FieldByName('NAME').AsString;
TMSFNCGrid1.Cells[3, RowIndex] := xdwdsCustomers.FieldByName('ADDRESS').AsString; TMSFNCGrid1.Cells[3, RowIndex] := xdwdsCustomers.FieldByName('staff_fields_invoice_to').AsString;
Inc(RowIndex); Inc(RowIndex);
xdwdsCustomers.Next; xdwdsCustomers.Next;
......
...@@ -19,7 +19,8 @@ uses ...@@ -19,7 +19,8 @@ uses
View.Orders in 'View.Orders.pas' {FViewOrders: TWebForm} {*.html}, View.Orders in 'View.Orders.pas' {FViewOrders: TWebForm} {*.html},
View.OrderEntryCorrugated in 'View.OrderEntryCorrugated.pas' {FOrderEntry: TWebForm} {*.html}, View.OrderEntryCorrugated in 'View.OrderEntryCorrugated.pas' {FOrderEntry: TWebForm} {*.html},
View.AddOrder in 'View.AddOrder.pas' {FAddOrder: TWebForm} {*.html}, View.AddOrder in 'View.AddOrder.pas' {FAddOrder: TWebForm} {*.html},
View.Search in 'View.Search.pas' {FSearch: TWebForm} {*.html}; View.Search in 'View.Search.pas' {FSearch: TWebForm} {*.html},
View.PDF in 'View.PDF.pas' {FViewPDF: TWebForm} {*.html};
{$R *.res} {$R *.res}
......
...@@ -180,6 +180,11 @@ ...@@ -180,6 +180,11 @@
<FormType>dfm</FormType> <FormType>dfm</FormType>
<DesignClass>TWebForm</DesignClass> <DesignClass>TWebForm</DesignClass>
</DCCReference> </DCCReference>
<DCCReference Include="View.PDF.pas">
<Form>FViewPDF</Form>
<FormType>dfm</FormType>
<DesignClass>TWebForm</DesignClass>
</DCCReference>
<None Include="index.html"/> <None Include="index.html"/>
<None Include="css\app.css"/> <None Include="css\app.css"/>
<None Include="config\config.json"/> <None Include="config\config.json"/>
......
...@@ -15,12 +15,14 @@ type ...@@ -15,12 +15,14 @@ type
FJWTTokenSecret: string; FJWTTokenSecret: string;
FAdminPassword: string; FAdminPassword: string;
FWebAppFolder: string; FWebAppFolder: string;
FReportsFolder: string;
public public
constructor Create; constructor Create;
property url: string read FUrl write FUrl; property url: string read FUrl write FUrl;
property jwtTokenSecret: string read FJWTTokenSecret write FJWTTokenSecret; property jwtTokenSecret: string read FJWTTokenSecret write FJWTTokenSecret;
property adminPassword: string read FAdminPassword write FAdminPassword; property adminPassword: string read FAdminPassword write FAdminPassword;
property webAppFolder: string read FWebAppFolder write FWebAppFolder; property webAppFolder: string read FWebAppFolder write FWebAppFolder;
property reportsFolder: string read FReportsFolder write FReportsFolder;
end; end;
procedure LoadServerConfig; procedure LoadServerConfig;
...@@ -76,6 +78,7 @@ begin ...@@ -76,6 +78,7 @@ begin
adminPassword := 'whatisthisusedfor'; adminPassword := 'whatisthisusedfor';
jwtTokenSecret := 'super_secret0123super_secret4567'; jwtTokenSecret := 'super_secret0123super_secret4567';
webAppFolder := 'static'; webAppFolder := 'static';
reportsFolder := '..\kgOrdersClient\TMSWeb\Debug\';
// ServerConfigStr := Bcl.Json.TJson.Serialize( ServerConfig ); // ServerConfigStr := Bcl.Json.TJson.Serialize( ServerConfig );
// ConfigFile := 'serverconfig.json'; // ConfigFile := 'serverconfig.json';
// TFile.WriteAllText( ConfigFile, ServerConfigStr ); // TFile.WriteAllText( ConfigFile, ServerConfigStr );
......
...@@ -230,7 +230,7 @@ type ...@@ -230,7 +230,7 @@ type
[HttpGet] function GetOrder(orderInfo: string): TFullOrder; [HttpGet] function GetOrder(orderInfo: string): TFullOrder;
[HttpGet] function GetCustomers(): TCustomerList; [HttpGet] function GetCustomers(): TCustomerList;
[HttpGet] function GetCustomer(ID: string): TCustomerItem; [HttpGet] function GetCustomer(ID: string): TCustomerItem;
[HttpGet] procedure GenerateReportPDF(searchOptions: string); [HttpGet] function GenerateReportPDF(searchOptions: string): string;
function AddUser(userInfo: string): string; function AddUser(userInfo: string): string;
......
...@@ -35,20 +35,20 @@ type ...@@ -35,20 +35,20 @@ type
function GetCustomer(ID: string): TCustomerItem; function GetCustomer(ID: string): TCustomerItem;
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); function GenerateReportPDF(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;
function generateSelectSQL(filterType, startDate, endDate: string): string; function GenerateSelectSQL(filterType, startDate, endDate: string): string;
function generateSubQuery(currStatus: string): string; function GenerateSubQuery(currStatus: string): string;
function AddCorrugatedOrder(orderInfo: string): TJSONObject; function AddCorrugatedOrder(orderInfo: string): TJSONObject;
function AddStatusSchedule(StatusType: string; order: TJSONObject; ORDER_ID: integer): string; function AddStatusSchedule(StatusType: string; order: TJSONObject; ORDER_ID: integer): string;
function EditStatusSchedule(StatusType: string; order: TJSONObject; ORDER_ID: string): string; function EditStatusSchedule(StatusType: string; order: TJSONObject; ORDER_ID: string): string;
function generateOrdersSQL(searchOptions: string): TSQLQuery; function GenerateOrdersSQL(searchOptions: string): TSQLQuery;
function getColorCount(colors: string): string; function GetColorCount(colors: string): string;
function generateStatusSelectSQL(statusTableShort, statusTableLong, startDate, endDate, statusType: string): string; function GenerateStatusSelectSQL(statusTableShort, statusTableLong, startDate, endDate, statusType: string): string;
function generateStatusWhereSQL(status: TStatusSearchInfo): string; function GenerateStatusWhereSQL(status: TStatusSearchInfo): string;
function createStatusSearchInfo(params: TStringList; statusNum: string): TStatusSearchInfo; function CreateStatusSearchInfo(params: TStringList; statusNum: string): TStatusSearchInfo;
procedure AfterConstruction; override; procedure AfterConstruction; override;
procedure BeforeDestruction; override; procedure BeforeDestruction; override;
end; end;
...@@ -74,7 +74,7 @@ end; ...@@ -74,7 +74,7 @@ end;
function TLookupService.GetCustomers: TCustomerList; function TLookupService.GetCustomers: TCustomerList;
var var
SQL, ADDRESS: string; SQL: string;
customer: TCustomerItem; customer: TCustomerItem;
begin begin
SQL := 'select NAME, CUSTOMER_ID, SHORT_NAME, BILL_ADDRESS, BILL_CITY, BILL_STATE, BILL_ZIP from customers'; SQL := 'select NAME, CUSTOMER_ID, SHORT_NAME, BILL_ADDRESS, BILL_CITY, BILL_STATE, BILL_ZIP from customers';
...@@ -168,7 +168,7 @@ begin ...@@ -168,7 +168,7 @@ begin
end; end;
procedure TLookupService.GenerateReportPDF(searchOptions: string); function TLookupService.GenerateReportPDF(searchOptions: string): string;
var var
SQL: string; SQL: string;
rptOrders: TrptOrders; // Local instance of rptOrders rptOrders: TrptOrders; // Local instance of rptOrders
...@@ -180,13 +180,13 @@ begin ...@@ -180,13 +180,13 @@ begin
SQL := GenerateOrdersSQL(searchOptions).SQL; SQL := GenerateOrdersSQL(searchOptions).SQL;
// Prepare the report dataset // Prepare the report dataset
rptOrders.PrepareReport(SQL); result := rptOrders.PrepareReport(SQL);
// Generate the PDF report // Generate the PDF report
rptOrders.GeneratePDF; //rptOrders.GeneratePDF;
// Optionally, log success // Optionally, log success
Logger.log(5, 'PDF Report successfully generated for searchOptions: ' + searchOptions); Logger.log(5, 'PDF Report successfully generated for searchOptions: ' + searchOptions);
finally finally
rptOrders.Free; rptOrders.Free;
end; end;
...@@ -213,10 +213,14 @@ begin ...@@ -213,10 +213,14 @@ begin
result := 'exists ( select 1 from ' + statusTableLong + ' ' + result := 'exists ( select 1 from ' + statusTableLong + ' ' +
statusTableShort + ' where ' + statusTableShort + '.ORDER_ID = ' + statusTableShort + ' where ' + statusTableShort + '.ORDER_ID = ' +
'o.ORDER_ID AND ' + statusTableShort + '.ORDER_STATUS = ' + 'o.ORDER_ID AND ' + statusTableShort + '.ORDER_STATUS = ' +
quotedStr(statusType) + ' AND ' + quotedStr(startDate) + quotedStr(statusType);
' <= STATUS_DATE';
if startDate <> '' then
begin
result := result + ' AND ' + quotedStr(endDate) + ' <= STATUS_DATE';
end;
if endDate <> '1899/12/30' then if ( ( endDate <> '1899/12/30' ) AND ( endDate <> '' ) ) then
begin begin
result := result + ' AND ' + quotedStr(endDate) + ' >= STATUS_DATE'; result := result + ' AND ' + quotedStr(endDate) + ' >= STATUS_DATE';
end; end;
...@@ -231,7 +235,8 @@ begin ...@@ -231,7 +235,8 @@ begin
result := TStatusSearchInfo.Create; result := TStatusSearchInfo.Create;
result.startDate := params.Values['startDate' + statusNum]; result.startDate := params.Values['startDate' + statusNum];
result.endDate := params.Values['endDate' + statusNum]; result.endDate := params.Values['endDate' + statusNum];
result.null := StrToBool(params.Values['null' + statusNum]); if params.Values['null' + statusNum] <> '' then
result.null := StrToBool(params.Values['null' + statusNum]);
result.statusType := ''; result.statusType := '';
result.filterType := ''; result.filterType := '';
......
...@@ -3,7 +3,7 @@ object rptOrders: TrptOrders ...@@ -3,7 +3,7 @@ object rptOrders: TrptOrders
Height = 480 Height = 480
Width = 640 Width = 640
object frxOrders: TfrxReport object frxOrders: TfrxReport
Version = '2025.1.3' Version = '2024.2.1'
DotMatrixReport = False DotMatrixReport = False
IniFile = '\Software\Fast Reports' IniFile = '\Software\Fast Reports'
PreviewOptions.Buttons = [pbPrint, pbLoad, pbSave, pbExport, pbZoom, pbFind, pbOutline, pbPageSetup, pbTools, pbEdit, pbNavigator, pbExportQuick, pbCopy, pbSelection] PreviewOptions.Buttons = [pbPrint, pbLoad, pbSave, pbExport, pbZoom, pbFind, pbOutline, pbPageSetup, pbTools, pbEdit, pbNavigator, pbExportQuick, pbCopy, pbSelection]
......
...@@ -38,14 +38,11 @@ type ...@@ -38,14 +38,11 @@ type
procedure uqOrdersCalcFields(DataSet: TDataSet); procedure uqOrdersCalcFields(DataSet: TDataSet);
private private
function BuildOrderQuery(searchOptions: string): string;
function generateSubQuery(filterType, statusType,
currStatus: string): string;
function getColorCount(colors: string): string; function getColorCount(colors: string): string;
public public
procedure PrepareReport(searchOptions: string); function PrepareReport(SQL: string): string;
procedure GeneratePDF; function GeneratePDF: string;
end; end;
var var
...@@ -54,7 +51,7 @@ var ...@@ -54,7 +51,7 @@ var
implementation implementation
uses uses
uLibrary; uLibrary, Common.Config;
{%CLASSGROUP 'Vcl.Controls.TControl'} {%CLASSGROUP 'Vcl.Controls.TControl'}
...@@ -75,11 +72,8 @@ begin ...@@ -75,11 +72,8 @@ begin
end; end;
procedure TrptOrders.PrepareReport(searchOptions: string); function TrptOrders.PrepareReport(SQL: string): string;
var
SQL: string;
begin begin
SQL := BuildOrderQuery(searchOptions);
Logger.Log(5, 'Generated SQL for Prepare Report: ' + SQL); Logger.Log(5, 'Generated SQL for Prepare Report: ' + SQL);
uqOrders.Close; uqOrders.Close;
...@@ -87,7 +81,7 @@ begin ...@@ -87,7 +81,7 @@ begin
uqOrders.Open; uqOrders.Open;
GeneratePDF; result := GeneratePDF;
Logger.Log(5, 'Report preparation complete.'); Logger.Log(5, 'Report preparation complete.');
end; end;
...@@ -124,8 +118,7 @@ begin ...@@ -124,8 +118,7 @@ begin
end; end;
end; end;
//create new field called color count
function TrptOrders.getColorCount(colors: string): string; function TrptOrders.getColorCount(colors: string): string;
var var
colorObject: TJSONObject; colorObject: TJSONObject;
...@@ -145,168 +138,35 @@ begin ...@@ -145,168 +138,35 @@ begin
end; end;
end; end;
function TrptOrders.GeneratePDF: string;
// Builds a dynamic SQL query based on the search options
function TrptOrders.BuildOrderQuery(searchOptions: string): string;
var
params: TStringList;
PageNum, PageSize: Integer;
startDate, endDate, filterType, statusType, statusSuffix: string;
statusTableShort, statusTableLong, whereSQL, SQL: string;
begin
params := TStringList.Create;
try
params.StrictDelimiter := True;
params.Delimiter := '&';
params.DelimitedText := searchOptions;
// Parse parameters
PageNum := StrToIntDef(params.Values['pagenumber'], 1);
PageSize := StrToIntDef(params.Values['pagesize'], 50);
startDate := params.Values['startDate'];
endDate := params.Values['endDate'];
filterType := params.Values['filterType'];
statusType := '';
statusSuffix := '';
if filterType <> '' then
begin
statusType := filterType.Split(['_'])[0];
statusSuffix := filterType.Split(['_'])[1];
filterType := statusType + '_' + statusSuffix;
end;
// Determine which status table to use
if statusSuffix = 'DUE' then
begin
statusTableShort := 'oss';
statusTableLong := 'orders_status_schedule';
end
else
begin
statusTableShort := 'os';
statusTableLong := 'orders_status';
end;
SQL := 'SELECT o.ORDER_ID, ';
if filterType <> '' then
SQL := SQL + statusTableShort + '.STATUS_DATE AS ' + filterType.ToUpper + ', ';
SQL := SQL +
'o.LOCATION AS Loc, c.NAME AS COMPANY_NAME, o.JOB_NAME, o.ORDER_DATE, o.ORDER_TYPE, ';
SQL := SQL + generateSubQuery(filterType, statusType, 'PROOF');
SQL := SQL + generateSubQuery(filterType, statusType, 'ART');
SQL := SQL + generateSubQuery(filterType, statusType, 'PLATE');
SQL := SQL + generateSubQuery(filterType, statusType, 'MOUNT');
SQL := SQL + generateSubQuery(filterType, statusType, 'SHIP');
SQL := SQL + 'o.PRICE, qb.QB_REF_NUM ' +
'FROM orders o ' +
'JOIN ' + statusTableLong + ' ' + statusTableShort +
' ON ' + statusTableShort + '.ORDER_ID = o.ORDER_ID ' +
'JOIN customers c ON c.CUSTOMER_ID = o.COMPANY_ID ' +
'LEFT JOIN qb_sales_orders qb ON qb.ORDER_ID = o.ORDER_ID ';
whereSQL := 'WHERE 1=1 ';
if startDate <> '' then
whereSQL := whereSQL + ' AND o.ORDER_DATE >= ' + QuotedStr(startDate);
if endDate <> '' then
whereSQL := whereSQL + ' AND o.ORDER_DATE <= ' + QuotedStr(endDate);
if statusType <> '' then
whereSQL := whereSQL + ' AND ' + statusTableShort + '.ORDER_STATUS = ' + QuotedStr(statusType);
SQL := SQL + whereSQL;
SQL := SQL + ' ORDER BY o.ORDER_DATE DESC ' +
'LIMIT ' + IntToStr(PageSize) + ' OFFSET ' + IntToStr((PageNum - 1) * PageSize);
Result := SQL;
finally
params.Free;
end;
end;
function TrptOrders.generateSubQuery(filterType, statusType, currStatus: string): string;
var
statusSuffix: string;
begin
Result := '';
statusSuffix := '';
if filterType <> '' then
statusSuffix := filterType.Split(['_'])[1];
if statusType <> currStatus then
begin
if (statusSuffix = 'DUE') or (statusSuffix = '') then
begin
Result := Result +
'(SELECT oss.STATUS_DATE FROM orders_status_schedule oss ' +
'WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ' + QuotedStr(currStatus) + ') AS ' + currStatus + '_DUE, ';
end
else
begin
Result := Result +
'(SELECT os.STATUS_TIMESTAMP FROM orders_status os ' +
'WHERE os.ORDER_ID = o.ORDER_ID AND os.ORDER_STATUS = ' + QuotedStr(currStatus) +
' ORDER BY os.STATUS_TIMESTAMP DESC LIMIT 1) AS ' + currStatus + '_DONE, ';
end;
end;
if (statusSuffix = 'DUE') or (statusSuffix = '') then
begin
Result := Result +
'(SELECT os.STATUS_TIMESTAMP FROM orders_status os ' +
'WHERE os.ORDER_ID = o.ORDER_ID AND os.ORDER_STATUS = ' + QuotedStr(currStatus) +
' ORDER BY os.STATUS_TIMESTAMP DESC LIMIT 1) AS ' + currStatus + '_DONE, ';
end
else
begin
Result := Result +
'(SELECT oss.STATUS_DATE FROM orders_status_schedule oss ' +
'WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ' + QuotedStr(currStatus) + ') AS ' + currStatus + '_DUE, ';
end;
end;
//create new field called color count
procedure TrptOrders.GeneratePDF;
var var
ReportDir, ReportFileName: string; ReportDir, ReportFileName: string;
reportURL: string;
begin begin
ReportDir := 'C:\Projects\KGOrders\Reports'; ReportDir := ServerConfig.reportsFolder;
if not DirectoryExists(ReportDir) then if not DirectoryExists(ReportDir) then
begin begin
ForceDirectories(ReportDir); ForceDirectories(ReportDir);
Logger.Log(5, 'Reports directory created: ' + ReportDir); Logger.Log(5, 'Reports directory created: ' + ReportDir);
end; end;
reportURL := 'reports\' + FormatDateTime('yyyymmdd_hhnnss', Now) + '.pdf';
ReportFileName := TPath.Combine(ReportDir, 'OrderReport_' + FormatDateTime('yyyymmdd_hhnnss', Now) + '.pdf'); ReportFileName := reportDir + reportUrl;
frxPDFExport1.FileName := ReportFileName; frxPDFExport1.FileName := ReportFileName;
frxPDFExport1.ShowDialog := False; frxPDFExport1.ShowDialog := False;
try try
frxOrders.PrepareReport; frxOrders.PrepareReport;
frxOrders.Export(frxPDFExport1); frxOrders.Export(frxPDFExport1);
frxOrders.ShowPreparedReport; //frxOrders.ShowPreparedReport;
finally finally
frxOrders.Clear; // Clear the report to avoid memory bloat frxOrders.Clear; // Clear the report to avoid memory bloat
end; end;
Logger.Log(5, 'PDF saved to: ' + ReportFileName); Logger.Log(5, 'PDF saved to: ' + ReportFileName);
result := reportURL;
end; end;
end. end.
[Settings] [Settings]
MemoLogLevel=4 MemoLogLevel=4
FileLogLevel=5 FileLogLevel=5
LogFileNum=35 LogFileNum=55
webClientVersion=1.0.0 webClientVersion=1.0.0
[Database] [Database]
--Server=192.168.159.132 Server=192.168.159.132
Server=192.168.100.130 --Server=192.168.100.130
--Server=192.168.75.133 --Server=192.168.75.133
--Database= --Database=
--Username= --Username=
Password=emsys!012 --Password=emsys!012
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