Commit 0128c655 by Cam Hayes

version 0.9.13.8 deployed on kgOrdersTest

parent 1fc480c1
......@@ -19,7 +19,7 @@ type
FUnauthorizedAccessProc: TUnauthorizedAccessProc;
public
const clientVersion = '0.9.13.7';
const clientVersion = '0.9.13.8';
procedure InitApp(SuccessProc: TSuccessProc;
UnauthorizedAccessProc: TUnauthorizedAccessProc);
procedure SetClientConfig(Callback: TVersionCheckCallback);
......
......@@ -132,18 +132,18 @@ object FViewMain: TFViewMain
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object lblLinkToQB: TWebLabel
Left = 538
Top = 128
Width = 49
object lblQBInfo: TWebLabel
Left = 552
Top = 126
Width = 36
Height = 14
Caption = 'Link to QB'
Caption = 'QB Info'
ElementID = 'dropdown.menu.linktoqb'
ElementFont = efCSS
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = lblLinkToQBClick
OnClick = lblQBInfoClick
end
object WebPanel1: TWebPanel
Left = 77
......
......@@ -33,7 +33,7 @@
<a class="dropdown-item" id="dropdown.menu.users" href="#"><i class="fas fa-address-book fa-fw"></i><span> Users</span></a>
</li>
<li>
<a class="dropdown-item" id="dropdown.menu.linktoqb" href="#"><i class="fas fa-book fa-fw"></i><span> Link to QB</span></a>
<a class="dropdown-item" id="dropdown.menu.linktoqb" href="#"><i class="fas fa-book fa-fw"></i><span> QB Info</span></a>
</li>
<li>
<hr class="dropdown-divider">
......
......@@ -6,7 +6,8 @@ uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, WEBLib.ExtCtrls, Vcl.Controls, Vcl.StdCtrls,
WEBLib.StdCtrls, Data.DB, XData.Web.JsonDataset, XData.Web.Dataset,
App.Types, ConnectionModule, XData.Web.Client, WEBLib.Menus, Utils, System.IOUtils;
App.Types, ConnectionModule, XData.Web.Client, WEBLib.Menus, Utils, System.IOUtils,
Vcl.Forms;
type
TFViewMain = class(TWebForm)
......@@ -24,7 +25,7 @@ type
lblorders: TWebLabel;
lblCustomers: TWebLabel;
lblVersion: TWebLabel;
lblLinkToQB: TWebLabel;
lblQBInfo: TWebLabel;
procedure WebFormCreate(Sender: TObject);
procedure mnuLogoutClick(Sender: TObject);
procedure wllblUserProfileClick(Sender: TObject);
......@@ -34,7 +35,7 @@ type
procedure lblUsersClick(Sender: TObject);
procedure lblordersClick(Sender: TObject);
procedure lblCustomersClick(Sender: TObject);
procedure lblLinkToQBClick(Sender: TObject);
procedure lblQBInfoClick(Sender: TObject);
{ Private declarations }
private
FUserInfo: string;
......@@ -83,7 +84,8 @@ uses
View.OrderEntryCuttingDie,
View.OrderEntryWeb,
View.Customers,
View.Customer.Add;
View.Customer.Add,
View.QBInfo;
{$R *.dfm}
......@@ -101,7 +103,7 @@ begin
if (not (JS.toString(AuthService.TokenPayload.Properties['user_access_type']) = 'ADMIN')) then
begin
lblUsers.enabled := false;
lblLinkToQB.Enabled := false;
lblQBInfo.Enabled := false;
lblCustomers.Enabled := false;
end;
lblAppTitle.Caption := 'Koehler-Gibson Orders';
......@@ -178,7 +180,7 @@ begin
ShowToast('Please Save or Cancel your changes', 'danger');
end;
procedure TFViewMain.lblLinkToQBClick(Sender: TObject);
procedure TFViewMain.lblQBInfoClick(Sender: TObject);
var
qblink, redirectUri: string;
qbWindow: TJSWindow;
......@@ -187,31 +189,34 @@ begin
end;
procedure TFViewMain.ShowQBInfoForm();
//var
// newform: TFQBInfo;
var
newform: TFQBInfo;
begin
// newform := TFQBInfo.CreateNew;
//
// newform.Caption := 'Quickbooks information';
//
// // used to manage Back button handling to close subform
// window.location.hash := 'subform';
//
// newform.ShowModal(
// procedure(AValue: TModalResult)
newform := TFQBInfo.CreateNew;
newform.Caption := 'Quickbooks information';
newForm.Popup := True;
newForm.Border := fbDialog;
newForm.Position := poScreenCenter;
// used to manage Back button handling to close subform
window.location.hash := 'subform';
newform.ShowModal(
procedure(AValue: TModalResult)
begin
// if newform.confirm then
// begin
//// if newform.confirm then
//// begin
//// if newform.cbCorrugatedPlate.Checked then
//// orderType := 'corrugated'
//// else if newform.cbWebPlate.Checked then
//// orderType := 'web'
//// else
//// orderType := 'cutting';
//// orderEntry('', newForm.DBID, 'ADD', orderType);
//// end;
// end
// );
// if newform.cbCorrugatedPlate.Checked then
// orderType := 'corrugated'
// else if newform.cbWebPlate.Checked then
// orderType := 'web'
// else
// orderType := 'cutting';
// orderEntry('', newForm.DBID, 'ADD', orderType);
// end;
end
);
end;
procedure TFViewMain.setActive(page: string);
......
object FQBInfo: TFQBInfo
Width = 640
Height = 208
object WebLabel1: TWebLabel
Width = 449
Height = 157
OnCreate = WebFormCreate
OnShow = WebFormShow
object lblConnected: TWebLabel
Left = 16
Top = 24
Width = 268
Top = 8
Width = 7
Height = 32
Caption = 'Quickbooks is not linked.'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -24
......@@ -18,7 +19,7 @@ object FQBInfo: TFQBInfo
end
object lblCompanyName: TWebLabel
Left = 16
Top = 68
Top = 46
Width = 120
Height = 21
Caption = 'Company Name: '
......@@ -33,7 +34,7 @@ object FQBInfo: TFQBInfo
end
object lblCompanyID: TWebLabel
Left = 16
Top = 98
Top = 76
Width = 93
Height = 21
Caption = 'Company ID: '
......@@ -47,8 +48,8 @@ object FQBInfo: TFQBInfo
WidthPercent = 100.000000000000000000
end
object WebButton1: TWebButton
Left = 16
Top = 125
Left = 13
Top = 107
Width = 96
Height = 25
Caption = 'Link to QB'
......@@ -57,4 +58,9 @@ object FQBInfo: TFQBInfo
WidthPercent = 100.000000000000000000
OnClick = WebButton1Click
end
object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection
Left = 376
Top = 63
end
end
......@@ -4,17 +4,23 @@ interface
uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls;
WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls,
XData.Web.Client, ConnectionModule;
type
TFQBInfo = class(TWebForm)
WebLabel1: TWebLabel;
lblConnected: TWebLabel;
lblCompanyName: TWebLabel;
lblCompanyID: TWebLabel;
WebButton1: TWebButton;
XDataWebClient1: TXDataWebClient;
procedure WebButton1Click(Sender: TObject);
procedure WebFormCreate(Sender: TObject);
procedure WebFormShow(Sender: TObject);
private
{ Private declarations }
ClientID: string;
[async] procedure GetQBInfo();
public
{ Public declarations }
end;
......@@ -26,23 +32,69 @@ implementation
{$R *.dfm}
uses View.Main, Utils;
procedure TFQBInfo.WebButton1Click(Sender: TObject);
var
qblink, redirectUri: string;
qbWindow: TJSWindow;
begin
// qblink := 'https://appcenter.intuit.com/connect/oauth2';
// //qblink := qblink + '?client_id=ABYqlDx1EsacZYXvHIJ7RDB7zmnQdwABU3fwQLIZPmBgU0VW1P';
// qblink := qblink + '?client_id=ABXLUuBrwvodIZMtaPcBg9acYBPafUxP80qk5aQ9HOAw1i2W3s';
// qblink := qblink + '&response_type=code';
// qblink := qblink + '&scope=com.intuit.quickbooks.accounting';
// qblink := qblink + '&state=7';
// //redirectUri := DMConnection.AuthConnection.URL + 'AuthService/QBAuthorize';
// qblink := qblink + '&redirect_uri=' + RedirectUri;
// console.log(redirectUri);
// qbWindow := window.open('', '_blank');
// if Assigned(qbWindow) then
// qbWindow.location.href := qbLink;
qblink := 'https://appcenter.intuit.com/connect/oauth2';
qblink := qblink + '?client_id=' + ClientID;
qblink := qblink + '&response_type=code';
qblink := qblink + '&scope=com.intuit.quickbooks.accounting';
qblink := qblink + '&state=7';
redirectUri := DMConnection.AuthConnection.URL + 'AuthService/QBAuthorize';
qblink := qblink + '&redirect_uri=' + RedirectUri;
console.log(redirectUri);
console.log(qbLink);
qbWindow := window.open('', '_blank');
if Assigned(qbWindow) then
qbWindow.location.href := qbLink;
Close();
end;
procedure TFQBInfo.WebFormCreate(Sender: TObject);
begin
if not DMConnection.ApiConnection.Connected then
begin
DMConnection.ApiConnection.OpenAsync;
console.log('report requirements connection open')
end;
end;
procedure TFQBInfo.WebFormShow(Sender: TObject);
begin
GetQBInfo();
end;
procedure TFQBInfo.GetQBInfo();
// retrieves customer list from server
var
xdcResponse: TXDataClientResponse;
QBInfo: TJSObject;
begin
try
Utils.ShowSpinner('spinner');
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.getQBInfo', []));
QBInfo := TJSObject(xdcResponse.Result);
ClientID := String(QBInfo['clientID']);
console.log(QBInfo);
if boolean(QBInfo['connected']) then
begin
lblCompanyName.Caption := lblCompanyName.Caption + String(QBInfo['CompanyName']);
lblCompanyID.Caption := lblCompanyID.Caption + String(QBInfo['CompanyID']);
lblConnected.Caption := 'QuickBooks is connected.'
end
else
lblConnected.Caption := 'Quickbooks is not connected.';
Utils.HideSpinner('spinner');
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal(E.ErrorResult.ErrorMessage);
end;
end;
end.
{
"AuthUrl" : "http://localhost:2004/kgOrders/auth/",
"ApiUrl" : "http://localhost:2004/kgOrders/api/",
"ApiUrl" : "http://localhost:2004/kgOrders/api/"
}
......@@ -29,7 +29,8 @@ uses
View.Address.Add in 'View.Address.Add.pas' {FViewAddAddress: TWebForm} {*.html},
View.Customer.Select in 'View.Customer.Select.pas' {FSelectCustomer: TWebForm} {*.html},
Utils in 'Utils.pas',
View.Item.Add in 'View.Item.Add.pas' {fViewAddItem: TWebForm} {*.html};
View.Item.Add in 'View.Item.Add.pas' {fViewAddItem: TWebForm} {*.html},
View.QBInfo in 'View.QBInfo.pas' {FQBInfo: TWebForm} {*.html};
{$R *.res}
......
......@@ -216,6 +216,11 @@
<Form>fViewAddItem</Form>
<DesignClass>TWebForm</DesignClass>
</DCCReference>
<DCCReference Include="View.QBInfo.pas">
<Form>FQBInfo</Form>
<FormType>dfm</FormType>
<DesignClass>TWebForm</DesignClass>
</DCCReference>
<None Include="index.html"/>
<None Include="css\app.css"/>
<None Include="config\config.json"/>
......
......@@ -20,6 +20,13 @@ const
API_MODEL = 'Api';
type
TQBInfo = class
public
clientID: string;
CompanyName: string;
CompanyID: string;
connected: boolean;
end;
TUserItem = class
public
......@@ -489,6 +496,7 @@ type
[HttpGet] function GetRepUsers(): TList<TUserItem>;
[HttpGet] function UpdateCustomer(QB_ID: string): TCustomerItem;
[HttpGet] function UpdateItem(itemName: string): TItemItem;
[HttpGet] function GetQBInfo(): TQBInfo;
function AddUser(userInfo: string): string;
......
......@@ -41,6 +41,7 @@ type
function GetRepUsers(): TList<TUserItem>;
function UpdateCustomer(QB_ID: string): TCustomerItem;
function UpdateItem(itemName: string): TItemItem;
function GetQBInfo(): TQBInfo;
function EditUser(const editOptions: string): string;
......@@ -87,6 +88,95 @@ implementation
uses
XData.Sys.Exceptions, uLibrary, rOrderWeb, rOrderCutting;
function TLookupService.GetQBInfo: TQBInfo;
var
restClient: TRESTClient;
restRequest: TRESTRequest;
restResponse: TRESTResponse;
param: TRESTRequestParameter;
res: string;
jsValue: TJSONValue;
jsObj: TJSONObject;
CompanyInfoList: TJSONArray;
CompanyInfo: TJSONObject;
I: integer;
AccessToken, RefreshToken, CompanyID, Client, Secret, SQL, desc, BaseUrl: string;
LastRefresh: TDateTime;
iniFile: TIniFile;
begin
logger.Log(3, 'TLookupService.GetQBItems');
iniFile := nil;
restClient := nil;
restRequest := nil;
restResponse := nil;
try
try
result := TQBInfo.Create;
iniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini');
restClient := TRESTClient.Create(nil);
restRequest := TRESTRequest.Create(nil);
restResponse := TRESTResponse.Create(nil);
result.clientID := iniFile.ReadString('Quickbooks', 'ClientID', '');
if iniFile.ReadString('Quickbooks', 'CompanyID', '') = '' then
begin
result.connected := false;
end
else
begin
restRequest.Client := restClient;
restRequest.Response := restResponse;
if iniFile.ReadString('Quickbooks', 'LastRefresh', '') = '' then
LastRefresh := 0
else
LastRefresh := StrToDateTime(iniFile.ReadString('Quickbooks', 'LastRefresh', ''));
if MinutesBetween(Now, LastRefresh) > 58 then
RefreshAccessToken();
Client := iniFile.ReadString('Quickbooks', 'ClientID', '');
Secret := iniFile.ReadString('Quickbooks', 'ClientSecret', '');
CompanyID := iniFile.ReadString('Quickbooks', 'CompanyID', '');
RefreshToken := iniFile.ReadString('Quickbooks', 'RefreshToken', '');
AccessToken := iniFile.ReadString('Quickbooks', 'AccessToken', '');
BaseUrl := iniFile.ReadString('Quickbooks', 'BaseUrl', '');
restClient.BaseURL := BaseUrl;
restRequest.Method := rmGET;
res := '/v3/company/' + companyID + '/query?query=select * from CompanyInfo&minorversion=75';
restRequest.Resource := res;
param := restRequest.Params.AddItem;
param.Name := 'Authorization';
param.Kind := pkHTTPHEADER;
param.Options := param.Options + [TRESTRequestParameterOption.poDoNotEncode];
param.Value := 'Bearer ' + AccessToken;
restRequest.Execute;
jsValue := restResponse.JSONValue;
jsObj := TJSONObject(jsValue);
CompanyInfoList := TJSONArray(TJSONObject(jsObj.GetValue('QueryResponse')).GetValue('CompanyInfo'));
CompanyInfo := CompanyInfoList.Items[I] as TJSONObject;
result.CompanyName := CompanyInfo.GetValue('CompanyName').Value;
result.CompanyID := CompanyID;
result.connected := true;
end;
except
on E: Exception do
begin
Logger.Log(1, 'Error in getQBItems: ' + E.Message);
raise EXDataHttpException.Create(500, 'Unable to retrieve QuickBooks Items: A QuickBooks interface error has occurred!');
end;
end;
finally
iniFile.Free;
restClient.Free;
restRequest.Free;
restResponse.Free;
end;
end;
function TLookupService.addEstimate(orderInfo: string): TJSONObject;
var
......
......@@ -114,11 +114,11 @@
<VerInfo_Locale>1033</VerInfo_Locale>
<DCC_ExeOutput>.\bin</DCC_ExeOutput>
<DCC_UnitSearchPath>C:\RADTOOLS\FastMM4;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<VerInfo_Keys>CompanyName=EM Systems;FileDescription=$(MSBuildProjectName);FileVersion=0.9.13.7;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=0.9.11;Comments=</VerInfo_Keys>
<VerInfo_Keys>CompanyName=EM Systems;FileDescription=$(MSBuildProjectName);FileVersion=0.9.13.8;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=0.9.11;Comments=</VerInfo_Keys>
<VerInfo_MajorVer>0</VerInfo_MajorVer>
<VerInfo_MinorVer>9</VerInfo_MinorVer>
<VerInfo_Release>13</VerInfo_Release>
<VerInfo_Build>7</VerInfo_Build>
<VerInfo_Build>8</VerInfo_Build>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1_Win64)'!=''">
<AppDPIAwarenessMode>PerMonitorV2</AppDPIAwarenessMode>
......
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