Commit 15d63c28 by cam

Starting point for filter finished in server

now starting on client end to test if the SQL works properly
parent 738e0705
......@@ -1200,7 +1200,7 @@ object FOrderEntry: TFOrderEntry
end
object WebDataSource1: TWebDataSource
DataSet = XDataWebDataSet1
Left = 246
Left = 216
Top = 104
end
end
......@@ -302,6 +302,20 @@ begin
console.log(color);
addColorRow(String(color['#']), string(color['Color']), string(color['LPI']), string(color['Size']));
end;
if not (XDataWebDataSet1orderDate.AsString = '') then
dtpOrderDate.Date := StrToDateTime(XDataWebDataSet1orderDate.Value);
if not (XDataWebDataSet1proofDate.AsString = '') then
dtpProofDate.Date := StrToDateTime(XDataWebDataSet1proofDate.Value);
if not (XDataWebDataSet1shipDate.AsString = '') then
dtpShipDate.Date := StrToDateTime(XDataWebDataSet1shipDate.Value);
if not (XDataWebDataSet1artDue.AsString = '') then
dtpArtDue.Date := StrToDateTime(XDataWebDataSet1artDue.Value);
if not (XDataWebDataSet1plateDue.AsString = '') then
dtpPlateDue.Date := StrToDateTime(XDataWebDataSet1plateDue.Value);
if not (XDataWebDataSet1mountDue.AsString = '') then
dtpMountDue.Date := StrToDateTime(XDataWebDataSet1mountDue.Value);
if not (XDataWebDataSet1approvedDate.AsString = '') then
dtpApprovedDate.Date := StrToDateTime(XDataWebDataSet1approvedDate.Value);
end;
procedure TFOrderEntry.WebFormShow(Sender: TObject);
......
......@@ -98,10 +98,14 @@ var
OrderBy: string;
offset: string;
limit: string;
startDate: string;
endDate: string;
filterType: string;
SQL: string;
Order: TOrderItem;
colors: string;
ColorType: string;
whereSQL: string;
begin
params := TStringList.Create;
params.StrictDelimiter := true;
......@@ -115,49 +119,211 @@ begin
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, ' +
'(SELECT oss.STATUS_DATE ' +
' FROM orders_status_schedule oss ' +
' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''PROOF'') AS PROOF_DUE, ' +
'(SELECT os.STATUS_TIMESTAMP ' +
' FROM orders_status os ' +
' WHERE os.ORDER_ID = o.ORDER_ID AND os.ORDER_STATUS = ''PROOF'' ' +
' ORDER BY os.STATUS_TIMESTAMP DESC LIMIT 1) AS PROOF_DONE, ' +
'(SELECT oss.STATUS_DATE ' +
' FROM orders_status_schedule oss ' +
' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''ART'') AS ART_DUE, ' +
'(SELECT os.STATUS_TIMESTAMP ' +
' FROM orders_status os ' +
' WHERE os.ORDER_ID = o.ORDER_ID AND os.ORDER_STATUS = ''ART'' ' +
' ORDER BY os.STATUS_TIMESTAMP DESC LIMIT 1) AS ART_DONE, ' +
'(SELECT oss.STATUS_DATE ' +
' FROM orders_status_schedule oss ' +
' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''PLATE'') AS PLATE_DUE, ' +
'(SELECT os.STATUS_TIMESTAMP ' +
' FROM orders_status os ' +
' WHERE os.ORDER_ID = o.ORDER_ID AND os.ORDER_STATUS = ''PLATE'' ' +
' ORDER BY os.STATUS_TIMESTAMP DESC LIMIT 1) AS PLATE_DONE, ' +
'(SELECT oss.STATUS_DATE ' +
' FROM orders_status_schedule oss ' +
' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''MOUNT'') AS MOUNT_DUE, ' +
'(SELECT os.STATUS_TIMESTAMP ' +
' FROM orders_status os ' +
' WHERE os.ORDER_ID = o.ORDER_ID AND os.ORDER_STATUS = ''MOUNT'' ' +
' ORDER BY os.STATUS_TIMESTAMP DESC LIMIT 1) AS MOUNT_DONE, ' +
'(SELECT oss.STATUS_DATE ' +
' FROM orders_status_schedule oss ' +
' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''SHIP'') AS SHIP_DUE, ' +
'(SELECT os.STATUS_TIMESTAMP ' +
' FROM orders_status os ' +
' WHERE os.ORDER_ID = o.ORDER_ID AND os.ORDER_STATUS = ''SHIP'' ' +
' ORDER BY os.STATUS_TIMESTAMP DESC LIMIT 1) AS SHIP_DONE, ' +
'o.PRICE, qb.QB_REF_NUM ' +
'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 ' +
'LIMIT ' + limit + ' OFFSET ' + offset;
'(SELECT oss.STATUS_DATE ' +
' FROM orders_status_schedule oss ';
// if proof is chosen as the filter
if filterType = 'proof' then
begin
if startDate <> '' then
begin
whereSQL := 'WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''PROOF'' AND ' +
quotedStr(startDate) +' <= oss.STATUS_DATE';
end;
if endDate <> '' then
begin
if whereSQL = 'WHERE ' then
begin
whereSQL := 'WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''PROOF'' AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE ) '
end
else
begin
whereSQL := whereSQL + 'AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE ) ';
end;
end
else
begin
whereSQL := 'WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''PROOF'') ';
end;
end
else
begin
whereSQL := 'WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''PROOF'') '
end;
SQL := SQL + whereSQL + 'AS PROOF_DUE, ' +
'(SELECT os.STATUS_TIMESTAMP ' +
' FROM orders_status os ' +
' WHERE os.ORDER_ID = o.ORDER_ID AND os.ORDER_STATUS = ''PROOF'' ' +
' ORDER BY os.STATUS_TIMESTAMP DESC LIMIT 1) AS PROOF_DONE, ' +
'(SELECT oss.STATUS_DATE ' +
' FROM orders_status_schedule oss ';
// if art is chosen as the filter
whereSQL := 'WHERE ';
if filterType = 'art' then
begin
if startDate <> '' then
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''ART'' AND ' +
quotedStr(startDate) +' <= oss.STATUS_DATE';
end;
if endDate <> '' then
begin
if whereSQL = 'WHERE ' then
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''ART'' AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE ) '
end
else
begin
whereSQL := whereSQL + 'AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE ) ';
end;
end
else
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''ART'') ';
end;
end
else
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''ART'') '
end;
SQL := SQL + whereSQL + 'AS ART_DUE, ' +
'(SELECT os.STATUS_TIMESTAMP ' +
' FROM orders_status os ' +
' WHERE os.ORDER_ID = o.ORDER_ID AND os.ORDER_STATUS = ''ART'' ' +
' ORDER BY os.STATUS_TIMESTAMP DESC LIMIT 1) AS ART_DONE, ' +
'(SELECT oss.STATUS_DATE ' +
' FROM orders_status_schedule oss ';
// if plate is chosen as the filter
whereSQL := 'WHERE ';
if filterType = 'plate' then
begin
if startDate <> '' then
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''PLATE'' AND ' +
quotedStr(startDate) +' <= oss.STATUS_DATE';
end;
if endDate <> '' then
begin
if whereSQL = 'WHERE ' then
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''PLATE'' AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE ) '
end
else
begin
whereSQL := whereSQL + 'AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE ) ';
end;
end
else
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''PLATE'') ';
end;
end
else
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''PLATE'') '
end;
SQL := SQL + whereSQL + 'AS PLATE_DUE, ' +
'(SELECT os.STATUS_TIMESTAMP ' +
' FROM orders_status os ' +
' WHERE os.ORDER_ID = o.ORDER_ID AND os.ORDER_STATUS = ''PLATE'' ' +
' ORDER BY os.STATUS_TIMESTAMP DESC LIMIT 1) AS PLATE_DONE, ' +
'(SELECT oss.STATUS_DATE ' +
' FROM orders_status_schedule oss ';
// if mount is selected as the filter
whereSQL := 'WHERE ';
if filterType = 'mount' then
begin
if startDate <> '' then
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''MOUNT'' AND ' +
quotedStr(startDate) +' <= oss.STATUS_DATE';
end;
if endDate <> '' then
begin
if whereSQL = 'WHERE ' then
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''MOUNT'' AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE ) '
end
else
begin
whereSQL := whereSQL + 'AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE ) ';
end;
end
else
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''MOUNT'') ';
end;
end
else
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''MOUNT'') '
end;
SQL := SQL + whereSQL + 'AS MOUNT_DUE, ' +
'(SELECT os.STATUS_TIMESTAMP ' +
' FROM orders_status os ' +
' WHERE os.ORDER_ID = o.ORDER_ID AND os.ORDER_STATUS = ''MOUNT'' ' +
' ORDER BY os.STATUS_TIMESTAMP DESC LIMIT 1) AS MOUNT_DONE, ' +
'(SELECT oss.STATUS_DATE ' +
' FROM orders_status_schedule oss ';
// if ship is chosen as the filter
whereSQL := 'WHERE ';
if filterType = 'mount' then
begin
if startDate <> '' then
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''SHIP'' AND ' +
quotedStr(startDate) +' <= oss.STATUS_DATE';
end;
if endDate <> '' then
begin
if whereSQL = 'WHERE ' then
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''SHIP'' AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE ) '
end
else
begin
whereSQL := whereSQL + 'AND ' +
quotedStr(endDate) + ' >= oss.STATUS_DATE ) ';
end;
end
else
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''SHIP'') ';
end;
end
else
begin
whereSQL := ' WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = ''SHIP'') '
end;
SQL := SQL + whereSQL + 'AS SHIP_DUE, ' +
'(SELECT os.STATUS_TIMESTAMP ' +
' FROM orders_status os ' +
' WHERE os.ORDER_ID = o.ORDER_ID AND os.ORDER_STATUS = ''SHIP'' ' +
' ORDER BY os.STATUS_TIMESTAMP DESC LIMIT 1) AS SHIP_DONE, ' +
'o.PRICE, qb.QB_REF_NUM ' +
'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 ' +
'LIMIT ' + limit + ' OFFSET ' + offset;
doQuery(ordersDB.UniQuery1, SQL);
......
[Options]
LogFileNum=109
LogFileNum=110
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