Commit 59c3c0cc by Cam Hayes

QB is now disabled from the ini

parent 962f9e80
......@@ -181,7 +181,10 @@ end;
procedure TFViewCustomers.btnAddCustomerClick(Sender: TObject);
begin
ShowSelectCustomerForm();
if AuthService.TokenPayload.Properties['qb_enabled'] then
ShowSelectCustomerForm()
else
ShowToast('QB interface not currently active', 'info');
end;
procedure TFViewCustomers.edtFilterChange(Sender: TObject);
......
......@@ -444,34 +444,40 @@ var
itemOptions: string;
newform: TFViewAddItem;
begin
newform := TFViewAddItem.CreateNew;
console.log(AuthService.TokenPayload.Properties['qb_enabled']);
if AuthService.TokenPayload.Properties['qb_enabled'] then
begin
newform := TFViewAddItem.CreateNew;
newform.Caption := 'Select Item to Add';
newForm.Popup := True;
newForm.position:= poScreenCenter;
newForm.Border := fbDialog;
newform.Caption := 'Select Item to Add';
newForm.Popup := True;
newForm.position:= poScreenCenter;
newForm.Border := fbDialog;
// used to manage Back button handling to close subform
window.location.hash := 'subform';
// used to manage Back button handling to close subform
window.location.hash := 'subform';
newform.ShowModal(
procedure(AValue: TModalResult)
begin
if newform.confirm then
newform.ShowModal(
procedure(AValue: TModalResult)
begin
xdwdsItems.Append;
if newform.confirm then
begin
xdwdsItems.Append;
xdwdsItems.FieldByName('QB_ID').AsString := newform.QB_ID;
xdwdsItems.FieldByName('name').AsString := newform.name;
xdwdsItems.FieldByName('description').AsString := newform.description;
xdwdsItems.FieldByName('status').AsString := newform.status;
xdwdsItems.FieldByName('QB_ID').AsString := newform.QB_ID;
xdwdsItems.FieldByName('name').AsString := newform.name;
xdwdsItems.FieldByName('description').AsString := newform.description;
xdwdsItems.FieldByName('status').AsString := newform.status;
xdwdsItems.Post;
EditMode();
lblFormState.Caption := 'Add Mode';
end;
end
);
xdwdsItems.Post;
EditMode();
lblFormState.Caption := 'Add Mode';
end;
end
);
end
else
ShowToast('QB interface not currently active', 'info');
end;
procedure TFViewItems.btnCancelClick(Sender: TObject);
......
......@@ -389,24 +389,31 @@ procedure TFOrderEntryCorrugated.btnQBClick(Sender: TObject);
var
orderJSON: TJSONObject;
begin
if JS.toString(AuthService.TokenPayload.Properties['user_qb_id']) <> '' then
if AuthService.TokenPayload.Properties['qb_enabled'] then
begin
if ( VerifyQBOrder() )then
begin
if wdbcbINQB.Checked = false then
if JS.toString(AuthService.TokenPayload.Properties['user_qb_id']) <> '' then
begin
Utils.ShowSpinner('spinner');
orderJSON := TJSONObject.Create;
orderJSON.AddPair('ORDER_ID', xdwdsOrder.FieldByName('ORDER_ID').AsString);
orderJSON.AddPair('USER_ID', JS.toString(AuthService.TokenPayload.Properties['user_id']));
addEstimate(orderJSON.ToString);
if ( VerifyQBOrder() )then
begin
if wdbcbINQB.Checked = false then
begin
Utils.ShowSpinner('spinner');
orderJSON := TJSONObject.Create;
orderJSON.AddPair('ORDER_ID', xdwdsOrder.FieldByName('ORDER_ID').AsString);
orderJSON.AddPair('USER_ID', JS.toString(AuthService.TokenPayload.Properties['user_id']));
addEstimate(orderJSON.ToString);
end
else
ShowToast('Failure:Cannot submit orders already in QuickBooks', 'failure');
end;
end
else
ShowToast('Failure:Cannot submit orders already in QuickBooks', 'failure');
end;
ShowToast('Failure:User not authorized to add to QuickBooks', 'failure');
end
end
else
ShowToast('Failure:User not authorized to add to QuickBooks', 'failure');
ShowToast('QB interface not currently active', 'info');
end;
[async] procedure TFOrderEntryCorrugated.GenerateReportPDF;
......
......@@ -193,24 +193,29 @@ procedure TFOrderEntryCuttingDie.btnQBClick(Sender: TObject);
var
orderJSON: TJSONObject;
begin
if JS.toString(AuthService.TokenPayload.Properties['user_qb_id']) <> '' then
if AuthService.TokenPayload.Properties['qb_enabled'] then
begin
if ( VerifyQBOrder() )then
if JS.toString(AuthService.TokenPayload.Properties['user_qb_id']) <> '' then
begin
if wdbcbINQB.Checked = false then
if ( VerifyQBOrder() )then
begin
Utils.ShowSpinner('spinner');
orderJSON := TJSONObject.Create;
orderJSON.AddPair('ORDER_ID', xdwdsOrder.FieldByName('ORDER_ID').AsString);
orderJSON.AddPair('USER_ID', JS.toString(AuthService.TokenPayload.Properties['user_id']));
addEstimate(orderJSON.ToString);
end
else
ShowToast('Failure:Cannot submit orders already in QuickBooks', 'failure');
end;
if wdbcbINQB.Checked = false then
begin
Utils.ShowSpinner('spinner');
orderJSON := TJSONObject.Create;
orderJSON.AddPair('ORDER_ID', xdwdsOrder.FieldByName('ORDER_ID').AsString);
orderJSON.AddPair('USER_ID', JS.toString(AuthService.TokenPayload.Properties['user_id']));
addEstimate(orderJSON.ToString);
end
else
ShowToast('Failure:Cannot submit orders already in QuickBooks', 'failure');
end;
end
else
ShowToast('Failure:User not authorized to add to QuickBooks', 'failure');
end
else
ShowToast('Failure:User not authorized to add to QuickBooks', 'failure');
ShowToast('QB interface not currently active', 'info');
end;
procedure TFOrderEntryCuttingDie.WebButton2Click(Sender: TObject);
......
......@@ -454,24 +454,29 @@ procedure TFOrderEntryWeb.btnQBClick(Sender: TObject);
var
orderJSON: TJSONObject;
begin
if JS.toString(AuthService.TokenPayload.Properties['user_qb_id']) <> '' then
if AuthService.TokenPayload.Properties['qb_enabled'] then
begin
if ( VerifyQBOrder() )then
if JS.toString(AuthService.TokenPayload.Properties['user_qb_id']) <> '' then
begin
if wdbcbINQB.Checked = false then
if ( VerifyQBOrder() )then
begin
Utils.ShowSpinner('spinner');
orderJSON := TJSONObject.Create;
orderJSON.AddPair('ORDER_ID', xdwdsOrder.FieldByName('ORDER_ID').AsString);
orderJSON.AddPair('USER_ID', JS.toString(AuthService.TokenPayload.Properties['user_id']));
addEstimate(orderJSON.ToString);
end
else
ShowToast('Failure:Cannot submit orders already in QuickBooks', 'failure');
end;
if wdbcbINQB.Checked = false then
begin
Utils.ShowSpinner('spinner');
orderJSON := TJSONObject.Create;
orderJSON.AddPair('ORDER_ID', xdwdsOrder.FieldByName('ORDER_ID').AsString);
orderJSON.AddPair('USER_ID', JS.toString(AuthService.TokenPayload.Properties['user_id']));
addEstimate(orderJSON.ToString);
end
else
ShowToast('Failure:Cannot submit orders already in QuickBooks', 'failure');
end;
end
else
ShowToast('Failure:User not authorized to add to QuickBooks', 'failure');
end
else
ShowToast('Failure:User not authorized to add to QuickBooks', 'failure');
ShowToast('QB interface not currently active', 'info');
end;
procedure TFOrderEntryWeb.AddEstimate(orderID: string);
......
......@@ -27,9 +27,9 @@ type
userAccessType: string;
userEmail: string;
userStatus: string;
qbEnabled: boolean;
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
property Query: TUniQuery read GetQuery;
function CheckUser(const user, password: string): Integer;
public
function Login(const user, password: string): string;
......@@ -81,6 +81,7 @@ begin
try
webClientVersion := iniFile.ReadString('Settings', 'webClientVersion', '');
Result.AddPair('webClientVersion', webClientVersion);
qbEnabled := iniFile.ReadBool('Quickbooks', 'Enabled', false);
if webClientVersion = '' then
begin
......@@ -102,6 +103,7 @@ end;
function TAuthService.Login(const user, password: string): string;
var
userState: Integer;
iniFile: TIniFile;
JWT: TJWT;
begin
Logger.Log(3, Format( 'AuthService.Login - User: "%s"', [User]));
......@@ -131,6 +133,14 @@ begin
raise EXDataHttpUnauthorized.Create('User not active!');
logger.Log(2, 'Login Error: User not active!');
iniFile := TIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));
try
qbEnabled := iniFile.ReadBool('Quickbooks', 'Enabled', false);
finally
iniFile.Free;
end;
JWT := TJWT.Create;
try
JWT.Claims.JWTId := LowerCase(Copy(TUtils.GuidToVariant(TUtils.NewGuid), 2, 36));
......@@ -144,6 +154,7 @@ begin
JWT.Claims.SetClaimOfType<string>('user_email', userEmail);
JWT.Claims.SetClaimOfType<string>('user_qb_id', userQBID);
JWT.Claims.SetClaimOfType<string>('user_access_type', userAccessType);
JWT.Claims.SetClaimOfType<boolean>('qb_enabled', qbEnabled);
Result := TJOSE.SHA256CompactToken(serverConfig.jwtTokenSecret, JWT);
finally
......
......@@ -98,7 +98,6 @@ var
f: TStringList;
fi: string;
JSObj: TJSONObject;
iniFile: TIniFile;
Encoder: TBase64Encoding;
begin
// 1. Encode credentials (same as working Postman request)
......@@ -129,7 +128,7 @@ begin
SSLIO.SSLOptions.SSLVersions := [sslvTLSv1_2];
IdHTTP.IOHandler := SSLIO;
// Set headers (EXACT match with Postman)
// Set headers
IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP.Request.Accept := 'application/json';
IdHTTP.Request.CustomHeaders.AddValue('Authorization', 'Basic ' + EncodedAuth);
......@@ -162,7 +161,6 @@ end;
procedure TQBService.SaveTokens(AccessToken, RefreshToken: string);
var
f: TStringList;
iniStr, line: string;
iniFile: TIniFile;
begin
iniFile := TIniFile.Create( ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini' );
......
......@@ -2,7 +2,7 @@
MemoLogLevel=4
FileLogLevel=4
webClientVersion=1.0.0
LogFileNum=137
LogFileNum=141
[Database]
--Server=192.168.116.138
......@@ -15,6 +15,7 @@ Password=emsys01
--Password=emsys!012
[Quickbooks]
Enabled=0
CompanyID=9341454336461805
ClientID=ABYqlDx1EsacZYXvHIJ7RDB7zmnQdwABU3fwQLIZPmBgU0VW1P
ClientSecret=PM7OnvQWsgOqjWfDpZAnyRttDN9446Am6d85pDxr
......
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