Commit 102303cd by Cam Hayes

Auto stash before checking out "origin/master"

Temp commint before merging
parent 95296f5f
...@@ -376,6 +376,100 @@ type ...@@ -376,6 +376,100 @@ type
general_special_instructions: string; general_special_instructions: string;
end; end;
// These objects are only used for quickbooks estimates.
TRef = record
value: string;
name: string; // optional
end;
TCustomerMemo = record
value: string;
end;
TAddress = record
Line1: string;
Line2: string; // optional
Line3: string; // optional
Line4: string; //optional
Line5: string; //optional
City: string;
CountrySubDivisionCode: string;
PostalCode: string;
Country: string; // optional
end;
TTaxCodeRef = record
value: string;
end;
TClassRef = record
value: string;
end;
TSalesItemLineDetail = record
ItemRef: TRef;
Qty: Double;
UnitPrice: Double;
TaxCodeRef: TTaxCodeRef; // optional
ClassRef: TClassRef; // optional
ServiceDate: string; // optional
end;
TLine = record
Id: string; // optional (auto-generated if omitted)
LineNum: Integer; // optional
Description: string; // optional
Amount: Double;
DetailType: string;
SalesItemLineDetail: TSalesItemLineDetail;
end;
TCustomField = record
DefinitionId: string;
Name: string;
Type_: string;
StringValue: string;
end;
TTxnTaxCodeRef = record
value: string;
end;
TTxnTaxDetail = record
TxnTaxCodeRef: TTxnTaxCodeRef;
TotalTax: Double;
end;
TEmail = record
Address: string;
end;
TEstimate = record
DocNumber: string; // optional
TxnDate: string;
PrivateNote: string; // optional
CustomerRef: TRef;
CustomerMemo: TCustomerMemo; // optional
BillAddr: TAddress; // optional
ShipAddr: TAddress; // optional
ShipMethodRef: TRef; // optional
SalesTermRef: TRef; // optional
DueDate: string; // optional
ClassRef: TRef; // optional
DepartmentRef: TRef; // optional
CurrencyRef: TRef; // optional
ExchangeRate: Double; // optional
EmailStatus: string; // optional
BillEmail: TEmail; // optional
ShipDate: string; // optional
TrackingNum: string; // optional
CustomerMsgRef: TRef; // optional
CustomField: TArray<TCustomField>; // optional
Line: TArray<TLine>;
TxnTaxDetail: TTxnTaxDetail; // optional
end;
type type
[ServiceContract, Model(API_MODEL)] [ServiceContract, Model(API_MODEL)]
......
...@@ -2382,6 +2382,7 @@ begin ...@@ -2382,6 +2382,7 @@ begin
ParsedCustomer.AddPair('Id', Customer.GetValue<string>('Id')); ParsedCustomer.AddPair('Id', Customer.GetValue<string>('Id'));
ParsedCustomer.AddPair('CompanyName', Customer.GetValue<string>('DisplayName')); ParsedCustomer.AddPair('CompanyName', Customer.GetValue<string>('DisplayName'));
// Handle Bill Address // Handle Bill Address
if Customer.GetValue('BillAddr') is TJSONObject then if Customer.GetValue('BillAddr') is TJSONObject then
begin begin
......
...@@ -2,8 +2,8 @@ object fQB: TfQB ...@@ -2,8 +2,8 @@ object fQB: TfQB
Left = 0 Left = 0
Top = 0 Top = 0
Caption = 'fQB' Caption = 'fQB'
ClientHeight = 711 ClientHeight = 661
ClientWidth = 962 ClientWidth = 982
Color = clBtnFace Color = clBtnFace
Font.Charset = DEFAULT_CHARSET Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText Font.Color = clWindowText
...@@ -13,55 +13,24 @@ object fQB: TfQB ...@@ -13,55 +13,24 @@ object fQB: TfQB
OnCreate = FormCreate OnCreate = FormCreate
OnDestroy = FormDestroy OnDestroy = FormDestroy
TextHeight = 15 TextHeight = 15
object Memo1: TMemo
Left = 0
Top = 76
Width = 962
Height = 260
Align = alBottom
Lines.Strings = (
'Memo1')
ScrollBars = ssVertical
TabOrder = 0
end
object Button1: TButton
Left = 42
Top = 18
Width = 87
Height = 25
Caption = 'Company Info'
TabOrder = 1
OnClick = Button1Click
end
object Memo2: TMemo
Left = 0
Top = 336
Width = 962
Height = 196
Align = alBottom
Lines.Strings = (
'')
ScrollBars = ssVertical
TabOrder = 2
end
object Button2: TButton object Button2: TButton
Left = 135 Left = 4
Top = 22 Top = 32
Width = 87 Width = 111
Height = 25 Height = 25
Caption = 'Get Customers' Caption = 'Get QB Customers'
TabOrder = 3 TabOrder = 0
OnClick = Button2Click OnClick = Button2Click
end end
object asgData: TAdvStringGrid object asgData: TAdvStringGrid
Left = 0 Left = 0
Top = 532 Top = 482
Width = 962 Width = 982
Height = 179 Height = 179
Align = alBottom Align = alBottom
DrawingStyle = gdsClassic DrawingStyle = gdsClassic
FixedColor = clWhite FixedColor = clWhite
TabOrder = 4 TabOrder = 1
GridLineColor = 13948116 GridLineColor = 13948116
GridFixedLineColor = 11250603 GridFixedLineColor = 11250603
ActiveCellFont.Charset = DEFAULT_CHARSET ActiveCellFont.Charset = DEFAULT_CHARSET
...@@ -179,6 +148,9 @@ object fQB: TfQB ...@@ -179,6 +148,9 @@ object fQB: TfQB
SortSettings.HeaderMirrorColor = clWhite SortSettings.HeaderMirrorColor = clWhite
SortSettings.HeaderMirrorColorTo = clWhite SortSettings.HeaderMirrorColorTo = clWhite
Version = '9.1.4.1' Version = '9.1.4.1'
ExplicitLeft = -40
ExplicitTop = 316
ExplicitWidth = 962
ColWidths = ( ColWidths = (
64 64
64 64
...@@ -198,38 +170,205 @@ object fQB: TfQB ...@@ -198,38 +170,205 @@ object fQB: TfQB
22) 22)
end end
object Button3: TButton object Button3: TButton
Left = 228 Left = 121
Top = 22 Top = 5
Width = 139 Width = 139
Height = 25 Height = 25
Caption = 'Get Customer By ID' Caption = 'Get Customer By ID'
TabOrder = 5 TabOrder = 2
OnClick = Button3Click OnClick = Button3Click
end end
object Button4: TButton object Button4: TButton
Left = 373 Left = 266
Top = 22 Top = 5
Width = 95 Width = 95
Height = 25 Height = 25
Caption = 'Add Estimate' Caption = 'Add Estimate'
TabOrder = 6 TabOrder = 3
OnClick = Button4Click OnClick = Button4Click
end end
object Button5: TButton object Button5: TButton
Left = 472 Left = 367
Top = 22 Top = 5
Width = 169 Width = 169
Height = 25 Height = 25
Caption = 'Show Customers with Orders' Caption = 'Show Customers with Orders'
TabOrder = 7 TabOrder = 4
OnClick = Button5Click OnClick = Button5Click
end end
object Memo1: TMemo
Left = 0
Top = 60
Width = 982
Height = 228
Align = alBottom
Lines.Strings = (
'')
ScrollBars = ssVertical
TabOrder = 5
ExplicitWidth = 962
end
object asgData2: TAdvStringGrid
Left = 0
Top = 288
Width = 982
Height = 194
Align = alBottom
DrawingStyle = gdsClassic
FixedColor = clWhite
TabOrder = 6
GridLineColor = 13948116
GridFixedLineColor = 11250603
OnClickCell = asgData2ClickCell
ActiveCellFont.Charset = DEFAULT_CHARSET
ActiveCellFont.Color = 4474440
ActiveCellFont.Height = -12
ActiveCellFont.Name = 'Segoe UI'
ActiveCellFont.Style = [fsBold]
ActiveCellColor = 11565130
ActiveCellColorTo = 11565130
BorderColor = 11250603
ControlLook.FixedGradientFrom = clWhite
ControlLook.FixedGradientTo = clWhite
ControlLook.FixedGradientHoverTo = clWhite
ControlLook.FixedGradientHoverMirrorFrom = clWhite
ControlLook.FixedGradientHoverMirrorTo = clWhite
ControlLook.FixedGradientHoverBorder = 11645361
ControlLook.FixedGradientDownFrom = clWhite
ControlLook.FixedGradientDownTo = clWhite
ControlLook.FixedGradientDownMirrorFrom = clWhite
ControlLook.FixedGradientDownMirrorTo = clWhite
ControlLook.FixedGradientDownBorder = 11250603
ControlLook.DropDownHeader.Font.Charset = DEFAULT_CHARSET
ControlLook.DropDownHeader.Font.Color = clWindowText
ControlLook.DropDownHeader.Font.Height = -11
ControlLook.DropDownHeader.Font.Name = 'Segoe UI'
ControlLook.DropDownHeader.Font.Style = []
ControlLook.DropDownHeader.Visible = True
ControlLook.DropDownHeader.Buttons = <>
ControlLook.DropDownFooter.Font.Charset = DEFAULT_CHARSET
ControlLook.DropDownFooter.Font.Color = clWindowText
ControlLook.DropDownFooter.Font.Height = -11
ControlLook.DropDownFooter.Font.Name = 'Segoe UI'
ControlLook.DropDownFooter.Font.Style = []
ControlLook.DropDownFooter.Visible = True
ControlLook.DropDownFooter.Buttons = <>
ControlLook.ToggleSwitch.BackgroundBorderWidth = 1.000000000000000000
ControlLook.ToggleSwitch.ButtonBorderWidth = 1.000000000000000000
ControlLook.ToggleSwitch.CaptionFont.Charset = DEFAULT_CHARSET
ControlLook.ToggleSwitch.CaptionFont.Color = clWindowText
ControlLook.ToggleSwitch.CaptionFont.Height = -12
ControlLook.ToggleSwitch.CaptionFont.Name = 'Segoe UI'
ControlLook.ToggleSwitch.CaptionFont.Style = []
ControlLook.ToggleSwitch.Shadow = False
Filter = <>
FilterDropDown.Font.Charset = DEFAULT_CHARSET
FilterDropDown.Font.Color = clWindowText
FilterDropDown.Font.Height = -12
FilterDropDown.Font.Name = 'Segoe UI'
FilterDropDown.Font.Style = []
FilterDropDown.TextChecked = 'Checked'
FilterDropDown.TextUnChecked = 'Unchecked'
FilterDropDownClear = '(All)'
FilterEdit.TypeNames.Strings = (
'Starts with'
'Ends with'
'Contains'
'Not contains'
'Equal'
'Not equal'
'Larger than'
'Smaller than'
'Clear')
FixedRowHeight = 22
FixedFont.Charset = DEFAULT_CHARSET
FixedFont.Color = 3881787
FixedFont.Height = -11
FixedFont.Name = 'Segoe UI'
FixedFont.Style = [fsBold]
FloatFormat = '%.2f'
HoverButtons.Buttons = <>
HTMLSettings.ImageFolder = 'images'
HTMLSettings.ImageBaseName = 'img'
Look = glCustom
PrintSettings.DateFormat = 'dd/mm/yyyy'
PrintSettings.Font.Charset = DEFAULT_CHARSET
PrintSettings.Font.Color = clWindowText
PrintSettings.Font.Height = -12
PrintSettings.Font.Name = 'Segoe UI'
PrintSettings.Font.Style = []
PrintSettings.FixedFont.Charset = DEFAULT_CHARSET
PrintSettings.FixedFont.Color = clWindowText
PrintSettings.FixedFont.Height = -12
PrintSettings.FixedFont.Name = 'Segoe UI'
PrintSettings.FixedFont.Style = []
PrintSettings.HeaderFont.Charset = DEFAULT_CHARSET
PrintSettings.HeaderFont.Color = clWindowText
PrintSettings.HeaderFont.Height = -12
PrintSettings.HeaderFont.Name = 'Segoe UI'
PrintSettings.HeaderFont.Style = []
PrintSettings.FooterFont.Charset = DEFAULT_CHARSET
PrintSettings.FooterFont.Color = clWindowText
PrintSettings.FooterFont.Height = -12
PrintSettings.FooterFont.Name = 'Segoe UI'
PrintSettings.FooterFont.Style = []
PrintSettings.PageNumSep = '/'
SearchFooter.ColorTo = clNone
SearchFooter.FindNextCaption = 'Find &next'
SearchFooter.FindPrevCaption = 'Find &previous'
SearchFooter.Font.Charset = DEFAULT_CHARSET
SearchFooter.Font.Color = clWindowText
SearchFooter.Font.Height = -12
SearchFooter.Font.Name = 'Segoe UI'
SearchFooter.Font.Style = []
SearchFooter.HighLightCaption = 'Highlight'
SearchFooter.HintClose = 'Close'
SearchFooter.HintFindNext = 'Find next occurrence'
SearchFooter.HintFindPrev = 'Find previous occurrence'
SearchFooter.HintHighlight = 'Highlight occurrences'
SearchFooter.MatchCaseCaption = 'Match case'
SearchFooter.ResultFormat = '(%d of %d)'
SelectionColor = 13744549
SortSettings.HeaderColor = clWhite
SortSettings.HeaderColorTo = clWhite
SortSettings.HeaderMirrorColor = clWhite
SortSettings.HeaderMirrorColorTo = clWhite
Version = '9.1.4.1'
ExplicitWidth = 962
end
object Button6: TButton
Left = 538
Top = 5
Width = 108
Height = 25
Caption = 'Match Customers'
TabOrder = 7
OnClick = Button6Click
end
object Button7: TButton
Left = 652
Top = 5
Width = 186
Height = 25
Caption = 'Show Customers without Orders'
TabOrder = 8
OnClick = Button7Click
end
object Button1: TButton
Left = 4
Top = 5
Width = 111
Height = 25
Caption = 'Get KG Customers'
TabOrder = 9
OnClick = Button1Click
end
object uq: TUniQuery object uq: TUniQuery
Connection = ApiDatabase.ucKG Connection = ApiDatabase.ucKG
SQL.Strings = ( SQL.Strings = (
'select * from web_plate_orders') 'select * from web_plate_orders')
Left = 743 Left = 851
Top = 36 Top = 182
object uqORDER_ID: TIntegerField object uqORDER_ID: TIntegerField
FieldName = 'ORDER_ID' FieldName = 'ORDER_ID'
Required = True Required = True
......
...@@ -16,9 +16,6 @@ uses ...@@ -16,9 +16,6 @@ uses
type type
TfQB = class(TForm) TfQB = class(TForm)
Memo1: TMemo;
Button1: TButton;
Memo2: TMemo;
Button2: TButton; Button2: TButton;
asgData: TAdvStringGrid; asgData: TAdvStringGrid;
Button3: TButton; Button3: TButton;
...@@ -110,6 +107,11 @@ type ...@@ -110,6 +107,11 @@ type
uqupc_distortion_percent: TStringField; uqupc_distortion_percent: TStringField;
uqupc_distortion_amount: TStringField; uqupc_distortion_amount: TStringField;
uqstaff_fields_art_location: TStringField; uqstaff_fields_art_location: TStringField;
Memo1: TMemo;
asgData2: TAdvStringGrid;
Button6: TButton;
Button7: TButton;
Button1: TButton;
procedure Button1Click(Sender: TObject); procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject); procedure Button2Click(Sender: TObject);
...@@ -117,6 +119,9 @@ type ...@@ -117,6 +119,9 @@ type
procedure Button4Click(Sender: TObject); procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject); procedure Button5Click(Sender: TObject);
procedure FormDestroy(Sender: TObject); procedure FormDestroy(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure asgData2ClickCell(Sender: TObject; ARow, ACol: Integer);
private private
{ Private declarations } { Private declarations }
strict private strict private
...@@ -128,8 +133,10 @@ type ...@@ -128,8 +133,10 @@ type
LastRefresh: TDateTime; LastRefresh: TDateTime;
public public
{ Public declarations } { Public declarations }
procedure findMatches(CustomerList: TJSONArray; JSONfield, DBField: string);
procedure getCompanyInfo(); procedure getCompanyInfo();
procedure LoadJsonArray(jaData: TJSONArray); procedure LoadJsonArray(jaData: TJSONArray);
procedure LoadJsonArray2(jaData: TJSONArray);
function RefreshAccessToken(): string; function RefreshAccessToken(): string;
procedure ConfigureSSL(IOHandler: TIdSSLIOHandlerSocketOpenSSL); procedure ConfigureSSL(IOHandler: TIdSSLIOHandlerSocketOpenSSL);
procedure SaveTokens(AccessToken, RefreshToken: string); procedure SaveTokens(AccessToken, RefreshToken: string);
...@@ -142,13 +149,61 @@ var ...@@ -142,13 +149,61 @@ var
implementation implementation
uses uses
Common.Logging, uLibrary; Common.Logging, uLibrary, Lookup.Service, Lookup.ServiceImpl;
{$R *.dfm} {$R *.dfm}
procedure TfQB.asgData2ClickCell(Sender: TObject; ARow, ACol: Integer);
var
point, origin: TPoint;
begin
origin := TPoint.Create(0,0);
Memo1.Lines.Add( asgData2.Cells[2, ARow]);
point := asgData.find(origin, asgData2.Cells[2, ARow], []);
asgData.Row := point.Y;
end;
procedure TfQB.Button1Click(Sender: TObject); procedure TfQB.Button1Click(Sender: TObject);
var
SQL: string;
count: integer;
ModifiedList: TJSONArray;
Customer, ParsedCustomer: TJSONObject;
I: integer;
begin begin
getCompanyInfo(); SQL := 'SELECT * FROM customers c';
doQuery(ordersDB.UniQuery1, SQL);
ModifiedList := TJSONArray.Create;
while not ordersDB.UniQuery1.Eof do
begin
ParsedCustomer := TJSONObject.Create;
//sql := 'select CUSTOMER_ID from customers where QB_LIST_ID = ' + Customer.GetValue<string>('Id');
//doQuery(ordersDB.UniQuery1, SQL);
try
//ParsedCustomer.AddPair('In KGOrders', not(ordersDB.UniQuery1.IsEmpty));
ParsedCustomer.AddPair('Id', ordersDB.UniQuery1.FieldByName('CUSTOMER_ID').AsString);
ParsedCustomer.AddPair('CompanyName', ordersDB.UniQuery1.FieldByName('NAME').AsString);
ParsedCustomer.AddPair('BillAddrCity', ordersDB.UniQuery1.FieldByName('BILL_CITY').AsString);
ParsedCustomer.AddPair('BillAddrLine1', ordersDB.UniQuery1.FieldByName('BILL_ADDRESS').AsString);
ParsedCustomer.AddPair('BillAddrState', ordersDB.UniQuery1.FieldByName('BILL_STATE').AsString);
ParsedCustomer.AddPair('BillAddrZip', ordersDB.UniQuery1.FieldByName('BILL_ZIP').AsString);
ParsedCustomer.AddPair('BillAddr', ordersDB.UniQuery1.FieldByName('BILL_ADDRESS_BLOCK').AsString);
ModifiedList.AddElement(ParsedCustomer);
ordersDB.UniQuery1.Next;
except
ParsedCustomer.Free;
raise;
end;
end;
LoadJSONArray2(ModifiedList);
end; end;
procedure TfQB.SaveTokens(AccessToken, RefreshToken: string); procedure TfQB.SaveTokens(AccessToken, RefreshToken: string);
...@@ -226,7 +281,6 @@ begin ...@@ -226,7 +281,6 @@ begin
jsValue := restResponse.JSONValue; jsValue := restResponse.JSONValue;
jsObj := TJSONObject(jsValue); jsObj := TJSONObject(jsValue);
//Memo2.Lines.Add(res);
Memo1.Lines.Add( jsObj.Format(2) ); Memo1.Lines.Add( jsObj.Format(2) );
// CustomerList := TJSONArray( TJSONObject( jsObj.GetValue('QueryResponse') ).GetValue('Customer')) ; // CustomerList := TJSONArray( TJSONObject( jsObj.GetValue('QueryResponse') ).GetValue('Customer')) ;
...@@ -252,7 +306,18 @@ var ...@@ -252,7 +306,18 @@ var
CustomerList: TJSONArray; CustomerList: TJSONArray;
pair: TJSONPair; pair: TJSONPair;
estimateJSON: TJSONObject; estimateJSON: TJSONObject;
SQL: string;
estimate: TEstimate;
begin begin
SQL := 'select * from corrugated_plate_orders cpo join customers c on cpo.COMPANY_ID = c.CUSTOMER_ID where ORDER_ID = 18690';
doQuery(ordersDB.UniQuery1, SQL);
estimate.TxnDate := DateTimeToStr(Now);
estimate.PrivateNote := ordersDB.UniQuery1.FieldByName('general_special_instructions').AsString;
//estimate.CustomerRef := order
///v3/company/<realmID>/estimate ///v3/company/<realmID>/estimate
restClient := TRESTClient.Create(nil); restClient := TRESTClient.Create(nil);
restClient.BaseURL := 'https://sandbox-quickbooks.api.intuit.com'; restClient.BaseURL := 'https://sandbox-quickbooks.api.intuit.com';
...@@ -286,7 +351,6 @@ begin ...@@ -286,7 +351,6 @@ begin
jsValue := restResponse.JSONValue; jsValue := restResponse.JSONValue;
jsObj := TJSONObject(jsValue); jsObj := TJSONObject(jsValue);
//Memo2.Lines.Add(res);
Memo1.Lines.Add( jsObj.Format(2) ); Memo1.Lines.Add( jsObj.Format(2) );
//CustomerList := TJSONArray(restResponse.JSONValue); //CustomerList := TJSONArray(restResponse.JSONValue);
...@@ -303,20 +367,156 @@ procedure TfQB.Button5Click(Sender: TObject); ...@@ -303,20 +367,156 @@ procedure TfQB.Button5Click(Sender: TObject);
var var
SQL: string; SQL: string;
count: integer; count: integer;
ModifiedList: TJSONArray;
Customer, ParsedCustomer: TJSONObject;
I: integer;
begin begin
SQL := 'SELECT c.CUSTOMER_ID, c.SHORT_NAME, c.NAME FROM customers c ' + SQL := 'SELECT * FROM customers c ' +
'WHERE EXISTS (SELECT 1 FROM corrugated_plate_orders cpo WHERE cpo.COMPANY_ID = c.CUSTOMER_ID) '+ 'WHERE EXISTS (SELECT 1 FROM corrugated_plate_orders cpo WHERE cpo.COMPANY_ID = c.CUSTOMER_ID) '+
'OR EXISTS (SELECT 1 FROM web_plate_orders wpo WHERE wpo.COMPANY_ID = c.CUSTOMER_ID) ORDER BY c.SHORT_NAME'; 'OR EXISTS (SELECT 1 FROM web_plate_orders wpo WHERE wpo.COMPANY_ID = c.CUSTOMER_ID) ORDER BY c.SHORT_NAME';
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
ModifiedList := TJSONArray.Create;
while not ordersDB.UniQuery1.Eof do
begin
ParsedCustomer := TJSONObject.Create;
//sql := 'select CUSTOMER_ID from customers where QB_LIST_ID = ' + Customer.GetValue<string>('Id');
//doQuery(ordersDB.UniQuery1, SQL);
try
//ParsedCustomer.AddPair('In KGOrders', not(ordersDB.UniQuery1.IsEmpty));
ParsedCustomer.AddPair('Id', ordersDB.UniQuery1.FieldByName('CUSTOMER_ID').AsString);
ParsedCustomer.AddPair('CompanyName', ordersDB.UniQuery1.FieldByName('NAME').AsString);
ParsedCustomer.AddPair('BillAddrCity', ordersDB.UniQuery1.FieldByName('BILL_CITY').AsString);
ParsedCustomer.AddPair('BillAddrLine1', ordersDB.UniQuery1.FieldByName('BILL_ADDRESS').AsString);
ParsedCustomer.AddPair('BillAddrState', ordersDB.UniQuery1.FieldByName('BILL_STATE').AsString);
ParsedCustomer.AddPair('BillAddrZip', ordersDB.UniQuery1.FieldByName('BILL_ZIP').AsString);
ParsedCustomer.AddPair('BillAddr', ordersDB.UniQuery1.FieldByName('BILL_ADDRESS_BLOCK').AsString);
ModifiedList.AddElement(ParsedCustomer);
ordersDB.UniQuery1.Next;
except
ParsedCustomer.Free;
raise;
end;
end;
LoadJSONArray2(ModifiedList);
end;
procedure TfQB.Button6Click(Sender: TObject);
var
restClient: TRESTClient;
restRequest: TRESTRequest;
restResponse: TRESTResponse;
param: TRESTRequestParameter;
res: string;
jsValue: TJSONValue;
jsObj: TJSONObject;
CustomerList: TJSONArray;
pair: TJSONPair;
ModifiedList: TJSONArray;
ParsedCustomer, Customer: TJSONObject;
I: integer;
BillAddr: TJSONObject;
ShipAddr: TJSONObject;
SQL: string;
begin
restClient := TRESTClient.Create(nil);
restClient.BaseURL := 'https://sandbox-quickbooks.api.intuit.com';
restRequest := TRESTRequest.Create(nil);
restRequest.Client := restClient;
restResponse := TRESTResponse.Create(nil);
restRequest.Response := restResponse;
if MinutesBetween(Now, LastRefresh) > 58 then
begin
RefreshAccessToken();
end;
restRequest.Method := rmGET;
//res := '/v3/company/' + companyID + '/preferences';
res := '/v3/company/' + companyID + '/query?query=select * from Customer&minorversion=75'; // '/customer/58';
restRequest.Resource := res;
///query?query=select * from Customer where CompanyName = ' + quotedStr('TYOGA CONTAINER') + '&minorversion=75';
param := restRequest.Params.AddItem;
param.Name := 'Authorization';
param.Kind := pkHTTPHEADER;
param.Options := param.Options + [TRESTRequestParameterOption.poDoNotEncode];
param.Value := 'Bearer ' + AccessToken;
restRequest.Execute;
//memo1.Lines.Add(restresponse.Content);
jsValue := restResponse.JSONValue;
jsObj := TJSONObject(jsValue);
//CustomerList := TJSONArray(restResponse.JSONValue);
CustomerList := TJSONArray( TJSONObject( jsObj.GetValue('QueryResponse') ).GetValue('Customer')) ;
//LoadJSONArray( CustomerList );
findMatches(CustomerList, 'DisplayName', 'Name');
//findMatches(CustomerList, 'BillAddrLine1', 'BILL_ADDRESS');
//findMatches(CustomerList, 'BillAddrCity', 'BILL_CITY');
//findMatches(CustomerList, 'BillAddrState', 'BILL_STATE');
//findMatches(CustomerList, 'BillAddrZip', 'BILL_ZIP');
end;
procedure TfQB.Button7Click(Sender: TObject);
var
SQL: string;
count: integer;
ModifiedList: TJSONArray;
Customer, ParsedCustomer: TJSONObject;
I: integer;
begin
SQL := 'SELECT * FROM customers c ' +
'WHERE NOT EXISTS (SELECT 1 FROM corrugated_plate_orders cpo WHERE cpo.COMPANY_ID = c.CUSTOMER_ID) '+
'AND NOT EXISTS (SELECT 1 FROM web_plate_orders wpo WHERE wpo.COMPANY_ID = c.CUSTOMER_ID) ORDER BY c.SHORT_NAME';
doQuery(ordersDB.UniQuery1, SQL);
ModifiedList := TJSONArray.Create;
while not ordersDB.UniQuery1.Eof do while not ordersDB.UniQuery1.Eof do
begin begin
Memo2.Lines.Add(ordersDB.UniQuery1.FieldByName('CUSTOMER_ID').AsString + ', ' + ordersDB.UniQuery1.FieldByName('SHORT_NAME').AsString + ', ' + ordersDB.UniQuery1.FieldByName('NAME').AsString); ParsedCustomer := TJSONObject.Create;
OrdersDB.UniQuery1.Next;
count := count + 1; //sql := 'select CUSTOMER_ID from customers where QB_LIST_ID = ' + Customer.GetValue<string>('Id');
//doQuery(ordersDB.UniQuery1, SQL);
try
//ParsedCustomer.AddPair('In KGOrders', not(ordersDB.UniQuery1.IsEmpty));
ParsedCustomer.AddPair('Id', ordersDB.UniQuery1.FieldByName('CUSTOMER_ID').AsString);
ParsedCustomer.AddPair('CompanyName', ordersDB.UniQuery1.FieldByName('NAME').AsString);
ParsedCustomer.AddPair('BillAddrCity', ordersDB.UniQuery1.FieldByName('BILL_CITY').AsString);
ParsedCustomer.AddPair('BillAddrLine1', ordersDB.UniQuery1.FieldByName('BILL_ADDRESS').AsString);
ParsedCustomer.AddPair('BillAddrState', ordersDB.UniQuery1.FieldByName('BILL_STATE').AsString);
ParsedCustomer.AddPair('BillAddrZip', ordersDB.UniQuery1.FieldByName('BILL_ZIP').AsString);
ParsedCustomer.AddPair('BillAddr', ordersDB.UniQuery1.FieldByName('BILL_ADDRESS_BLOCK').AsString);
ModifiedList.AddElement(ParsedCustomer);
ordersDB.UniQuery1.Next;
except
ParsedCustomer.Free;
raise;
end;
end; end;
Memo2.Lines.Add('Showing ' + IntToStr(count) + ' entries'); LoadJSONArray2(ModifiedList);
end; end;
...@@ -337,6 +537,7 @@ var ...@@ -337,6 +537,7 @@ var
BillAddr: TJSONObject; BillAddr: TJSONObject;
ShipAddr: TJSONObject; ShipAddr: TJSONObject;
begin begin
restClient := TRESTClient.Create(nil); restClient := TRESTClient.Create(nil);
restClient.BaseURL := 'https://sandbox-quickbooks.api.intuit.com'; restClient.BaseURL := 'https://sandbox-quickbooks.api.intuit.com';
...@@ -372,18 +573,80 @@ begin ...@@ -372,18 +573,80 @@ begin
jsValue := restResponse.JSONValue; jsValue := restResponse.JSONValue;
jsObj := TJSONObject(jsValue); jsObj := TJSONObject(jsValue);
Memo2.Lines.Add(res);
Memo2.Lines.Add( jsObj.Format(2) );
//CustomerList := TJSONArray(restResponse.JSONValue); //CustomerList := TJSONArray(restResponse.JSONValue);
Memo1.Lines.Add( jsObj.Format(2) );
CustomerList := TJSONArray( TJSONObject( jsObj.GetValue('QueryResponse') ).GetValue('Customer')) ; CustomerList := TJSONArray( TJSONObject( jsObj.GetValue('QueryResponse') ).GetValue('Customer')) ;
LoadJSONArray( CustomerList ); // Load customer info
ModifiedList := TJSONArray.Create;
for I := 0 to CustomerList.Count - 1 do
begin
Customer := CustomerList.Items[I] as TJSONObject;
Memo1.Lines.Add( Customer.Format(2) );
ParsedCustomer := TJSONObject.Create;
//sql := 'select CUSTOMER_ID from customers where QB_LIST_ID = ' + Customer.GetValue<string>('Id');
//doQuery(ordersDB.UniQuery1, SQL);
try
//ParsedCustomer.AddPair('In KGOrders', not(ordersDB.UniQuery1.IsEmpty));
ParsedCustomer.AddPair('Id', Customer.GetValue<string>('Id'));
ParsedCustomer.AddPair('CompanyName', Customer.GetValue<string>('DisplayName'));
// Handle Bill Address
if Customer.GetValue('BillAddr') is TJSONObject then
begin
BillAddr := Customer.GetValue('BillAddr') as TJSONObject;
ParsedCustomer.AddPair('BillAddrLine1', TJSONString.Create(BillAddr.GetValue<string>('Line1', '')));
ParsedCustomer.AddPair('BillAddrCity', TJSONString.Create(BillAddr.GetValue<string>('City', '')));
ParsedCustomer.AddPair('BillAddrState', TJSONString.Create(BillAddr.GetValue<string>('CountrySubDivisionCode', '')));
ParsedCustomer.AddPair('BillAddrZip', TJSONString.Create(BillAddr.GetValue<string>('PostalCode', '')));
ParsedCustomer.AddPair('BillAddr',
TJSONString.Create(
Customer.GetValue<string>('DisplayName') + sLineBreak +
BillAddr.GetValue('Line1', '') + ',' + sLineBreak +
BillAddr.GetValue('City', '') + ', ' +
BillAddr.GetValue('CountrySubDivisionCode', '') + ' ' +
BillAddr.GetValue('PostalCode', '')
)
);
end;
// Handle Ship Address
if Customer.GetValue('ShipAddr') is TJSONObject then
begin
BillAddr := Customer.GetValue('ShipAddr') as TJSONObject;
ParsedCustomer.AddPair('ShipAddrLine1', TJSONString.Create(BillAddr.GetValue<string>('Line1', '')));
ParsedCustomer.AddPair('ShipAddrCity', TJSONString.Create(BillAddr.GetValue<string>('City', '')));
ParsedCustomer.AddPair('ShipAddrState', TJSONString.Create(BillAddr.GetValue<string>('CountrySubDivisionCode', '')));
ParsedCustomer.AddPair('ShipAddrZip', TJSONString.Create(BillAddr.GetValue<string>('PostalCode', '')));
ParsedCustomer.AddPair('ShipAddr',
TJSONString.Create(
Customer.GetValue<string>('DisplayName') + sLineBreak +
BillAddr.GetValue('Line1', '') + ',' + sLineBreak +
BillAddr.GetValue('City', '') + ', ' +
BillAddr.GetValue('CountrySubDivisionCode', '') + ' ' +
BillAddr.GetValue('PostalCode', '')
)
);
end;
ModifiedList.AddElement(ParsedCustomer);
except
ParsedCustomer.Free;
raise;
end;
end;
LoadJSONArray(ModifiedList);
restClient.Free; restClient.Free;
restRequest.Free; restRequest.Free;
restResponse.Free; restResponse.Free;
end; end;
procedure TfQB.ConfigureSSL(IOHandler: TIdSSLIOHandlerSocketOpenSSL); procedure TfQB.ConfigureSSL(IOHandler: TIdSSLIOHandlerSocketOpenSSL);
...@@ -475,7 +738,6 @@ begin ...@@ -475,7 +738,6 @@ begin
// 4. Create and send request // 4. Create and send request
RequestStream := TStringStream.Create(PostData, TEncoding.UTF8); RequestStream := TStringStream.Create(PostData, TEncoding.UTF8);
try try
// Execute POST // Execute POST
try try
response := IdHTTP.Post('https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer', RequestStream); response := IdHTTP.Post('https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer', RequestStream);
...@@ -488,7 +750,7 @@ begin ...@@ -488,7 +750,7 @@ begin
Memo1.Lines.Add('Tokens Successfully Saved'); Memo1.Lines.Add('Tokens Successfully Saved');
except except
on E: EIdHTTPProtocolException do on E: EIdHTTPProtocolException do
Memo2.Lines.Add('Error: ' + E.Message + #13#10 + 'Response: ' + E.ErrorMessage); Memo1.Lines.Add('Error: ' + E.Message + #13#10 + 'Response: ' + E.ErrorMessage);
end; end;
finally finally
RequestStream.Free; RequestStream.Free;
...@@ -576,5 +838,59 @@ begin ...@@ -576,5 +838,59 @@ begin
asgData.AutoSizeColumns(true); asgData.AutoSizeColumns(true);
end; end;
procedure TfQB.LoadJsonArray2(jaData: TJSONArray);
var
jso: TJSONObject;
i, j: integer;
row: integer;
begin
Memo1.Lines.Add( '---------------------------------------------------------------' );
Memo1.Lines.Add( 'LoadJsonArray into asgData' );
asgData2.ClearAll;
asgData2.RowCount := 1;
asgData2.StartUpdate;
jso := TJSONObject(jaData.Items[0]);
asgData2.ColCount := jso.Count;
for i := 0 to jso.Count - 1 do
asgData2.Cells[i+1, 0] := jso.Pairs[i].JsonString.Value;
for i := 0 to jaData.Count - 1 do
begin
jso := TJSONObject(jaData.Items[i]);
asgData2.RowCount := asgData2.RowCount + 1;
row := asgData2.RowCount - 1;
for j := 0 to jso.Count - 1 do
asgData2.Cells[j+1, row] := jso.Pairs[j].JsonValue.Value;
end;
asgData2.EndUpdate;
asgData2.AutoSizeColumns(true);
end;
procedure tfQB.findMatches(CustomerList: TJSONArray; JSONfield, DBField: string);
var
I: integer;
Customer: TJSONObject;
SQL: string;
begin
Memo1.Lines.Add('Matching ' + JSONfield + ' on ' + DBField);
for I := 0 to CustomerList.Count - 1 do
begin
Customer := CustomerList.Items[I] as TJSONObject;
SQL := 'select COUNT(*) as count from customers where NAME = ' + quotedStr(Customer.GetValue<string>(JSONfield));
doQuery(ordersDB.UniQuery1, SQL);
if ordersDB.UniQuery1.FieldByName('count').AsInteger = 1 then
begin
SQL := 'select * from customers where ' + DBField + ' = ' + quotedStr(Customer.GetValue<string>(JSONfield));
doQuery(ordersDB.UniQuery1, SQL);
Memo1.Lines.Add('Match at ' + ordersDB.UniQuery1.FieldByName('SHORT_NAME').AsString)
end
else if ordersDB.UniQuery1.FieldByName('count').AsInteger > 1 then
Memo1.Lines.Add(ordersDB.UniQuery1.FieldByName('count').AsString + ' Matches at ' + Customer.GetValue<string>(JSONfield) + ' in field ' + JSONfield);
end;
end;
end. end.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
MemoLogLevel=3 MemoLogLevel=3
FileLogLevel=5 FileLogLevel=5
webClientVersion=0.9.2 webClientVersion=0.9.2
LogFileNum=621 LogFileNum=661
[Database] [Database]
Server=192.168.159.131 Server=192.168.159.131
...@@ -17,6 +17,6 @@ Password=emsys01 ...@@ -17,6 +17,6 @@ Password=emsys01
CompanyID=9341454272655710 CompanyID=9341454272655710
ClientID=ABgO14uvjh8XqLud7spQ8lkb98AUpcdA7HbyMJfCAtl65sQ5yy ClientID=ABgO14uvjh8XqLud7spQ8lkb98AUpcdA7HbyMJfCAtl65sQ5yy
ClientSecret=bQ06TRemHeAGFzVHRaTUvUoBU9jpU9itK6MOMgqN ClientSecret=bQ06TRemHeAGFzVHRaTUvUoBU9jpU9itK6MOMgqN
RefreshToken=RT1-113-H0-1757255538seyqgsf5e04vo9schkoa RefreshToken=RT1-136-H0-1757775400coc1hvsehylf0uejgm7f
AccessToken=eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwieC5vcmciOiJIMCJ9..Cqnj0xScf85NYKa6g4lanA.LN1AIU3ZlnDDbIMt-J4vl8V_gvcTfynSjGKYsmbhbfBJovq5IfZU4dHt6cqDAwUfnfOm42l-OpbwN9hWrZvUGlVx8x_3MA-vdtxIOByp7neq5vL2t4XcR5svPKIkX-CqlTsTb2ylBARiXehgk3tVHBysbHcnp0Ka0Ic_Waj64wQMYvE3Z-D19gCu-Xn9WFQwDICn8HSgJmHL2huLvRX-OrcxH6uERzLcQqRLsgT7fx9j68UWDW-KL_KRnzE43ieXlxXCwiCDnaF39Ei5iPHstnh19lGMgo1Z1mlF6tVZ9-8Z1prZutpiX8rzaPzS7Wdqo8pKtYaUqQZP6AGa6ZCqWR2BlF3y-R_FtheERNpafRiXWIDW68jOOrgp8QXc1uKA0sxDMjiLE7Bd0t9QAsIzln-0WiWIXFSlLGLimMd2oxxLoR7fpQvgB851I50b4S3V-c891WA8bHfuzScmjVwp40JxofhviFXwAevLNzRYvGkvIyz4oS9d6U6K_ZWKDB3iYxEgJzkFFwnfuPybWX7iNHwnmvFfAXz61jdaL9KRJM-lCChGuaQuv8_df9z_az_sbUtXJw2I8ivEppmDEQVxv49ZwzJlb6bFbqtnhy6ILO7_ecx3G1d4Utg-BrtgvzsR.oFJV6VBShL1-cERGZEqqkw AccessToken=eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwieC5vcmciOiJIMCJ9..Cqnj0xScf85NYKa6g4lanA.LN1AIU3ZlnDDbIMt-J4vl8V_gvcTfynSjGKYsmbhbfBJovq5IfZU4dHt6cqDAwUfnfOm42l-OpbwN9hWrZvUGlVx8x_3MA-vdtxIOByp7neq5vL2t4XcR5svPKIkX-CqlTsTb2ylBARiXehgk3tVHBysbHcnp0Ka0Ic_Waj64wQMYvE3Z-D19gCu-Xn9WFQwDICn8HSgJmHL2huLvRX-OrcxH6uERzLcQqRLsgT7fx9j68UWDW-KL_KRnzE43ieXlxXCwiCDnaF39Ei5iPHstnh19lGMgo1Z1mlF6tVZ9-8Z1prZutpiX8rzaPzS7Wdqo8pKtYaUqQZP6AGa6ZCqWR2BlF3y-R_FtheERNpafRiXWIDW68jOOrgp8QXc1uKA0sxDMjiLE7Bd0t9QAsIzln-0WiWIXFSlLGLimMd2oxxLoR7fpQvgB851I50b4S3V-c891WA8bHfuzScmjVwp40JxofhviFXwAevLNzRYvGkvIyz4oS9d6U6K_ZWKDB3iYxEgJzkFFwnfuPybWX7iNHwnmvFfAXz61jdaL9KRJM-lCChGuaQuv8_df9z_az_sbUtXJw2I8ivEppmDEQVxv49ZwzJlb6bFbqtnhy6ILO7_ecx3G1d4Utg-BrtgvzsR.oFJV6VBShL1-cERGZEqqkw
LastRefresh=5/28/2025 10:46:30 AM LastRefresh=5/28/2025 10:46:30 AM
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