Commit 06a2b66b by cam

Filters are now working and SQL statement has been condensed

parent 15d63c28
......@@ -23,8 +23,8 @@ object FViewOrders: TFViewOrders
WidthPercent = 100.000000000000000000
end
object wcbPageSize: TWebComboBox
Left = 0
Top = 0
Left = -4
Top = 52
Width = 145
Height = 21
ElementClassName = 'custom-select'
......@@ -41,8 +41,8 @@ object FViewOrders: TFViewOrders
'50')
end
object wcbSortBy: TWebComboBox
Left = 442
Top = 52
Left = 0
Top = 18
Width = 145
Height = 21
ElementClassName = 'custom-select'
......@@ -50,16 +50,19 @@ object FViewOrders: TFViewOrders
ElementFont = efCSS
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
Text = 'Date'
Text = 'PROOF'
WidthPercent = 100.000000000000000000
ItemIndex = -1
Items.Strings = (
'Date'
'Phone Number')
'PROOF'
'ART'
'PLATE'
'MOUNT'
'SHIP')
end
object btnApply: TWebButton
Left = 478
Top = 128
Left = 542
Top = 16
Width = 96
Height = 25
Caption = 'Apply'
......@@ -88,8 +91,8 @@ object FViewOrders: TFViewOrders
WidthPercent = 100.000000000000000000
end
object btnaddOrder: TWebButton
Left = 236
Top = 166
Left = 0
Top = 79
Width = 96
Height = 25
Caption = 'Add Order'
......@@ -102,6 +105,53 @@ object FViewOrders: TFViewOrders
WidthPercent = 100.000000000000000000
OnClick = btnaddOrderClick
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
Connection = DMConnection.ApiConnection
Left = 426
......
......@@ -4,25 +4,43 @@
<div class="container mt-4">
<div class="row justify-content-center">
<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="col-sm-6">
<div class="col-auto">
<label class='pe-2'style="font-weight: 700;">Search:</label>
<input class="form-control input-sm" id="edtsearch">
</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>
</form>
<form class="form-inline">
<div class= "row">
<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>
</div>
<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 class="col-sm-2">
<button class= "ps-3" id="btnapply"></button>
<button class= "ps-3" id="btnfilters"></button>
</div>
<div class="col-sm-2">
<button class= "ps-3" id="btnaddorder"></button>
......
......@@ -40,10 +40,14 @@ type
XDataWebDataSet1qbRefNum: TStringField;
XDataWebDataSet1colors: TStringField;
btnaddOrder: TWebButton;
btnFilters: TWebButton;
dtpStartDate: TWebDateTimePicker;
dtpEndDate: TWebDateTimePicker;
procedure WebFormCreate(Sender: TObject);
procedure btnApplyClick(Sender: TObject);
procedure btnSearchClick(Sender: TObject);
procedure btnaddOrderClick(Sender: TObject);
procedure btnFiltersClick(Sender: TObject);
private
FChildForm: TWebForm;
procedure AddRowToTable(temp: string);
......@@ -62,6 +66,7 @@ type
EndDate: string;
OrderBy: string;
Caller: string;
filters: boolean;
public
end;
......@@ -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
// TotalPages: Total number of pages returned from the search.
// PageSize: Number of entries per page.
var
today: TDateTime;
begin
DMConnection.ApiConnection.Connected := True;
PageNumber := 1;
TotalPages := 1; // Initial total pages
wcbPageSize.Text := '10';
wcbSortBy.Text := 'PROOF';
//today := TDateTime.Today;
dtpStartDate.Date := Now;
dtpEndDate.Date := Now;
getOrders(GenerateSearchOptions());
end;
......@@ -510,10 +521,33 @@ begin
OrderBy := wcbSortBy.Text;
searchOptions := '&pagenumber=' + IntToStr(PageNumber) +
'&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);
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);
// Search method that searches the database for a specific phone number
var
......
......@@ -30,6 +30,8 @@ type
function AddUser(userInfo: string): string;
function AddItem(itemInfo: 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 BeforeDestruction; override;
end;
......@@ -90,6 +92,24 @@ begin
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;
var
params: TStringList;
......@@ -106,6 +126,7 @@ var
colors: string;
ColorType: string;
whereSQL: string;
fromSQL: string;
begin
params := TStringList.Create;
params.StrictDelimiter := true;
......@@ -116,12 +137,15 @@ begin
PageNum := StrToInt(params.Values['pagenumber']);
PageSize := StrToInt(params.Values['pagesize']);
OrderBy := params.Values['orderby'];
startDate := params.Values['startDate'];
endDate := params.Values['endDate'];
filterType := params.Values['filterType'];
offset := IntToStr((PageNum - 1) * PageSize);
limit := IntToStr(PageSize);
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 ' +
' FROM orders_status_schedule oss ';
......@@ -142,7 +166,7 @@ begin
end
else
begin
whereSQL := whereSQL + 'AND ' +
whereSQL := whereSQL + ' AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE ) ';
end;
end
......@@ -171,8 +195,8 @@ begin
begin
if startDate <> '' then
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''ART'' AND ' +
quotedStr(startDate) +' <= oss.STATUS_DATE';
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''ART'' AND oss.STATUS_DATE >= ' +
quotedStr(startDate);
end;
if endDate <> '' then
begin
......@@ -183,8 +207,7 @@ begin
end
else
begin
whereSQL := whereSQL + 'AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE ) ';
whereSQL := whereSQL + ' AND oss.STATUS_DATE <= ' + quotedStr(endDate);
end;
end
else
......@@ -323,7 +346,40 @@ begin
'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 ' +
'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);
......@@ -371,10 +427,7 @@ begin
end;
ordersDB.UniQuery1.Close;
SQL := 'SELECT COUNT(*) AS total_count '+
'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';
SQL := 'SELECT COUNT(*) AS total_count ' + whereSQL;
doQuery(ordersDB.UniQuery1, SQL);
Result.count := ordersDB.UniQuery1.FieldByName('total_count').AsInteger;
......
[Options]
LogFileNum=110
LogFileNum=129
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