Commit b2e1a1b8 by cam

Fixed SQL statements to work with new filters requested by Dave

parent 1e9dbe96
...@@ -247,11 +247,17 @@ begin ...@@ -247,11 +247,17 @@ begin
colorJSON.AddPair(header, value); colorJSON.AddPair(header, value);
end; end;
colorList.Add(colorJSON); colorList.Add(colorJSON);
end;
colorListJSON := TJSONObject.Create; colorListJSON := TJSONObject.Create;
colorListJSON.AddPair('items', colorList); colorListJSON.AddPair('items', colorList);
end;
XDataWebDataSet1.Edit; XDataWebDataSet1.Edit;
XDataWebDataSet1colors_colors.Value := colorListJSON.ToString; XDataWebDataSet1colors_colors.Value := colorListJSON.ToString;
XDataWebDataSet1staff_fields_proof_date.Value := DateTimeToStr(dtpProofDate.Date);
XDataWebDataSet1staff_fields_ship_date.Value := DateTimeToStr(dtpShipDate.Date);
XDataWebDataSet1staff_fields_art_due.Value := DateTimeToStr(dtpArtDue.Date);
XDataWebDataSet1staff_fields_mount_due.Value := DateTimeToStr(dtpMountDue.Date);
XDataWebDataSet1staff_fields_plate_due.Value := DateTimeToStr(dtpPlateDue.Date);
XDataWebDataSet1ORDER_DATE.Value := dtpOrderDate.Date;
XDataWebDataSet1.Post; XDataWebDataSet1.Post;
XDataWebDataSet1.First; XDataWebDataSet1.First;
while not XDataWebDataSet1.Eof do while not XDataWebDataSet1.Eof do
...@@ -398,21 +404,35 @@ begin ...@@ -398,21 +404,35 @@ begin
end; end;
end; end;
if not (XDataWebDataSet1staff_fields_order_date.AsString = '') then if not (XDataWebDataSet1staff_fields_order_date.AsString = '') then
dtpOrderDate.Date := StrToDateTime(XDataWebDataSet1staff_fields_order_date.Value); dtpOrderDate.Date := StrToDateTime(XDataWebDataSet1staff_fields_order_date.Value)
else
dtpOrderDate.Date := 0;
if not (XDataWebDataSet1staff_fields_proof_date.AsString = '') then if not (XDataWebDataSet1staff_fields_proof_date.AsString = '') then
dtpProofDate.Date := StrToDateTime(XDataWebDataSet1staff_fields_proof_date.AsString); dtpProofDate.Date := StrToDateTime(XDataWebDataSet1staff_fields_proof_date.AsString)
else
dtpProofDate.Date := 0;
if not (XDataWebDataSet1staff_fields_ship_date.AsString = '') then if not (XDataWebDataSet1staff_fields_ship_date.AsString = '') then
dtpShipDate.Date := StrToDateTime(XDataWebDataSet1staff_fields_ship_date.AsString); dtpShipDate.Date := StrToDateTime(XDataWebDataSet1staff_fields_ship_date.AsString)
else
dtpShipDate.Date := 0;
if not (XDataWebDataSet1staff_fields_art_due.AsString = '') then if not (XDataWebDataSet1staff_fields_art_due.AsString = '') then
dtpArtDue.Date := StrToDateTime(XDataWebDataSet1staff_fields_art_due.AsString); dtpArtDue.Date := StrToDateTime(XDataWebDataSet1staff_fields_art_due.AsString)
else
dtpArtDue.Date := 0;
if not (XDataWebDataSet1staff_fields_plate_due.AsString = '') then if not (XDataWebDataSet1staff_fields_plate_due.AsString = '') then
dtpPlateDue.Date := StrToDateTime(XDataWebDataSet1staff_fields_plate_due.AsString); dtpPlateDue.Date := StrToDateTime(XDataWebDataSet1staff_fields_plate_due.AsString)
else
dtpPlateDue.Date := 0;
if not (XDataWebDataSet1staff_fields_mount_due.AsString = '') then if not (XDataWebDataSet1staff_fields_mount_due.AsString = '') then
dtpMountDue.Date := StrToDateTime(XDataWebDataSet1staff_fields_mount_due.AsString); dtpMountDue.Date := StrToDateTime(XDataWebDataSet1staff_fields_mount_due.AsString)
else
dtpMountDue.Date := 0;
if not (XDataWebDataSet1proofing_approved_date.AsString = '') then if not (XDataWebDataSet1proofing_approved_date.AsString = '') then
dtpApprovedDate.Date := StrToDateTime(XDataWebDataSet1proofing_approved_date.AsString) dtpApprovedDate.Date := StrToDateTime(XDataWebDataSet1proofing_approved_date.AsString)
else else
dtpApprovedDate.Date := Now; dtpApprovedDate.Date := 0;
console.log(dtpApprovedDate.Date);
console.log(DateTimeToStr(dtpApprovedDate.Date));
end; end;
procedure TFOrderEntry.WebFormShow(Sender: TObject); procedure TFOrderEntry.WebFormShow(Sender: TObject);
......
...@@ -62,15 +62,20 @@ object FViewOrders: TFViewOrders ...@@ -62,15 +62,20 @@ object FViewOrders: TFViewOrders
ElementFont = efCSS ElementFont = efCSS
HeightStyle = ssAuto HeightStyle = ssAuto
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
Text = 'PROOF' Text = 'PROOF DONE'
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
ItemIndex = -1 ItemIndex = -1
Items.Strings = ( Items.Strings = (
'PROOF' 'PROOF DUE'
'ART' 'PROOF DONE'
'PLATE' 'ART DUE'
'MOUNT' 'ART DONE'
'SHIP') 'PLATE DUE'
'PLATE DONE'
'MOUNT DUE'
'MOUNT DONE'
'SHIP DUE'
'SHIP DONE')
end end
object btnApply: TWebButton object btnApply: TWebButton
Left = 542 Left = 542
......
...@@ -295,7 +295,6 @@ begin ...@@ -295,7 +295,6 @@ begin
colorObject := TJSObject(TJSJSON.parse(XDataWebDataSet1colors.Value)); colorObject := TJSObject(TJSJSON.parse(XDataWebDataSet1colors.Value));
colorList := TJSArray(colorObject['items']); colorList := TJSArray(colorObject['items']);
colors := colorList.flength; colors := colorList.flength;
console.log(colorList);
Cell.innerText := IntToStr(colors); Cell.innerText := IntToStr(colors);
end; end;
NewRow.appendChild(Cell); NewRow.appendChild(Cell);
...@@ -340,6 +339,8 @@ begin ...@@ -340,6 +339,8 @@ begin
begin begin
for I := 1 to 7 do for I := 1 to 7 do
begin begin
if I <= TotalPages then
begin
PageItem := TJSHTMLElement(document.createElement('li')); PageItem := TJSHTMLElement(document.createElement('li'));
PageItem.className := 'page-item'; PageItem.className := 'page-item';
if I = PageNumber then if I = PageNumber then
...@@ -359,6 +360,7 @@ begin ...@@ -359,6 +360,7 @@ begin
PageItem.appendChild(PageLink); PageItem.appendChild(PageLink);
PaginationElement.appendChild(PageItem); PaginationElement.appendChild(PageItem);
end; end;
end;
end end
else else
begin begin
......
...@@ -193,6 +193,7 @@ type ...@@ -193,6 +193,7 @@ type
function DelUser(username: string): string; function DelUser(username: string): string;
function EditUser(const editOptions: string): string; function EditUser(const editOptions: string): string;
function AddCorrugatedOrder(orderInfo: string): TJSONObject; function AddCorrugatedOrder(orderInfo: string): TJSONObject;
function AddStatusSchedule(StatusType: string; order: TJSONObject; ORDER_ID: integer): string;
end; end;
implementation implementation
......
...@@ -31,8 +31,9 @@ type ...@@ -31,8 +31,9 @@ type
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(filterType: string; currStatus: string): string; function generateSubQuery(filterType, statusType, currStatus: string): string;
function AddCorrugatedOrder(orderInfo: string): TJSONObject; function AddCorrugatedOrder(orderInfo: string): TJSONObject;
function AddStatusSchedule(StatusType: string; order: TJSONObject; ORDER_ID: integer): string;
procedure AfterConstruction; override; procedure AfterConstruction; override;
procedure BeforeDestruction; override; procedure BeforeDestruction; override;
end; end;
...@@ -99,16 +100,34 @@ begin ...@@ -99,16 +100,34 @@ begin
end; end;
function TLookupService.generateSubQuery(filterType: string; currStatus: string): string; function TLookupService.generateSubQuery(filterType, statusType, currStatus: string): string;
var
statusSuffix: string;
begin begin
result := ''; result := '';
if filterType <> currStatus then statusSuffix := '';
if filterType <> '' then
statusSuffix := filterType.Split(['_'])[1];
if statusType <> currStatus then
begin
if (statusSuffix = 'DUE') or (statusSuffix = '') then
begin begin
result := result + '(select oss.STATUS_DATE from orders_status_schedule oss ' + 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,'; 'where oss.ORDER_ID = o.ORDER_ID and oss.ORDER_STATUS = ' + quotedStr(currStatus) + ') AS '+ currStatus + '_DUE,';
end
else
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 = ' + 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, '; quotedStr(currStatus) + ' order by os.STATUS_TIMESTAMP desc LIMIT 1) AS ' + currStatus + '_DONE, ';
end
else
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;
function TLookupService.GetOrders(searchOptions: string): TOrderList; function TLookupService.GetOrders(searchOptions: string): TOrderList;
...@@ -122,12 +141,16 @@ var ...@@ -122,12 +141,16 @@ var
startDate: string; startDate: string;
endDate: string; endDate: string;
filterType: string; filterType: string;
statusType: string;
statusSuffix: string;
SQL: string; SQL: string;
Order: TOrderItem; Order: TOrderItem;
colors: string; colors: string;
ColorType: string; ColorType: string;
whereSQL: string; whereSQL: string;
fromSQL: string; fromSQL: string;
statusTableShort: string;
statusTableLong: string;
begin begin
params := TStringList.Create; params := TStringList.Create;
params.StrictDelimiter := true; params.StrictDelimiter := true;
...@@ -140,7 +163,26 @@ begin ...@@ -140,7 +163,26 @@ begin
OrderBy := params.Values['orderby']; OrderBy := params.Values['orderby'];
startDate := params.Values['startDate']; startDate := params.Values['startDate'];
endDate := params.Values['endDate']; endDate := params.Values['endDate'];
filterType := params.Values['filterType']; statusType := '';
filterType := '';
statusSuffix := '';
if params.Values['filterType'] <> '' then
begin
statusType := params.Values['filterType'].Split([' '])[0];
statusSuffix := params.Values['filterType'].Split([' '])[1];
filterType := params.Values['filterType'].Split([' '])[0] + '_' + params.Values['filterType'].Split([' '])[1];
end;
if statusSuffix = 'DUE' then
begin
statusTableShort := 'oss';
statusTableLong := 'orders_status_schedule';
end
else
begin
statusTableShort := 'os';
statusTableLong := 'orders_status';
end;
offset := IntToStr((PageNum - 1) * PageSize); offset := IntToStr((PageNum - 1) * PageSize);
limit := IntToStr(PageSize); limit := IntToStr(PageSize);
...@@ -148,28 +190,30 @@ begin ...@@ -148,28 +190,30 @@ begin
if filterType <> '' then if filterType <> '' then
begin begin
SQL := 'SELECT o.ORDER_ID, oss.STATUS_DATE AS '+ filterType.ToUpper + '_DUE'+ SQL := 'SELECT o.ORDER_ID, ' + statusTableShort + '.STATUS_DATE AS '+ filterType.ToUpper +
', o.LOCATION AS Loc, c.NAME AS COMPANY_NAME, o.JOB_NAME, o.ORDER_DATE, o.ORDER_TYPE, '; ', o.LOCATION AS Loc, c.NAME AS COMPANY_NAME, o.JOB_NAME, o.ORDER_DATE, o.ORDER_TYPE, ';
end end
else else
begin begin
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, '
end; end;
SQL := SQL + generateSubquery(filterType, 'PROOF'); SQL := SQL + generateSubquery(filterType, statusType, 'PROOF');
SQL := SQL + generateSubquery(filterType, 'ART'); SQL := SQL + generateSubquery(filterType, statusType, 'ART');
SQL := SQL + generateSubquery(filterType, 'PLATE'); SQL := SQL + generateSubquery(filterType, statusType, 'PLATE');
SQL := SQL + generateSubquery(filterType, 'MOUNT'); SQL := SQL + generateSubquery(filterType, statusType, 'MOUNT');
SQL := SQL + generateSubquery(filterType, 'SHIP'); SQL := SQL + generateSubquery(filterType, statusType, 'SHIP');
if filterType <> '' then if filterType <> '' then
begin begin
whereSQL := 'FROM orders o join orders_status_schedule oss on oss.ORDER_ID = o.ORDER_ID join ' + whereSQL := '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 ' + 'customers c on c.CUSTOMER_ID = o.COMPANY_ID left join ' +
'qb_sales_orders qb on qb.ORDER_ID = o.ORDER_ID ' + 'qb_sales_orders qb on qb.ORDER_ID = o.ORDER_ID ' +
'WHERE oss.ORDER_ID = o.ORDER_ID AND oss.ORDER_STATUS = '+ quotedStr(filterType) + 'WHERE ' + statusTableShort + '.ORDER_ID = o.ORDER_ID AND + ' +
' AND ' + quotedStr(startDate) + ' <= oss.STATUS_DATE AND ' + statusTableShort + '.ORDER_STATUS = '+ quotedStr(statusType) +
quotedStr(endDate) + ' >= oss.STATUS_DATE'; ' AND ' + quotedStr(startDate) + ' <= '+ statusTableShort + '.STATUS_DATE AND ' +
quotedStr(endDate) + ' >= ' + statusTableShort + '.STATUS_DATE';
SQL := SQL + 'o.PRICE, qb.QB_REF_NUM ' + whereSQL + ' ORDER BY ' + filterType + '_DUE DESC LIMIT ' + limit + ' OFFSET ' + offset; SQL := SQL + 'o.PRICE, qb.QB_REF_NUM ' + whereSQL + ' ORDER BY ' + filterType + ' DESC LIMIT ' + limit + ' OFFSET ' + offset;
end end
else else
begin begin
...@@ -274,7 +318,6 @@ begin ...@@ -274,7 +318,6 @@ begin
result.staff_fields_art_due := ordersDB.UniQuery1.FieldByName('staff_fields_art_due').AsString; result.staff_fields_art_due := ordersDB.UniQuery1.FieldByName('staff_fields_art_due').AsString;
result.staff_fields_plate_due := ordersDB.UniQuery1.FieldByName('staff_fields_plate_due').AsString; result.staff_fields_plate_due := ordersDB.UniQuery1.FieldByName('staff_fields_plate_due').AsString;
result.staff_fields_price := ordersDB.UniQuery1.FieldByName('staff_fields_price').AsString; result.staff_fields_price := ordersDB.UniQuery1.FieldByName('staff_fields_price').AsString;
if orderType = 'corrugated_plate_order' then
result.staff_fields_mount_due := ordersDB.UniQuery1.FieldByName('staff_fields_mount_due').AsString; result.staff_fields_mount_due := ordersDB.UniQuery1.FieldByName('staff_fields_mount_due').AsString;
result.staff_fields_art_location := ordersDB.UniQuery1.FieldByName('staff_fields_art_location').AsString; result.staff_fields_art_location := ordersDB.UniQuery1.FieldByName('staff_fields_art_location').AsString;
...@@ -606,6 +649,7 @@ var ...@@ -606,6 +649,7 @@ var
Field: TField; Field: TField;
DateFormat: TFormatSettings; DateFormat: TFormatSettings;
CurrDate: TDateTime; CurrDate: TDateTime;
ORDER_ID: integer;
begin begin
DateFormat := TFormatSettings.Create; DateFormat := TFormatSettings.Create;
DateFormat.ShortDateFormat := 'yyyy-mm-dd'; DateFormat.ShortDateFormat := 'yyyy-mm-dd';
...@@ -652,6 +696,22 @@ begin ...@@ -652,6 +696,22 @@ begin
ordersDB.UniQuery1.Post; ordersDB.UniQuery1.Post;
ordersDB.UniQuery1.Close;
ordersDB.UniQuery1.SQL.Text := 'SELECT LAST_INSERT_ID() AS OrderID'; // Use database's method to get the last inserted ID
ordersDB.UniQuery1.Open;
ORDER_ID := ordersDB.UniQuery1.FieldByName('OrderID').AsInteger;
if JSONData.GetValue<string>('staff_fields_proof_date') <> '' then
AddStatusSchedule('PROOF', JSONData, ORDER_ID);
if JSONData.GetValue<string>('staff_fields_ship_date') <> '' then
AddStatusSchedule('SHIP', JSONData, ORDER_ID);
if JSONData.GetValue<string>('staff_fields_art_due') <> '' then
AddStatusSchedule('ART', JSONData, ORDER_ID);
if JSONData.GetValue<string>('staff_fields_plate_due') <> '' then
AddStatusSchedule('PLATE', JSONData, ORDER_ID);
if JSONData.GetValue<string>('staff_fields_mount_due') <> '' then
AddStatusSchedule('MOUNT', JSONData, ORDER_ID);
Result := TJSONObject.Create.AddPair('status', 'success'); Result := TJSONObject.Create.AddPair('status', 'success');
TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result); TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);
except except
...@@ -665,6 +725,38 @@ begin ...@@ -665,6 +725,38 @@ begin
Result := TJSONObject.Create.AddPair('error', 'Order Already Exists'); Result := TJSONObject.Create.AddPair('error', 'Order Already Exists');
end; end;
function TLookupService.AddStatusSchedule(StatusType: string; order: TJSONObject; ORDER_ID: integer): string;
var
SQL: string;
temp: string;
begin
SQL := 'select * from orders_status_schedule where ORDER_ID = 0 and ORDER_ID <> 0';
doQuery(ordersDB.UniQuery1, SQL);
ordersDB.UniQuery1.Insert;
ordersDB.UniQuery1.FieldByName('ORDER_ID').AsInteger := ORDER_ID;
ordersDB.UniQuery1.FieldByName('ORDER_STATUS').AsString := StatusType;
if( (StatusType = 'PROOF') or (StatusType = 'SHIP') ) then
begin
//temp := order.GetValue<string>('staff_fields_'+ StatusType.ToLower +'_date');
ordersDB.UniQuery1.FieldByName('STATUS_DATE').AsString := order.GetValue<string>('staff_fields_'+ StatusType.ToLower +'_date');
ordersDB.UniQuery1.FieldByName('ORIGINAL_STATUS_DATE').AsString := order.GetValue<string>('staff_fields_'+ StatusType.ToLower +'_date');
end
else
begin
//temp := order.GetValue<string>('staff_fields_'+ StatusType.ToLower +'_due');
ordersDB.UniQuery1.FieldByName('STATUS_DATE').AsDateTime := StrToDateTime(order.GetValue<string>('staff_fields_'+ StatusType.ToLower +'_due'));
ordersDB.UniQuery1.FieldByName('ORIGINAL_STATUS_DATE').AsDateTime := StrToDateTime(order.GetValue<string>('staff_fields_'+ StatusType.ToLower +'_due'));
end;
ordersDB.UniQuery1.FieldByName('USER_ID').AsString := order.GetValue<string>('USER_ID');
ordersDB.UniQuery1.FieldByName('ORDER_REVISION').AsInteger := 1;
ordersDB.UniQuery1.Post;
Result := 'success';
end;
function TLookupService.AddUser(userInfo:string): string; function TLookupService.AddUser(userInfo:string): string;
var var
user: string; user: string;
......
[Options] [Options]
LogFileNum=168 LogFileNum=196
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