Commit 06a2b66b by cam

Filters are now working and SQL statement has been condensed

parent 15d63c28
...@@ -23,8 +23,8 @@ object FViewOrders: TFViewOrders ...@@ -23,8 +23,8 @@ object FViewOrders: TFViewOrders
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
end end
object wcbPageSize: TWebComboBox object wcbPageSize: TWebComboBox
Left = 0 Left = -4
Top = 0 Top = 52
Width = 145 Width = 145
Height = 21 Height = 21
ElementClassName = 'custom-select' ElementClassName = 'custom-select'
...@@ -41,8 +41,8 @@ object FViewOrders: TFViewOrders ...@@ -41,8 +41,8 @@ object FViewOrders: TFViewOrders
'50') '50')
end end
object wcbSortBy: TWebComboBox object wcbSortBy: TWebComboBox
Left = 442 Left = 0
Top = 52 Top = 18
Width = 145 Width = 145
Height = 21 Height = 21
ElementClassName = 'custom-select' ElementClassName = 'custom-select'
...@@ -50,16 +50,19 @@ object FViewOrders: TFViewOrders ...@@ -50,16 +50,19 @@ object FViewOrders: TFViewOrders
ElementFont = efCSS ElementFont = efCSS
HeightStyle = ssAuto HeightStyle = ssAuto
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
Text = 'Date' Text = 'PROOF'
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
ItemIndex = -1 ItemIndex = -1
Items.Strings = ( Items.Strings = (
'Date' 'PROOF'
'Phone Number') 'ART'
'PLATE'
'MOUNT'
'SHIP')
end end
object btnApply: TWebButton object btnApply: TWebButton
Left = 478 Left = 542
Top = 128 Top = 16
Width = 96 Width = 96
Height = 25 Height = 25
Caption = 'Apply' Caption = 'Apply'
...@@ -88,8 +91,8 @@ object FViewOrders: TFViewOrders ...@@ -88,8 +91,8 @@ object FViewOrders: TFViewOrders
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
end end
object btnaddOrder: TWebButton object btnaddOrder: TWebButton
Left = 236 Left = 0
Top = 166 Top = 79
Width = 96 Width = 96
Height = 25 Height = 25
Caption = 'Add Order' Caption = 'Add Order'
...@@ -102,6 +105,53 @@ object FViewOrders: TFViewOrders ...@@ -102,6 +105,53 @@ object FViewOrders: TFViewOrders
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
OnClick = btnaddOrderClick OnClick = btnaddOrderClick
end end
object btnFilters: TWebButton
Left = 542
Top = 50
Width = 96
Height = 25
Caption = 'Show Filters'
ChildOrder = 6
ElementClassName = 'btn btn-light'
ElementID = 'btnfilters'
ElementFont = efCSS
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = btnFiltersClick
end
object dtpStartDate: TWebDateTimePicker
Left = 168
Top = 16
Width = 170
Height = 22
ElementClassName = 'form-control'
ElementID = 'dtpstartdate'
HeightStyle = ssAuto
BorderStyle = bsSingle
ChildOrder = 7
Color = clWhite
Date = 45553.505972858790000000
ElementFont = efCSS
Role = ''
Text = ''
end
object dtpEndDate: TWebDateTimePicker
Left = 356
Top = 16
Width = 170
Height = 22
ElementClassName = 'form-control'
ElementID = 'dtpenddate'
HeightStyle = ssAuto
BorderStyle = bsSingle
ChildOrder = 7
Color = clWhite
Date = 45553.505972858790000000
ElementFont = efCSS
Role = ''
Text = ''
end
object XDataWebClient1: TXDataWebClient object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection Connection = DMConnection.ApiConnection
Left = 426 Left = 426
......
...@@ -4,25 +4,43 @@ ...@@ -4,25 +4,43 @@
<div class="container mt-4"> <div class="container mt-4">
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-12 col-md-8"> <div class="col-12 col-md-8">
<form class="form-inline"> <div class="mb-3" id="filter_info" style="display: none;">
<h4 class="custom-h4 mt-3">Filters</h4>
<hr class="custom-hr">
<div class="row"> <div class="row">
<div class="col-sm-6"> <div class="col-auto">
<label class='pe-2'style="font-weight: 700;">Search:</label> <label class='pe-2'style="font-weight: 700;">Search:</label>
<input class="form-control input-sm" id="edtsearch"> <input class="form-control input-sm" id="edtsearch">
</div> </div>
<div class="col-auto">
<label class='pe-2'style="font-weight: 700;">Start Date:</label>
<input class="form-control input-sm" id="dtpstartdate" type="date">
</div>
<div class="col-auto">
<label class='pe-2'style="font-weight: 700;">End Date:</label>
<input class="form-control input-sm" id="dtpenddate" type="date">
</div>
<div class="col-auto">
<label class="py-2" style="font-weight: 700;">Status Type:</label>
<select class="custom-select" id="wcbsortby" style="font-size: 1.00rem;"></select>
</div>
</div>
<div class ="row mt-2">
<div class="col-auto">
<button class= "mt2-2" id="btnapply"></button>
</div>
</div>
</div> </div>
</form>
<form class="form-inline"> <form class="form-inline">
<div class= "row"> <div class= "row">
<div class="col-sm-5"> <div class="col-sm-5">
<label class="py-2" style="font-weight: 700;">Show <select class="custom-select" id="wcbpagesize" style="font-size: 1.00rem;"></select> entries</label> <label class="py-2" style="font-weight: 700;">Show <select class="custom-select" id="wcbpagesize" style="font-size: 1.00rem;"></select> entries</label>
</div> </div>
<div class="col-sm-5"> <div class="col-sm-5">
<label class="py-2" style="font-weight: 700;">Sorted by:</label>
<select class="custom-select" id="wcbsortby" style="font-size: 1.00rem;"></select>
</div> </div>
<div class="col-sm-2"> <div class="col-sm-2">
<button class= "ps-3" id="btnapply"></button> <button class= "ps-3" id="btnfilters"></button>
</div> </div>
<div class="col-sm-2"> <div class="col-sm-2">
<button class= "ps-3" id="btnaddorder"></button> <button class= "ps-3" id="btnaddorder"></button>
......
...@@ -40,10 +40,14 @@ type ...@@ -40,10 +40,14 @@ type
XDataWebDataSet1qbRefNum: TStringField; XDataWebDataSet1qbRefNum: TStringField;
XDataWebDataSet1colors: TStringField; XDataWebDataSet1colors: TStringField;
btnaddOrder: TWebButton; btnaddOrder: TWebButton;
btnFilters: TWebButton;
dtpStartDate: TWebDateTimePicker;
dtpEndDate: TWebDateTimePicker;
procedure WebFormCreate(Sender: TObject); procedure WebFormCreate(Sender: TObject);
procedure btnApplyClick(Sender: TObject); procedure btnApplyClick(Sender: TObject);
procedure btnSearchClick(Sender: TObject); procedure btnSearchClick(Sender: TObject);
procedure btnaddOrderClick(Sender: TObject); procedure btnaddOrderClick(Sender: TObject);
procedure btnFiltersClick(Sender: TObject);
private private
FChildForm: TWebForm; FChildForm: TWebForm;
procedure AddRowToTable(temp: string); procedure AddRowToTable(temp: string);
...@@ -62,6 +66,7 @@ type ...@@ -62,6 +66,7 @@ type
EndDate: string; EndDate: string;
OrderBy: string; OrderBy: string;
Caller: string; Caller: string;
filters: boolean;
public public
end; end;
...@@ -82,11 +87,17 @@ procedure TFViewOrders.WebFormCreate(Sender: TObject); ...@@ -82,11 +87,17 @@ procedure TFViewOrders.WebFormCreate(Sender: TObject);
// 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
// TotalPages: Total number of pages returned from the search. // TotalPages: Total number of pages returned from the search.
// PageSize: Number of entries per page. // PageSize: Number of entries per page.
var
today: TDateTime;
begin begin
DMConnection.ApiConnection.Connected := True; DMConnection.ApiConnection.Connected := True;
PageNumber := 1; PageNumber := 1;
TotalPages := 1; // Initial total pages TotalPages := 1; // Initial total pages
wcbPageSize.Text := '10'; wcbPageSize.Text := '10';
wcbSortBy.Text := 'PROOF';
//today := TDateTime.Today;
dtpStartDate.Date := Now;
dtpEndDate.Date := Now;
getOrders(GenerateSearchOptions()); getOrders(GenerateSearchOptions());
end; end;
...@@ -510,10 +521,33 @@ begin ...@@ -510,10 +521,33 @@ begin
OrderBy := wcbSortBy.Text; OrderBy := wcbSortBy.Text;
searchOptions := '&pagenumber=' + IntToStr(PageNumber) + searchOptions := '&pagenumber=' + IntToStr(PageNumber) +
'&pagesize=' + IntToStr(PageSize) + '&pagesize=' + IntToStr(PageSize) +
'&orderby=' + OrderBy; '&orderby=' + OrderBy +
'&startDate=' + FormatDateTime('yyyy/mm/dd', dtpStartDate.Date) +
'&endDate=' + FormatDateTime('yyyy/mm/dd', dtpEndDate.Date) +
'&filterType=' + wcbSortBy.Text;
GetOrders(searchOptions); GetOrders(searchOptions);
end; end;
procedure TFViewOrders.btnFiltersClick(Sender: TObject);
var
filterSection: TJSHTMLElement;
begin
if btnFilters.Caption = 'Show Filters' then
begin
btnFilters.Caption := 'Hide Filters';
filterSection := TJSHTMLElement(document.getElementById('filter_info'));
if Assigned(filterSection) then
filterSection.style.setProperty('display', 'block');
end
else
begin
btnFilters.Caption := 'Show Filters';
filterSection := TJSHTMLElement(document.getElementById('filter_info'));
if Assigned(filterSection) then
filterSection.style.setProperty('display', 'none');
end;
end;
procedure TFViewOrders.Search(searchOptions: string); procedure TFViewOrders.Search(searchOptions: string);
// Search method that searches the database for a specific phone number // Search method that searches the database for a specific phone number
var var
......
...@@ -30,6 +30,8 @@ type ...@@ -30,6 +30,8 @@ type
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 generateSubQuery(filterType: string; currStatus: string): string;
procedure AfterConstruction; override; procedure AfterConstruction; override;
procedure BeforeDestruction; override; procedure BeforeDestruction; override;
end; end;
...@@ -90,6 +92,24 @@ begin ...@@ -90,6 +92,24 @@ begin
end; end;
function TLookupService.generateSelectSQL(filterType, startDate, endDate: string): string;
begin
end;
function TLookupService.generateSubQuery(filterType: string; currStatus: string): string;
begin
result := '';
if filterType <> currStatus 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;
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;
function TLookupService.GetOrders(searchOptions: string): TOrderList; function TLookupService.GetOrders(searchOptions: string): TOrderList;
var var
params: TStringList; params: TStringList;
...@@ -106,6 +126,7 @@ var ...@@ -106,6 +126,7 @@ var
colors: string; colors: string;
ColorType: string; ColorType: string;
whereSQL: string; whereSQL: string;
fromSQL: string;
begin begin
params := TStringList.Create; params := TStringList.Create;
params.StrictDelimiter := true; params.StrictDelimiter := true;
...@@ -116,12 +137,15 @@ begin ...@@ -116,12 +137,15 @@ begin
PageNum := StrToInt(params.Values['pagenumber']); PageNum := StrToInt(params.Values['pagenumber']);
PageSize := StrToInt(params.Values['pagesize']); PageSize := StrToInt(params.Values['pagesize']);
OrderBy := params.Values['orderby']; OrderBy := params.Values['orderby'];
startDate := params.Values['startDate'];
endDate := params.Values['endDate'];
filterType := params.Values['filterType'];
offset := IntToStr((PageNum - 1) * PageSize); offset := IntToStr((PageNum - 1) * PageSize);
limit := IntToStr(PageSize); limit := IntToStr(PageSize);
whereSQL := 'WHERE '; whereSQL := 'WHERE ';
SQL := 'SELECT o.ORDER_ID, o.LOCATION AS Loc, c.NAME AS COMPANY_NAME, o.JOB_NAME, o.ORDER_DATE, o.ORDER_TYPE, ' + {SQL := 'SELECT o.ORDER_ID, o.LOCATION AS Loc, c.NAME AS COMPANY_NAME, o.JOB_NAME, o.ORDER_DATE, o.ORDER_TYPE, ' +
'(SELECT oss.STATUS_DATE ' + '(SELECT oss.STATUS_DATE ' +
' FROM orders_status_schedule oss '; ' FROM orders_status_schedule oss ';
...@@ -142,7 +166,7 @@ begin ...@@ -142,7 +166,7 @@ begin
end end
else else
begin begin
whereSQL := whereSQL + 'AND ' + whereSQL := whereSQL + ' AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE ) '; quotedStr(endDate) + ' >= oss.STATUS_DATE ) ';
end; end;
end end
...@@ -171,8 +195,8 @@ begin ...@@ -171,8 +195,8 @@ begin
begin begin
if startDate <> '' then if startDate <> '' then
begin begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''ART'' AND ' + whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''ART'' AND oss.STATUS_DATE >= ' +
quotedStr(startDate) +' <= oss.STATUS_DATE'; quotedStr(startDate);
end; end;
if endDate <> '' then if endDate <> '' then
begin begin
...@@ -183,8 +207,7 @@ begin ...@@ -183,8 +207,7 @@ begin
end end
else else
begin begin
whereSQL := whereSQL + 'AND ' + whereSQL := whereSQL + ' AND oss.STATUS_DATE <= ' + quotedStr(endDate);
quotedStr(endDate) + ' >= oss.STATUS_DATE ) ';
end; end;
end end
else else
...@@ -323,7 +346,40 @@ begin ...@@ -323,7 +346,40 @@ begin
'JOIN customers c ON c.CUSTOMER_ID = o.COMPANY_ID ' + 'JOIN customers c ON c.CUSTOMER_ID = o.COMPANY_ID ' +
'LEFT JOIN qb_sales_orders qb ON qb.ORDER_ID = o.ORDER_ID ' + 'LEFT JOIN qb_sales_orders qb ON qb.ORDER_ID = o.ORDER_ID ' +
'ORDER BY o.ORDER_DATE DESC ' + 'ORDER BY o.ORDER_DATE DESC ' +
'LIMIT ' + limit + ' OFFSET ' + offset; 'LIMIT ' + limit + ' OFFSET ' + offset; }
if filterType <> '' then
begin
SQL := 'SELECT o.ORDER_ID, oss.STATUS_DATE AS '+ filterType.ToUpper + '_DUE'+
', o.LOCATION AS Loc, c.NAME AS COMPANY_NAME, o.JOB_NAME, o.ORDER_DATE, o.ORDER_TYPE, ';
end
else
begin
SQL := 'SELECT o.ORDER_ID, o.LOCATION AS Loc, c.NAME AS COMPANY_NAME, o.JOB_NAME, o.ORDER_DATE, o.ORDER_TYPE, '
end;
SQL := SQL + generateSubquery(filterType, 'PROOF');
SQL := SQL + generateSubquery(filterType, 'ART');
SQL := SQL + generateSubquery(filterType, 'PLATE');
SQL := SQL + generateSubquery(filterType, 'MOUNT');
SQL := SQL + generateSubquery(filterType, 'SHIP');
if filterType <> '' then
begin
whereSQL := 'FROM orders o join orders_status_schedule oss on oss.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 ' +
'WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = '+ quotedStr(filterType) +
' AND ' + quotedStr(startDate) + ' <= oss.STATUS_DATE AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE';
SQL := SQL + 'o.PRICE, qb.QB_REF_NUM ' + whereSQL + ' ORDER BY ' + filterType + '_DUE DESC';
end
else
begin
whereSQL := 'from orders o join customers c on ' +
'c.CUSTOMER_ID = o.COMPANY_ID left join qb_sales_orders qb on qb.ORDER_ID = o.ORDER_ID ' +
'ORDER BY o.ORDER_DATE DESC';
SQL := SQL + 'o.PRICE, qb.QB_REF_NUM ' + whereSQL + ' LIMIT ' + limit + ' OFFSET ' + offset;
end;
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
...@@ -371,10 +427,7 @@ begin ...@@ -371,10 +427,7 @@ begin
end; end;
ordersDB.UniQuery1.Close; ordersDB.UniQuery1.Close;
SQL := 'SELECT COUNT(*) AS total_count '+ SQL := 'SELECT COUNT(*) AS total_count ' + whereSQL;
'FROM orders o ' +
'JOIN customers c ON c.CUSTOMER_ID = o.COMPANY_ID ' +
'LEFT JOIN qb_sales_orders qb ON qb.ORDER_ID = o.ORDER_ID';
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
Result.count := ordersDB.UniQuery1.FieldByName('total_count').AsInteger; Result.count := ordersDB.UniQuery1.FieldByName('total_count').AsInteger;
......
[Options] [Options]
LogFileNum=110 LogFileNum=129
UpdateTimerLength=0 UpdateTimerLength=0
......
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