Commit 0a10d405 by Cam Hayes

Finished adding the memory leak fix and the column width fix. Updated the loggers as well

parent d7f1e3db
...@@ -5,8 +5,9 @@ interface ...@@ -5,8 +5,9 @@ interface
uses uses
System.SysUtils, System.Classes, Web, WEBLib.Graphics, WEBLib.Controls, WEBLib.Forms, WEBLib.Dialogs, System.SysUtils, System.Classes, Web, WEBLib.Graphics, WEBLib.Controls, WEBLib.Forms, WEBLib.Dialogs,
Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls, WEBLib.JSON, Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls, WEBLib.JSON,
JS, XData.Web.Connection, WEBLib.ExtCtrls, XData.Web.Client, WEBLib.ExtCtrls, Vcl.Imaging.pngimage,
App.Types, ConnectionModule, XData.Web.Client, Vcl.Imaging.pngimage; JS, XData.Web.Connection,
App.Types, ConnectionModule;
type type
TFViewLogin = class(TWebForm) TFViewLogin = class(TWebForm)
...@@ -55,7 +56,8 @@ procedure TFViewLogin.btnLoginClick(Sender: TObject); ...@@ -55,7 +56,8 @@ procedure TFViewLogin.btnLoginClick(Sender: TObject);
begin begin
ShowNotification('Login Error: ' + AMsg); ShowNotification('Login Error: ' + AMsg);
end; end;
var
hashPW: string;
begin begin
AuthService.Login( AuthService.Login(
edtUsername.Text, edtPassword.Text, edtUsername.Text, edtPassword.Text,
......
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content shadow-lg"> <div class="modal-content shadow-lg">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="main_notification_modal">Error</h5> <h5 class="modal-title" id="main_notification_modal">Info</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div> </div>
<div class="modal-body fs-6 fw-bold" id="main_notification_modal_body"> <div class="modal-body fs-6 fw-bold" id="main_notification_modal_body">
......
...@@ -156,40 +156,50 @@ object FViewOrders: TFViewOrders ...@@ -156,40 +156,50 @@ object FViewOrders: TFViewOrders
Title = 'Proof Due' Title = 'Proof Due'
end end
item item
ElementClassName = 'tbl-min-120'
DataField = 'proofDone' DataField = 'proofDone'
Title = 'Proof Done' Title = 'Proof Done'
TitleElementClassName = 'tbl-min-120'
end end
item item
DataField = 'artDue' DataField = 'artDue'
Title = 'Art Due' Title = 'Art Due'
end end
item item
ElementClassName = 'tbl-min-120'
DataField = 'artDone' DataField = 'artDone'
Title = 'Art Done' Title = 'Art Done'
TitleElementClassName = 'tbl-min-120'
end end
item item
DataField = 'plateDue' DataField = 'plateDue'
Title = 'Plate Due' Title = 'Plate Due'
end end
item item
ElementClassName = 'tbl-min-120'
DataField = 'plateDone' DataField = 'plateDone'
Title = 'Plate Done' Title = 'Plate Done'
TitleElementClassName = 'tbl-min-120'
end end
item item
DataField = 'mountDue' DataField = 'mountDue'
Title = 'Mount Due' Title = 'Mount Due'
end end
item item
ElementClassName = 'tbl-min-120'
DataField = 'mountDone' DataField = 'mountDone'
Title = 'Mount Done' Title = 'Mount Done'
TitleElementClassName = 'tbl-min-120'
end end
item item
DataField = 'shipDue' DataField = 'shipDue'
Title = 'Ship Due' Title = 'Ship Due'
end end
item item
ElementClassName = 'tbl-min-120'
DataField = 'shipDone' DataField = 'shipDone'
Title = 'Ship Done' Title = 'Ship Done'
TitleElementClassName = 'tbl-min-120'
end end
item item
DataField = 'price' DataField = 'price'
...@@ -360,6 +370,7 @@ object FViewOrders: TFViewOrders ...@@ -360,6 +370,7 @@ object FViewOrders: TFViewOrders
FieldName = 'proofDue' FieldName = 'proofDue'
end end
object xdwdsOrdersproofDone: TStringField object xdwdsOrdersproofDone: TStringField
DisplayWidth = 40
FieldName = 'proofDone' FieldName = 'proofDone'
end end
object xdwdsOrdersartDue: TStringField object xdwdsOrdersartDue: TStringField
......
...@@ -165,7 +165,7 @@ begin ...@@ -165,7 +165,7 @@ begin
ShowToast(FMessage); ShowToast(FMessage);
edtUsername.Text := Username; edtUsername.Text := Username;
edtFullName.Text := FullName; edtFullName.Text := FullName;
if Mode = 'Edit' then if Mode = 'EDIT' then
begin begin
edtPassword.Text := 'hidden'; edtPassword.Text := 'hidden';
end; end;
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
background-color: #fff; background-color: #fff;
} }
.tbl-min-120 {
min-width: 120px;
}
input[type="text"] { input[type="text"] {
min-width: 50px; min-width: 50px;
max-width: 100%; max-width: 100%;
......
...@@ -181,7 +181,7 @@ begin ...@@ -181,7 +181,7 @@ begin
begin begin
name := authDB.uq.FieldByName('NAME').AsString; name := authDB.uq.FieldByName('NAME').AsString;
checkString := THashSHA2.GetHashString(name + password, THashSHA2.TSHA2Version.SHA512).ToUpper; checkString := THashSHA2.GetHashString(name + password, THashSHA2.TSHA2Version.SHA512).ToUpper;
if authDB.uq.FieldByName('PASSWORD').AsString = checkString then if authDB.uq.FieldByName('PASSWORD').AsString = checkstring then
begin begin
Logger.Log(1, Format('AuthDB.SetLoginAuditEntry: "%s"', [user]) ); Logger.Log(1, Format('AuthDB.SetLoginAuditEntry: "%s"', [user]) );
Result := 3; // Succcess Result := 3; // Succcess
......
...@@ -158,6 +158,7 @@ begin ...@@ -158,6 +158,7 @@ begin
USER_ID := JSONData.GetValue<string>('USER_ID'); USER_ID := JSONData.GetValue<string>('USER_ID');
SQL := 'select * from orders where ORDER_ID = ' + ORDER_ID; SQL := 'select * from orders where ORDER_ID = ' + ORDER_ID;
logger.Log(5, 'Retrieving order type with SQL: ' + SQL);
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
if ordersDB.UniQuery1.FieldByName('ORDER_TYPE').AsString = 'corrugated_plate' then if ordersDB.UniQuery1.FieldByName('ORDER_TYPE').AsString = 'corrugated_plate' then
begin begin
...@@ -171,6 +172,7 @@ begin ...@@ -171,6 +172,7 @@ begin
table := 'cutting_die_orders'; table := 'cutting_die_orders';
SQL := 'select * from ' + table + ' cpo join customers c on cpo.COMPANY_ID = c.CUSTOMER_ID join customers_ship cs on cpo.staff_fields_ship_to = cs.ship_block JOIN qb_items ON cpo.staff_fields_quickbooks_item = qb_items.qb_item_name where cpo.ORDER_ID = ' + ORDER_ID; SQL := 'select * from ' + table + ' cpo join customers c on cpo.COMPANY_ID = c.CUSTOMER_ID join customers_ship cs on cpo.staff_fields_ship_to = cs.ship_block JOIN qb_items ON cpo.staff_fields_quickbooks_item = qb_items.qb_item_name where cpo.ORDER_ID = ' + ORDER_ID;
logger.Log(5, 'Retrieveing Customer Info with SQL: ' + SQL);
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
estimateJSON.AddPair('TxnDate', ordersDB.UniQuery1.FieldByName('staff_fields_order_date').AsString); estimateJSON.AddPair('TxnDate', ordersDB.UniQuery1.FieldByName('staff_fields_order_date').AsString);
...@@ -251,7 +253,7 @@ begin ...@@ -251,7 +253,7 @@ begin
estimateJSON.AddPair('ShipDate', ordersDB.UniQuery1.FieldByName('staff_fields_ship_date').AsString) estimateJSON.AddPair('ShipDate', ordersDB.UniQuery1.FieldByName('staff_fields_ship_date').AsString)
end; end;
logger.Log(5, 'estimateJSON finished construction');
restClient.BaseURL := 'https://sandbox-quickbooks.api.intuit.com'; restClient.BaseURL := 'https://sandbox-quickbooks.api.intuit.com';
...@@ -284,6 +286,7 @@ begin ...@@ -284,6 +286,7 @@ begin
restRequest.AddBody(estimateJSON.ToJSON, TRESTContentType.ctAPPLICATION_JSON); restRequest.AddBody(estimateJSON.ToJSON, TRESTContentType.ctAPPLICATION_JSON);
logger.Log(5, 'Executing rest request with JSON: ' + estimateJSON.ToJSON);
restRequest.Execute; restRequest.Execute;
jsValue := restResponse.JSONValue; jsValue := restResponse.JSONValue;
...@@ -291,6 +294,7 @@ begin ...@@ -291,6 +294,7 @@ begin
jsObj := TJSONObject(jsValue).GetValue<TJSONObject>('Estimate'); jsObj := TJSONObject(jsValue).GetValue<TJSONObject>('Estimate');
sql := 'select * from orders where ORDER_ID = ' + ORDER_ID; sql := 'select * from orders where ORDER_ID = ' + ORDER_ID;
logger.Log(5, 'Updating orders QB info');
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
ordersDB.UniQuery1.Edit; ordersDB.UniQuery1.Edit;
...@@ -303,10 +307,11 @@ begin ...@@ -303,10 +307,11 @@ begin
result := TJSONObject.Create; result := TJSONObject.Create;
Result.AddPair('status','Success:Estimate Successfully Added'); Result.AddPair('status','Success:Estimate Successfully Added');
logger.log(3, 'AddEstimate Finished');
except except
on E: Exception do on E: Exception do
begin begin
logger.Log(2, 'Error when adding Estimate ' + e.Message); logger.Log(1, 'Error when adding Estimate ' + e.Message);
jsValue := restResponse.JSONValue; jsValue := restResponse.JSONValue;
if not (jsValue is TJSONObject) then if not (jsValue is TJSONObject) then
...@@ -329,7 +334,7 @@ begin ...@@ -329,7 +334,7 @@ begin
on E: Exception do on E: Exception do
msg := 'Unable to parse QuickBooks error: ' + E.Message; msg := 'Unable to parse QuickBooks error: ' + E.Message;
end; end;
logger.Log(2, 'QuickBooks Error Message: ' + msg); logger.Log(1, 'QuickBooks Error Message: ' + msg);
raise EXDataHttpException.Create(500, 'Unable to add QuickBooks Estimate: A QuickBooks interface error has occurred!'); raise EXDataHttpException.Create(500, 'Unable to add QuickBooks Estimate: A QuickBooks interface error has occurred!');
end; end;
end; end;
...@@ -370,10 +375,13 @@ var ...@@ -370,10 +375,13 @@ var
begin begin
logger.Log(3, 'TLookupService.DelShippingAddress'); logger.Log(3, 'TLookupService.DelShippingAddress');
SQL := 'DELETE FROM customers_ship WHERE customer_ship_id = ' + AddressID; SQL := 'DELETE FROM customers_ship WHERE customer_ship_id = ' + AddressID;
logger.Log(5, 'Deleting shipping address with SQL: ' + SQL);
OrdersDB.UniQuery1.SQL.Text := SQL; OrdersDB.UniQuery1.SQL.Text := SQL;
OrdersDB.UniQuery1.ExecSQL; OrdersDB.UniQuery1.ExecSQL;
result := TJSONObject.Create; result := TJSONObject.Create;
result.AddPair('status', 'Success: Address Successfully Deleted'); result.AddPair('status', 'Success: Address Successfully Deleted');
logger.Log(5, 'Address deleted retrieving updated address list...');
SQL := 'select * FROM customers c LEFT JOIN customers_ship s ON c.CUSTOMER_ID = s.customer_id WHERE c.CUSTOMER_ID = ' + CustomerID; SQL := 'select * FROM customers c LEFT JOIN customers_ship s ON c.CUSTOMER_ID = s.customer_id WHERE c.CUSTOMER_ID = ' + CustomerID;
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
ADDRESS_LIST := TJSONArray.Create; ADDRESS_LIST := TJSONArray.Create;
...@@ -393,6 +401,7 @@ begin ...@@ -393,6 +401,7 @@ begin
Result.AddPair('ADDRESS', ADDRESS_LIST); Result.AddPair('ADDRESS', ADDRESS_LIST);
TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result); TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);
logger.Log(3, 'DelShippingAddress Finished');
end; end;
...@@ -430,6 +439,7 @@ begin ...@@ -430,6 +439,7 @@ begin
try try
SQL := 'select * from customers' + limitSQL; SQL := 'select * from customers' + limitSQL;
logger.Log(5, 'retrieving customers with SQL: ' + SQL);
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
result := TCustomerList.Create; result := TCustomerList.Create;
...@@ -459,6 +469,7 @@ begin ...@@ -459,6 +469,7 @@ begin
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
Result.count := ordersDB.UniQuery1.FieldByName('total_count').AsInteger; Result.count := ordersDB.UniQuery1.FieldByName('total_count').AsInteger;
ordersDB.UniQuery1.Close; ordersDB.UniQuery1.Close;
logger.Log(3, 'GetCustomers finished');
except except
on E: Exception do on E: Exception do
begin begin
...@@ -485,6 +496,7 @@ begin ...@@ -485,6 +496,7 @@ begin
SQL := 'select * FROM customers c LEFT JOIN customers_ship s ON c.CUSTOMER_ID = s.customer_id WHERE c.CUSTOMER_ID = -1' SQL := 'select * FROM customers c LEFT JOIN customers_ship s ON c.CUSTOMER_ID = s.customer_id WHERE c.CUSTOMER_ID = -1'
else else
SQL := 'select * FROM customers c LEFT JOIN customers_ship s ON c.CUSTOMER_ID = s.customer_id WHERE c.CUSTOMER_ID = ' + ID; SQL := 'select * FROM customers c LEFT JOIN customers_ship s ON c.CUSTOMER_ID = s.customer_id WHERE c.CUSTOMER_ID = ' + ID;
logger.Log(5, 'Getting customer with SQL: ' + SQL);
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
result := TCustomerItem.Create; result := TCustomerItem.Create;
...@@ -523,6 +535,7 @@ begin ...@@ -523,6 +535,7 @@ begin
ordersDB.UniQuery1.Next; ordersDB.UniQuery1.Next;
end; end;
logger.Log(3, 'GetCustomer Finished');
except except
on E: Exception do on E: Exception do
begin begin
...@@ -552,6 +565,7 @@ begin ...@@ -552,6 +565,7 @@ begin
result.Add(USER); result.Add(USER);
ordersDB.uqUsers.Next; ordersDB.uqUsers.Next;
end; end;
logger.Log(3, 'GetRepUsers finished');
end; end;
...@@ -638,6 +652,7 @@ begin ...@@ -638,6 +652,7 @@ begin
ShipID := JSONData.GetValue<integer>('customer_ship_id'); ShipID := JSONData.GetValue<integer>('customer_ship_id');
SQL := 'select * from customers_ship where customer_ship_id = ' + IntToStr(ShipID); SQL := 'select * from customers_ship where customer_ship_id = ' + IntToStr(ShipID);
end; end;
logger.Log(5, 'Retrieving Address with SQL ' + SQL);
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
try try
...@@ -670,10 +685,11 @@ begin ...@@ -670,10 +685,11 @@ begin
end end
else else
msg := 'Success: Shipping Address Successfully Edited'; msg := 'Success: Shipping Address Successfully Edited';
logger.Log(3, msg);
// Sends the updated Address List Back. // Sends the updated Address List Back.
SQL := 'select * FROM customers c LEFT JOIN customers_ship s ON c.CUSTOMER_ID = s.customer_id WHERE c.CUSTOMER_ID = ' + CustomerID; SQL := 'select * FROM customers c LEFT JOIN customers_ship s ON c.CUSTOMER_ID = s.customer_id WHERE c.CUSTOMER_ID = ' + CustomerID;
logger.Log(5, 'Retrieving updated customer address list with SQL: ' + SQL);
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
ADDRESS_LIST := TJSONArray.Create; ADDRESS_LIST := TJSONArray.Create;
while not ordersDB.UniQuery1.Eof do while not ordersDB.UniQuery1.Eof do
...@@ -693,6 +709,7 @@ begin ...@@ -693,6 +709,7 @@ begin
Result.AddPair('status', msg); Result.AddPair('status', msg);
Result.AddPair('ADDRESS', ADDRESS_LIST); Result.AddPair('ADDRESS', ADDRESS_LIST);
TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result); TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);
logger.Log(3, 'AddShippingAddress finished');
except except
on E: Exception do on E: Exception do
begin begin
...@@ -739,6 +756,7 @@ begin ...@@ -739,6 +756,7 @@ begin
CustomerID := JSONData.GetValue<integer>('CUSTOMER_ID'); CustomerID := JSONData.GetValue<integer>('CUSTOMER_ID');
SQL := 'select CUSTOMER_ID from customers where SHORT_NAME = ' + quotedStr(JSONData.GetValue<string>('SHORT_NAME')); SQL := 'select CUSTOMER_ID from customers where SHORT_NAME = ' + quotedStr(JSONData.GetValue<string>('SHORT_NAME'));
logger.Log(5, 'Retrieving customer with SQL: ' + SQL);
doQuery(OrdersDB.UniQuery1, SQL); doQuery(OrdersDB.UniQuery1, SQL);
if mode = 'ADD' then if mode = 'ADD' then
...@@ -800,6 +818,7 @@ begin ...@@ -800,6 +818,7 @@ begin
else else
msg := 'Success: Customer Successfully Edited'; msg := 'Success: Customer Successfully Edited';
logger.Log(3, msg);
Result := TJSONObject.Create.AddPair('status', msg); Result := TJSONObject.Create.AddPair('status', msg);
Result.AddPair('CustomerID', CustomerID); Result.AddPair('CustomerID', CustomerID);
...@@ -812,7 +831,10 @@ begin ...@@ -812,7 +831,10 @@ begin
end; end;
end end
else else
begin
Result := TJSONObject.Create.AddPair('status', 'Failure: Company Account Name Must Be Unique'); Result := TJSONObject.Create.AddPair('status', 'Failure: Company Account Name Must Be Unique');
logger.Log(3, 'Failure: Company Account Name Must Be Unique');
end;
end; end;
function TLookupService.GenerateOrderCorrugatedPDF(orderID: string): string; function TLookupService.GenerateOrderCorrugatedPDF(orderID: string): string;
...@@ -831,7 +853,7 @@ begin ...@@ -831,7 +853,7 @@ begin
Result := rptOrderCorrugated.PrepareReport(SQL); Result := rptOrderCorrugated.PrepareReport(SQL);
// Optionally log success // Optionally log success
Logger.Log(5, 'PDF Report successfully generated for order ID: ' + orderID); Logger.Log(3, 'PDF Report successfully generated for order ID: ' + orderID);
except except
on E: Exception do on E: Exception do
begin begin
...@@ -861,11 +883,11 @@ begin ...@@ -861,11 +883,11 @@ begin
Result := rptOrderWeb.PrepareReport(SQL); Result := rptOrderWeb.PrepareReport(SQL);
// Optionally log success // Optionally log success
Logger.Log(5, 'PDF Report successfully generated for order ID: ' + orderID); Logger.Log(3, 'PDF Report successfully generated for order ID: ' + orderID);
except except
on E: Exception do on E: Exception do
begin begin
Logger.Log(2, 'Error generating web PDF: ' + E.Message); Logger.Log(1, 'Error generating web PDF: ' + E.Message);
raise EXDataHttpException.Create(500, 'Error generating web PDF: A KG Orders database issue has occurred!'); raise EXDataHttpException.Create(500, 'Error generating web PDF: A KG Orders database issue has occurred!');
end; end;
end; end;
...@@ -890,11 +912,11 @@ begin ...@@ -890,11 +912,11 @@ begin
Result := rptOrderCutting.PrepareReport(SQL); Result := rptOrderCutting.PrepareReport(SQL);
// Optionally log success // Optionally log success
Logger.Log(5, 'PDF Report successfully generated for order ID: ' + orderID); Logger.Log(3, 'PDF Report successfully generated for order ID: ' + orderID);
except except
on E: Exception do on E: Exception do
begin begin
Logger.Log(2, 'Error generating cutting die PDF: ' + E.Message); Logger.Log(1, 'Error generating cutting die PDF: ' + E.Message);
raise EXDataHttpException.Create(500, 'Error generating cutting die PDF: A KG Orders database issue has occurred!'); raise EXDataHttpException.Create(500, 'Error generating cutting die PDF: A KG Orders database issue has occurred!');
end; end;
end; end;
...@@ -944,45 +966,61 @@ begin ...@@ -944,45 +966,61 @@ begin
end; end;
function TLookupService.createStatusSearchInfo(params: TStringList; statusNum: string): TStatusSearchInfo; function TLookupService.createStatusSearchInfo(params: TStringList; statusNum: string): TStatusSearchInfo;
// Takes all the status info recieved from the client and puts it into an object // Takes all the status info received from the client and puts it into an object
// for convinence and to make it easier to expand. Returns said object. // for convenience and to make it easier to expand. Returns said object.
// params: string list recieved from the client with all the search params var
// statusNum: which status number we are on to make it easier to tell what info info: TStatusSearchInfo;
// we want to take from client. I.E. differentiate between startDate1 and filterValue: string;
// startDate2 parts: TArray<string>;
begin begin
result := TStatusSearchInfo.Create; info := TStatusSearchInfo.Create;
result.startDate := params.Values['startDate' + statusNum]; logger.log(3, 'TLookupService.createStatusSearchInfo');
result.endDate := params.Values['endDate' + statusNum]; try
info.startDate := params.Values['startDate' + statusNum];
info.endDate := params.Values['endDate' + statusNum];
if params.Values['null' + statusNum] <> '' then if params.Values['null' + statusNum] <> '' then
result.null := StrToBool(params.Values['null' + statusNum]); info.null := StrToBool(params.Values['null' + statusNum]);
info.statusType := '';
info.filterType := '';
info.statusSuffix := '';
result.statusType := ''; filterValue := params.Values['filterType' + statusNum];
result.filterType := ''; if (filterValue <> '') and (filterValue <> 'NONE') then
result.statusSuffix := '';
if ( ( params.Values['filterType' + statusNum] <> '' ) and ( params.Values['filterType' + statusNum] <> 'NONE' ) ) then
begin begin
result.statusType := params.Values['filterType' + statusNum].Split([' '])[0]; parts := filterValue.Split([' ']);
result.statusSuffix := params.Values['filterType' + statusNum].Split([' '])[1]; if Length(parts) > 0 then
result.filterType := result.statusType + '_' + result.statusSuffix; info.statusType := parts[0];
if Length(parts) > 1 then
info.statusSuffix := parts[1];
if (info.statusType <> '') and (info.statusSuffix <> '') then
info.filterType := info.statusType + '_' + info.statusSuffix;
end; end;
// Figure out what table the status belongs to // Figure out what table the status belongs to
if result.statusSuffix = 'DUE' then if info.statusSuffix = 'DUE' then
begin begin
result.statusTableShort := 'oss'; info.statusTableShort := 'oss';
result.statusTableLong := 'orders_status_schedule'; info.statusTableLong := 'orders_status_schedule';
result.altStatusTableShort := 'os'; info.altStatusTableShort := 'os';
result.altStatusTableLong := 'orders_status'; info.altStatusTableLong := 'orders_status';
end end
else else
begin begin
result.statusTableShort := 'os'; info.statusTableShort := 'os';
result.statusTableLong := 'orders_status'; info.statusTableLong := 'orders_status';
result.altStatusTableShort := 'oss'; info.altStatusTableShort := 'oss';
result.altStatusTableLong := 'orders_status_schedule'; info.altStatusTableLong := 'orders_status_schedule';
end; end;
Result := info; // hand ownership to the caller
logger.Log(3, 'StatusSearchInfo generated successfully');
except
info.Free; // avoid leak if anything above raises
raise;
end;
end; end;
function TLookupService.generateStatusWhereSQL(status: TStatusSearchInfo): string; function TLookupService.generateStatusWhereSQL(status: TStatusSearchInfo): string;
...@@ -1030,19 +1068,23 @@ function TLookupService.generateOrdersSQL(searchOptions: string): TSQLQuery; ...@@ -1030,19 +1068,23 @@ function TLookupService.generateOrdersSQL(searchOptions: string): TSQLQuery;
// searchOptions: search information sent form client to be parsed. // searchOptions: search information sent form client to be parsed.
var var
params: TStringList; params: TStringList;
PageNum, PageSize: integer; PageNum, PageSize: Integer;
OrderBy, offset, limit: string; OrderBy, offset, limit: string;
SQL, whereSQL, orderBySQL: string; SQL, whereSQL: string;
OrderID, CompanyID, JobName, orderType: string; OrderID, CompanyID, JobName, orderType: string;
status1, status2: TStatusSearchInfo; status1, status2: TStatusSearchInfo;
ForPDF: Boolean; ForPDF: Boolean;
accessRights, userID: string; accessRights, userID: string;
q: TSQLQuery;
begin begin
result := TSQLQuery.Create; q := TSQLQuery.Create;
params := TStringList.Create; params := TStringList.Create;
status1 := nil;
status2 := nil;
logger.log(3, 'TLookupService.generatingOrdersSQL');
try try
params.StrictDelimiter := true; try
params.StrictDelimiter := True;
params.Delimiter := '&'; params.Delimiter := '&';
params.DelimitedText := searchOptions; params.DelimitedText := searchOptions;
...@@ -1057,17 +1099,18 @@ begin ...@@ -1057,17 +1099,18 @@ begin
end; end;
OrderBy := params.Values['orderby'] + ' ' + params.Values['direction']; OrderBy := params.Values['orderby'] + ' ' + params.Values['direction'];
orderType := params.Values['orderType'].ToLower(); orderType := params.Values['orderType'].ToLower;
OrderID := params.Values['orderID']; OrderID := params.Values['orderID'];
companyID := params.Values['companyID']; CompanyID := params.Values['companyID'];
jobName := params.Values['jobName']; JobName := params.Values['jobName'];
accessRights := params.Values['accessRights']; accessRights := params.Values['accessRights'];
userID := params.Values['userID']; userID := params.Values['userID'];
status1 := createStatusSearchInfo(params, '1'); status1 := createStatusSearchInfo(params, '1');
status2 := createStatusSearchInfo(params, '2'); status2 := createStatusSearchInfo(params, '2');
SQL := 'SELECT o.ORDER_ID, c.SHORT_NAME, o.LOCATION AS Loc, c.NAME AS COMPANY_NAME, o.JOB_NAME, o.ORDER_TYPE, o.IN_QB, o.QB_ORDER_NUM,' + SQL := 'SELECT o.ORDER_ID, c.SHORT_NAME, o.LOCATION AS Loc, c.NAME AS COMPANY_NAME, ' +
'o.JOB_NAME, o.ORDER_TYPE, o.IN_QB, o.QB_ORDER_NUM,' +
generateSubquery('PROOF') + generateSubquery('PROOF') +
generateSubquery('ART') + generateSubquery('ART') +
generateSubquery('PLATE') + generateSubquery('PLATE') +
...@@ -1084,27 +1127,24 @@ begin ...@@ -1084,27 +1127,24 @@ begin
whereSQL := whereSQL + generateStatusWhereSQL(status1); whereSQL := whereSQL + generateStatusWhereSQL(status1);
if (status2.filterType <> '') and (status2.filterType <> 'NONE') then if (status2.filterType <> '') and (status2.filterType <> 'NONE') then
whereSQL := whereSQL + generateStatusWhereSQL(status2); whereSQL := whereSQL + generateStatusWhereSQL(status2);
if (orderType <> '') and (orderType <> 'any') then if (orderType <> '') and (orderType <> 'any') then
begin begin
if (orderType <> 'cutting die') then if orderType <> 'cutting die' then
whereSQL := whereSQL + ' AND o.ORDER_TYPE = ' + QuotedStr(orderType + '_plate') whereSQL := whereSQL + ' AND o.ORDER_TYPE = ' + QuotedStr(orderType + '_plate')
else else
whereSQL := whereSQL + ' AND o.ORDER_TYPE = ' + QuotedStr('cutting_die'); whereSQL := whereSQL + ' AND o.ORDER_TYPE = ' + QuotedStr('cutting_die');
end; end;
if OrderID <> '' then if OrderID <> '' then
whereSQL := whereSQL + ' AND o.ORDER_ID = ' + OrderID; whereSQL := whereSQL + ' AND o.ORDER_ID = ' + OrderID;
if companyID <> '' then if CompanyID <> '' then
whereSQL := whereSQL + ' AND c.CUSTOMER_ID = ' + companyID; whereSQL := whereSQL + ' AND c.CUSTOMER_ID = ' + CompanyID;
if jobName <> '' then if JobName <> '' then
whereSQL := whereSQL + ' AND o.JOB_NAME LIKE ' + QuotedStr('%' + jobName + '%'); whereSQL := whereSQL + ' AND o.JOB_NAME LIKE ' + QuotedStr('%' + JobName + '%');
if accessRights = 'SALES' then if accessRights = 'SALES' then
begin
whereSQL := whereSQL + ' AND c.REP_USER_ID = ' + userID; whereSQL := whereSQL + ' AND c.REP_USER_ID = ' + userID;
end;
orderBySQL := ' ORDER BY ' + OrderBy;
SQL := SQL + ' o.PRICE, qb.QB_REF_NUM, ' + SQL := SQL + ' o.PRICE, qb.QB_REF_NUM, ' +
'COALESCE(cpo.staff_fields_po_number, wpo.staff_fields_po_number, cdo.staff_fields_po_number) AS po_number, ' + 'COALESCE(cpo.staff_fields_po_number, wpo.staff_fields_po_number, cdo.staff_fields_po_number) AS po_number, ' +
...@@ -1112,13 +1152,22 @@ begin ...@@ -1112,13 +1152,22 @@ begin
'COALESCE(cpo.staff_fields_order_date, wpo.staff_fields_order_date, cdo.staff_fields_order_date) AS ORDER_DATE '; 'COALESCE(cpo.staff_fields_order_date, wpo.staff_fields_order_date, cdo.staff_fields_order_date) AS ORDER_DATE ';
if not ForPDF then if not ForPDF then
SQL := SQL + whereSQL + orderBySQL + ' LIMIT ' + limit + ' OFFSET ' + offset SQL := SQL + whereSQL + ' ORDER BY ' + OrderBy + ' LIMIT ' + limit + ' OFFSET ' + offset
else else
SQL := SQL + whereSQL + orderBySQL; SQL := SQL + whereSQL + ' ORDER BY ' + OrderBy;
q.SQL := SQL;
q.whereSQL := whereSQL;
result.SQL := SQL; Result := q; // hand ownership of q to the caller
result.whereSQL := whereSQL; logger.Log(4, 'Successfully generated orders SQL');
except
q.Free; // only if we never handed it to the caller
raise;
end;
finally finally
status1.Free;
status2.Free;
params.Free; params.Free;
end; end;
end; end;
...@@ -1232,11 +1281,11 @@ begin ...@@ -1232,11 +1281,11 @@ begin
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
Result.count := ordersDB.UniQuery1.FieldByName('total_count').AsInteger; Result.count := ordersDB.UniQuery1.FieldByName('total_count').AsInteger;
ordersDB.UniQuery1.Close; ordersDB.UniQuery1.Close;
logger.Log(4, 'Orders successfully retrieved');
except except
on E: Exception do on E: Exception do
begin begin
Logger.Log(2, 'Error in GetOrders: ' + E.Message); Logger.Log(1, 'Error in GetOrders: ' + E.Message);
raise EXDataHttpException.Create(500, 'Unable to retrieve order list: A KG Orders database issue has occurred!'); raise EXDataHttpException.Create(500, 'Unable to retrieve order list: A KG Orders database issue has occurred!');
end; end;
end; end;
...@@ -1343,6 +1392,7 @@ begin ...@@ -1343,6 +1392,7 @@ begin
result.general_special_instructions := ordersDB.UniQuery1.FieldByName('general_special_instructions').AsString; result.general_special_instructions := ordersDB.UniQuery1.FieldByName('general_special_instructions').AsString;
ordersDB.UniQuery1.Close; ordersDB.UniQuery1.Close;
logger.Log(4, 'Corrugated order successfully retrieved');
except except
on E: Exception do on E: Exception do
begin begin
...@@ -1469,6 +1519,7 @@ begin ...@@ -1469,6 +1519,7 @@ begin
result.general_comments := ordersDB.UniQuery1.FieldByName('general_comments').AsString; result.general_comments := ordersDB.UniQuery1.FieldByName('general_comments').AsString;
ordersDB.UniQuery1.Close; ordersDB.UniQuery1.Close;
logger.Log(4, 'Web plate order successfully retrieved');
except except
on E: Exception do on E: Exception do
begin begin
...@@ -1517,10 +1568,12 @@ begin ...@@ -1517,10 +1568,12 @@ begin
ordersDB.UniQuery1.Close; ordersDB.UniQuery1.Close;
logger.Log(4, 'Cutting Die order successfully retrieved');
except except
on E: Exception do on E: Exception do
begin begin
logger.Log(2, 'An Error has occurred in TLookupSerivceImpl.GetCuttingDieOrder: ' + E.Message); logger.Log(1, 'An Error has occurred in TLookupSerivceImpl.GetCuttingDieOrder: ' + E.Message);
raise EXDataHttpException.Create(500, 'Could not retrieve cutting die order: A KG Orders database issue has occurred!'); raise EXDataHttpException.Create(500, 'Could not retrieve cutting die order: A KG Orders database issue has occurred!');
end; end;
end; end;
...@@ -1588,6 +1641,8 @@ begin ...@@ -1588,6 +1641,8 @@ begin
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
Result.count := ordersDB.UniQuery1.FieldByName('total_count').AsInteger; Result.count := ordersDB.UniQuery1.FieldByName('total_count').AsInteger;
ordersDB.UniQuery1.Close; ordersDB.UniQuery1.Close;
logger.Log(4, 'Items list successfully retrieved');
except except
on E: Exception do on E: Exception do
begin begin
...@@ -1658,6 +1713,7 @@ begin ...@@ -1658,6 +1713,7 @@ begin
ordersDB.UniQuery1.Open; ordersDB.UniQuery1.Open;
Result.count := ordersDB.UniQuery1.FieldByName('total_count').AsInteger; Result.count := ordersDB.UniQuery1.FieldByName('total_count').AsInteger;
ordersDB.UniQuery1.Close; ordersDB.UniQuery1.Close;
logger.Log(4, 'Users list successfully retrieved');
except except
on E: Exception do on E: Exception do
begin begin
...@@ -1752,6 +1808,7 @@ begin ...@@ -1752,6 +1808,7 @@ begin
ordersDB.UniQuery1.Post; ordersDB.UniQuery1.Post;
Result := 'Success: User Successfully Edited'; Result := 'Success: User Successfully Edited';
logger.Log(4, 'User Successfully Edited');
end; end;
ordersDB.UniQuery1.Close; ordersDB.UniQuery1.Close;
finally finally
...@@ -1763,6 +1820,7 @@ procedure TLookupService.AddToOrdersTable(mode, ORDER_TYPE: string; JSONData: TJ ...@@ -1763,6 +1820,7 @@ procedure TLookupService.AddToOrdersTable(mode, ORDER_TYPE: string; JSONData: TJ
var var
SQL: string; SQL: string;
begin begin
logger.Log(3, 'TLookupService.AddToOrdersTable');
if mode = 'ADD' then if mode = 'ADD' then
begin begin
SQL := 'select * from orders where ORDER_ID = 0 and ORDER_ID <> 0'; SQL := 'select * from orders where ORDER_ID = 0 and ORDER_ID <> 0';
...@@ -1794,6 +1852,7 @@ begin ...@@ -1794,6 +1852,7 @@ begin
ordersDB.UniQuery1.Post; ordersDB.UniQuery1.Post;
ordersDB.UniQuery1.Close; ordersDB.UniQuery1.Close;
logger.log(4, 'Order successfully added to orders table');
end; end;
function TLookupService.AddCorrugatedOrder(orderInfo: string): TJSONObject; function TLookupService.AddCorrugatedOrder(orderInfo: string): TJSONObject;
...@@ -1882,6 +1941,7 @@ begin ...@@ -1882,6 +1941,7 @@ begin
else else
msg := 'Success: Order Successfully Edited'; msg := 'Success: Order Successfully Edited';
logger.Log(4, msg);
Result := JSONData; Result := JSONData;
Result.AddPair('status', msg); Result.AddPair('status', msg);
Result.AddPair('ORDER_ID', ORDER_ID); Result.AddPair('ORDER_ID', ORDER_ID);
...@@ -1941,6 +2001,7 @@ begin ...@@ -1941,6 +2001,7 @@ begin
ordersDB.uqOrdersStatusSchedule.Post; ordersDB.uqOrdersStatusSchedule.Post;
logger.Log(4, 'Status schedule succesfully added');
Result := 'success'; Result := 'success';
end; end;
...@@ -1976,6 +2037,8 @@ begin ...@@ -1976,6 +2037,8 @@ begin
SQL := 'select * from orders_status where ORDER_ID = ' + IntToStr(ORDER_ID) + ' AND ' + SQL := 'select * from orders_status where ORDER_ID = ' + IntToStr(ORDER_ID) + ' AND ' +
'ORDER_STATUS = ' + quotedStr(Status); 'ORDER_STATUS = ' + quotedStr(Status);
logger.log(5, 'Retrieving order status with SQL: ' + SQL);
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
if ordersDB.UniQuery1.IsEmpty then if ordersDB.UniQuery1.IsEmpty then
...@@ -1999,6 +2062,7 @@ begin ...@@ -1999,6 +2062,7 @@ begin
end; end;
ordersDB.UniQuery1.Post; ordersDB.UniQuery1.Post;
logger.Log(4, 'Order Status successfully posted to database');
if StatusInfo.GetValue<string>('staff_fields_ship_date') <> '12/30/1899' then if StatusInfo.GetValue<string>('staff_fields_ship_date') <> '12/30/1899' then
AddStatusSchedule('SHIP', StatusInfo, ORDER_ID); AddStatusSchedule('SHIP', StatusInfo, ORDER_ID);
...@@ -2024,6 +2088,7 @@ begin ...@@ -2024,6 +2088,7 @@ begin
SQL := 'select * from ' + table + ' where ORDER_ID = ' + IntToStr(ORDER_ID); SQL := 'select * from ' + table + ' where ORDER_ID = ' + IntToStr(ORDER_ID);
doQuery(OrdersDB.UniQuery1, SQL); doQuery(OrdersDB.UniQuery1, SQL);
logger.Log(4, 'Updating Orders status as well with SQL: ' + SQL);
OrdersDB.UniQuery1.Edit; OrdersDB.UniQuery1.Edit;
if StatusInfo.GetValue<string>('staff_fields_ship_date') <> '12/30/1899' then if StatusInfo.GetValue<string>('staff_fields_ship_date') <> '12/30/1899' then
...@@ -2035,7 +2100,7 @@ begin ...@@ -2035,7 +2100,7 @@ begin
if StatusInfo.GetValue<string>('staff_fields_mount_due') <> '12/30/1899' then if StatusInfo.GetValue<string>('staff_fields_mount_due') <> '12/30/1899' then
OrdersDB.UniQuery1.FieldByName('staff_fields_mount_due').AsString := StatusInfo.GetValue<string>('staff_fields_mount_due'); OrdersDB.UniQuery1.FieldByName('staff_fields_mount_due').AsString := StatusInfo.GetValue<string>('staff_fields_mount_due');
OrdersDB.UniQuery1.Post; OrdersDB.UniQuery1.Post;
logger.Log(4, 'Order status successfully set');
finally finally
order.Free; order.Free;
end; end;
...@@ -2120,6 +2185,8 @@ begin ...@@ -2120,6 +2185,8 @@ begin
end end
else else
Result := 'Failure: Username already taken'; Result := 'Failure: Username already taken';
logger.Log(4, Result);
except except
on E: Exception do on E: Exception do
begin begin
...@@ -2199,9 +2266,11 @@ begin ...@@ -2199,9 +2266,11 @@ begin
ordersDB.UniQuery1.Post; ordersDB.UniQuery1.Post;
Result.AddPair('msg', 'Success: Item successfully edited'); Result.AddPair('msg', 'Success: Item successfully edited');
end; end
else
result.AddPair('msg', 'Failure: Item does not exist');
logger.Log(4, result.GetValue('msg').Value);
end; end;
except except
on E: Exception do on E: Exception do
...@@ -2320,6 +2389,7 @@ begin ...@@ -2320,6 +2389,7 @@ begin
msg := 'Success: Order Successfully Added' msg := 'Success: Order Successfully Added'
else else
msg := 'Success: Order Successfully Edited'; msg := 'Success: Order Successfully Edited';
logger.Log(4, msg);
Result := JSONData; Result := JSONData;
Result.AddPair('status', msg); Result.AddPair('status', msg);
...@@ -2414,6 +2484,7 @@ begin ...@@ -2414,6 +2484,7 @@ begin
msg := 'Success: Order Successfully Added' msg := 'Success: Order Successfully Added'
else else
msg := 'Success: Order Successfully Edited'; msg := 'Success: Order Successfully Edited';
logger.Log(4, msg);
Result := JSONData; Result := JSONData;
Result.AddPair('status', msg); Result.AddPair('status', msg);
...@@ -2476,6 +2547,8 @@ begin ...@@ -2476,6 +2547,8 @@ begin
SQL := 'SELECT * FROM ' + table + ' WHERE ORDER_ID = ' + IntToStr(OrderIDInt); SQL := 'SELECT * FROM ' + table + ' WHERE ORDER_ID = ' + IntToStr(OrderIDInt);
doQuery(OrdersDB.UniQuery1, SQL); doQuery(OrdersDB.UniQuery1, SQL);
//convert the order into a JSON object to put it in the database using existing code
logger.Log(4, 'Adding order into the revisions table before deleting...');
stream := TStringStream.Create('', TEncoding.UTF8); stream := TStringStream.Create('', TEncoding.UTF8);
try try
OrdersDB.UniQuery1.SaveToJSON(stream); OrdersDB.UniQuery1.SaveToJSON(stream);
...@@ -2528,7 +2601,7 @@ begin ...@@ -2528,7 +2601,7 @@ begin
OrdersDB.UniQuery1.FieldByName('ORDER_REVISION_ID').AsInteger := RevisionID; OrdersDB.UniQuery1.FieldByName('ORDER_REVISION_ID').AsInteger := RevisionID;
OrdersDB.UniQuery1.FieldByName('REVISION_USER_ID').AsString := UserID; OrdersDB.UniQuery1.FieldByName('REVISION_USER_ID').AsString := UserID;
OrdersDB.UniQuery1.Post; OrdersDB.UniQuery1.Post;
logger.Log(4, 'Order successfully added into revision table, beginning deletion');
finally finally
stream.Free; stream.Free;
JSONValue.Free; JSONValue.Free;
...@@ -2548,7 +2621,7 @@ begin ...@@ -2548,7 +2621,7 @@ begin
Result.AddPair('status', 'success'); Result.AddPair('status', 'success');
Result.AddPair('OrderID', IntToStr(OrderIDInt)); Result.AddPair('OrderID', IntToStr(OrderIDInt));
TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result); TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);
logger.log(4, 'order successfully deleted');
except except
on E: Exception do on E: Exception do
begin begin
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
MemoLogLevel=4 MemoLogLevel=4
FileLogLevel=4 FileLogLevel=4
webClientVersion=0.9.11 webClientVersion=0.9.11
LogFileNum=171 LogFileNum=175
[Database] [Database]
--Server=192.168.116.132 --Server=192.168.116.132
......
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