Commit 03b02ef4 by Cam Hayes

Fixed Minor Bugs in AddCustomer Form and began working on importing QB Customers

QB Implementation is currently commented out.
parent ec390bdd
......@@ -136,18 +136,6 @@ object FViewAddCustomer: TFViewAddCustomer
DataField = 'FAX'
DataSource = WebDataSource1
end
object edtRep: TWebDBEdit
Left = 19
Top = 332
Width = 121
Height = 22
ChildOrder = 12
ElementID = 'edtrepid'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
DataField = 'REP_USER_ID'
DataSource = WebDataSource1
end
object btnSave: TWebButton
Left = 19
Top = 402
......@@ -221,7 +209,7 @@ object FViewAddCustomer: TFViewAddCustomer
ChildOrder = 5
ElementPosition = epRelative
Role = 'null'
TabOrder = 17
TabOrder = 16
object lblMessage: TWebLabel
Left = 28
Top = 9
......@@ -505,6 +493,20 @@ object FViewAddCustomer: TFViewAddCustomer
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object wdblcbRep: TWebDBLookupComboBox
Left = 19
Top = 336
Width = 145
Height = 22
ElementID = 'wdblcbrep'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
DataField = 'REP_USER_ID'
DataSource = WebDataSource1
KeyField = 'userID'
ListField = 'full_name'
ListSource = wdsUsers
end
object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection
Left = 454
......@@ -544,24 +546,24 @@ object FViewAddCustomer: TFViewAddCustomer
object XDataWebDataSet1START_DATE: TStringField
FieldName = 'START_DATE'
end
object XDataWebDataSet1END_DATE: TStringField
FieldName = 'END_DATE'
end
object XDataWebDataSet1QB_LIST_ID: TStringField
FieldName = 'QB_LIST_ID'
end
object XDataWebDataSet1END_DATE: TStringField
FieldName = 'END_DATE'
end
object XDataWebDataSet1FAX: TStringField
FieldName = 'FAX'
end
object XDataWebDataSet1PHONE: TStringField
FieldName = 'PHONE'
end
object XDataWebDataSet1REP_USER_ID: TIntegerField
FieldName = 'REP_USER_ID'
end
object XDataWebDataSet1CUSTOMER_ID: TIntegerField
FieldName = 'CUSTOMER_ID'
end
object XDataWebDataSet1REP_USER_ID: TStringField
FieldName = 'REP_USER_ID'
end
end
object wdsShipTo: TWebDataSource
DataSet = xdwdsShipTo
......@@ -600,4 +602,20 @@ object FViewAddCustomer: TFViewAddCustomer
Left = 542
Top = 42
end
object wdsUsers: TWebDataSource
DataSet = xdwdsUsers
Left = 776
Top = 144
end
object xdwdsUsers: TXDataWebDataSet
Left = 776
Top = 54
object xdwdsUsersuserID: TStringField
FieldName = 'userID'
end
object xdwdsUsersfull_name: TStringField
FieldName = 'full_name'
Size = 0
end
end
end
......@@ -70,8 +70,8 @@
<input id="edtfax" class="form-control input-sm"style="width: 200px"/>
</div>
<div class="col-auto">
<label for="wdbe_first_name" style="font-weight: 700; font-size: 15px;" class="form-label mt-2">Representative ID:</label>
<input id="edtrepid" class="form-control input-sm" style="width: 200px"/>
<label for="wdbe_first_name" style="font-weight: 700; font-size: 15px;" class="form-label mt-2">Representative:</label>
<select id="wdblcbrep" class='form-select'></select>
</div>
</div>
<h4 class="custom-h4 mt-3">Billing Information</h4>
......
object FViewAddAddress: TFViewAddAddress
Width = 281
Height = 402
object WebLabel1: TWebLabel
Left = 8
Top = 283
Width = 92
Height = 15
Caption = 'Shipping Contact'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object WebLabel2: TWebLabel
Left = 8
Top = 234
Width = 67
Height = 15
Caption = 'Shipping Zip'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object WebLabel3: TWebLabel
Left = 8
Top = 136
Width = 71
Height = 15
Caption = 'Shipping City'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object WebLabel4: TWebLabel
Left = 8
Top = 185
Width = 76
Height = 15
Caption = 'Shipping State'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object WebLabel5: TWebLabel
Left = 8
Top = 87
Width = 92
Height = 15
Caption = 'Shipping Address'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object WebLabel6: TWebLabel
Left = 8
Top = 36
Width = 47
Height = 15
Caption = 'First Line'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object edtState: TWebEdit
Left = 8
Top = 206
Width = 78
Height = 22
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object edtFirstLine: TWebEdit
Left = 8
Top = 59
Width = 198
Height = 22
ChildOrder = 1
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object edtCity: TWebEdit
Left = 8
Top = 157
Width = 149
Height = 22
ChildOrder = 2
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object edtZip: TWebEdit
Left = 8
Top = 255
Width = 121
Height = 22
ChildOrder = 3
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object edtContact: TWebEdit
Left = 8
Top = 304
Width = 198
Height = 22
ChildOrder = 4
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object edtAddress: TWebEdit
Left = 8
Top = 108
Width = 198
Height = 22
ChildOrder = 1
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object edtNotification: TWebEdit
Left = 8
Top = 8
Width = 198
Height = 22
ChildOrder = 12
Enabled = False
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object btnSave: TWebButton
Left = 8
Top = 340
Width = 96
Height = 25
Caption = 'Save'
ChildOrder = 13
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = btnSaveClick
end
object btnCancel: TWebButton
Left = 110
Top = 340
Width = 96
Height = 25
Caption = 'Cancel'
ChildOrder = 13
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = btnCancelClick
end
end
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>TMS Web Project</title>
<style>
</style>
</head>
<body>
</body>
</html>
\ No newline at end of file
// Small Pop-Up page when adding orders if you want to quickly add an address
unit View.AddAddress;
interface
uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls;
type
TFViewAddAddress = class(TWebForm)
edtState: TWebEdit;
edtFirstLine: TWebEdit;
edtCity: TWebEdit;
edtZip: TWebEdit;
edtContact: TWebEdit;
edtAddress: TWebEdit;
WebLabel1: TWebLabel;
WebLabel2: TWebLabel;
WebLabel3: TWebLabel;
WebLabel4: TWebLabel;
WebLabel5: TWebLabel;
WebLabel6: TWebLabel;
edtNotification: TWebEdit;
btnSave: TWebButton;
btnCancel: TWebButton;
procedure btnCancelClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
private
{ Private declarations }
function Verify(): boolean;
public
{ Public declarations }
var
confirm: boolean;
end;
var
FViewAddAddress: TFViewAddAddress;
implementation
{$R *.dfm}
procedure TFViewAddAddress.btnSaveClick(Sender: TObject);
begin
if Verify() then
begin
confirm := true;
Close;
end;
end;
function TFViewAddAddress.Verify(): boolean;
// Makes sure the address is filled in.
begin
result := true;
if edtFirstLine.Text = '' then
begin
edtNotification.Text := 'Please Fill in the First Line';
result := false;
end
else if edtAddress.Text = '' then
begin
edtNotification.Text := 'Please Fill in the Address';
result := false;
end
else if edtCity.Text = '' then
begin
edtNotification.Text := 'Please Fill in the City';
result := false;
end
else
if edtState.Text = '' then
begin
edtNotification.Text := 'Please Fill in the State';
result := false;
end
else if edtZip.Text = '' then
begin
edtNotification.Text := 'Please Fill in the Zip Code';
result := false;
end
else if edtContact.Text = '' then
begin
edtNotification.Text := 'Please Fill in the Contact';
result := false;
end
end;
procedure TFViewAddAddress.btnCancelClick(Sender: TObject);
begin
Close;
end;
end.
\ No newline at end of file
// Customer Form accessed from the ccustomer header in the main form.
unit View.Customers;
interface
......@@ -41,6 +43,7 @@ type
function GenerateSearchOptions(): string;
procedure HideNotification();
procedure ShowNotification(Notification: string);
procedure ShowSelectCustomerForm();
var
PageNumber: integer;
......@@ -58,10 +61,41 @@ var
implementation
uses
XData.Model.Classes, View.Main;
XData.Model.Classes, View.Main, View.SelectCustomer;
{$R *.dfm}
procedure TFViewCustomers.ShowSelectCustomerForm();
// displays the add order pop-up so the user can choose a customer
var
newform: TFSelectCustomer;
begin
newform := TFSelectCustomer.CreateNew;
newform.Caption := 'Select Customer and Order Type';
newForm.Popup := True;
newForm.Border := fbDialog;
// 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.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 TFViewCustomers.WebFormCreate(Sender: TObject);
// Initializes important values:
// PageNumber: What page number the user is on IE 1: 1-10, 2: 11-20 etc
......@@ -113,6 +147,9 @@ begin
lblEntries.Caption := 'No entries found';
end
else if (PageNumber * PageSize) < customerListLength then
// Currently these do the same thing. If you want to limit the number of entries
// You will need to edit the server side, and then change this if statement so the label
// Correctly displayes. I believe it is IntToStr(PageSize * PageNum)
begin
lblEntries.Caption := 'Showing entries ' + IntToStr((PageNumber - 1) * PageSize + 1) +
' - ' + IntToStr(customerListLength) +
......@@ -184,6 +221,7 @@ end;
procedure TFViewCustomers.btnAddCustomerClick(Sender: TObject);
begin
//ShowSelectCustomerForm();
FViewMain.ViewAddCustomer('', '');
end;
......@@ -196,6 +234,7 @@ end;
procedure TFViewCustomers.GeneratePagination(TotalPages: Integer);
// Generates pagination for the table.
// TotalPages: Total amount of pages generated by the search
// This could definitely be improved.
var
PaginationElement, PageItem, PageLink: TJSHTMLElement;
I, Start, Finish: Integer;
......
......@@ -24,17 +24,6 @@ object FViewEditUser: TFViewEditUser
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object lblQB: TWebLabel
Left = 256
Top = 65
Width = 80
Height = 15
Caption = 'Quickbooks ID:'
Color = clBtnFace
ElementID = 'lblQB'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object WebLabel5: TWebLabel
Left = 284
Top = 8
......@@ -92,20 +81,21 @@ object FViewEditUser: TFViewEditUser
object lblAccess: TWebLabel
Left = 272
Top = 96
Width = 66
Width = 67
Height = 15
Caption = 'Access Type:'
ElementID = 'lblaccess'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object lblPerspective: TWebLabel
Left = 3
Top = 132
Width = 77
object lblQB: TWebLabel
Left = 256
Top = 65
Width = 80
Height = 15
Caption = 'Perspective ID:'
ElementID = 'lblperspective'
Caption = 'Quickbooks ID:'
Color = clBtnFace
ElementID = 'lblQB'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
......@@ -256,16 +246,6 @@ object FViewEditUser: TFViewEditUser
ParentFont = False
WidthPercent = 100.000000000000000000
end
object edtQB: TWebEdit
Left = 348
Top = 62
Width = 121
Height = 22
ChildOrder = 7
ElementID = 'edtQB'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object edtRights: TWebEdit
Left = 96
Top = 93
......@@ -293,13 +273,13 @@ object FViewEditUser: TFViewEditUser
'ALL'
'ACTIVE')
end
object edtPerspective: TWebEdit
Left = 96
Top = 129
object edtQB: TWebEdit
Left = 346
Top = 62
Width = 121
Height = 22
ChildOrder = 23
ElementID = 'edtperspective'
ChildOrder = 7
ElementID = 'edtQB'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
......
......@@ -48,15 +48,10 @@
</div>
</form>
<div class="row">
<div class="col-sm">
<div class="col-6">
<label class='pe-2' style="font-weight: 700;font-size: 15px;" id="lblrights">System Rights:</label>
<input id="edtrights" class= "form-control input-sm" width='50%'/>
</div>
<div class="col-sm-6">
<label class='pe-2' style="font-weight: 700;font-size: 15px;" id="lblperspective">Perspective ID:</label>
<input id="edtperspective" class= "form-control input-sm" width='50%'/>
</div>
</div>
<div class="row">
<div class="col-sm py-3">
......
......@@ -14,7 +14,6 @@ type
TFViewEditUser = class(TWebForm)
WebLabel2: TWebLabel;
WebLabel3: TWebLabel;
lblQB: TWebLabel;
WebLabel5: TWebLabel;
WebLabel6: TWebLabel;
WebLabel7: TWebLabel;
......@@ -34,12 +33,11 @@ type
lblactive: TWebLabel;
cbStatus: TWebCheckBox;
lblRights: TWebLabel;
edtQB: TWebEdit;
edtRights: TWebEdit;
lblAccess: TWebLabel;
cbAccess: TWebComboBox;
lblPerspective: TWebLabel;
edtPerspective: TWebEdit;
lblQB: TWebLabel;
edtQB: TWebEdit;
procedure WebFormCreate(Sender: TObject);
procedure btnConfirmClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
......@@ -121,7 +119,6 @@ begin
'&access=' + cbAccess.Text +
'&newuser=' + edtUsername.Text +
'&rights=' + edtRights.Text +
'&perspective=' + edtPerspective.Text +
'&QB=' + edtQB.Text;
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddUser',
......@@ -160,7 +157,6 @@ begin
'&access=' + cbAccess.Text +
'&newuser=' + edtUsername.Text +
'&rights=' + edtRights.Text +
'&perspective=' + edtPerspective.Text +
'&QB=' + edtQB.Text;
console.log(editOptions);
......@@ -215,7 +211,6 @@ begin
edtQB.Text := QB;
if Status = 'ACTIVE' then
cbStatus.checked := true;
edtPerspective.Text := Perspective
end;
procedure TFViewEditUser.WebTimer1Timer(Sender: TObject);
......
......@@ -1226,6 +1226,18 @@ object FOrderEntryCorrugated: TFOrderEntryCorrugated
WidthPercent = 100.000000000000000000
OnClick = btnAddClick
end
object WebButton2: TWebButton
Left = 186
Top = 429
Width = 96
Height = 25
Caption = 'Add Address'
ChildOrder = 85
ElementID = 'btnaddaddress'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = WebButton2Click
end
object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection
Left = 1014
......
......@@ -107,6 +107,9 @@
<div class="invalid-feedback" style="font-size: 15px;">
Please Provide a Ship To Address.
</div>
<div class="mt-2">
<button id="btnaddaddress" class="btn btn-primary btn-sm">Add Address</button>
</div>
</div>
<div class="col-auto">
<label for="wdbe_first_name" style="font-weight: 700; font-size: 15px;" class="form-label mt-2">PO Number:</label>
......
......@@ -202,6 +202,7 @@ type
tmrReturn: TWebTimer;
btnEdit: TWebButton;
btnAdd: TWebButton;
WebButton2: TWebButton;
procedure WebFormCreate(Sender: TObject);
procedure HideNotification();
procedure ShowNotification(Notification: string);
......@@ -238,6 +239,9 @@ type
procedure btnAddClick(Sender: TObject);
procedure xdwdsQBItemAfterEdit(DataSet: TDataSet);
procedure ViewMode();
procedure WebButton2Click(Sender: TObject);
procedure ShowAddAddressForm();
[async] procedure SendAddressToServer(AddressJSON: TJSONObject);
private
FAgencyCode: string;
FCurrentReportType: string;
......@@ -260,9 +264,12 @@ implementation
{$R *.dfm}
uses
View.Home, View.Main, View.AddOrder;
View.Home, View.Main, View.AddOrder, View.AddAddress;
procedure TFOrderEntryCorrugated.sendOrderToServer();
// This can be improved. I was struggling to get the checkboxes to work with
// The dataset at first, but if you just change the fields in the database to be
// Booleans it should work
var
colorList: TJSONArray;
container: TJSElement;
......@@ -654,6 +661,73 @@ begin
addColorRow('','','','');
end;
procedure TFOrderEntryCorrugated.WebButton2Click(Sender: TObject);
begin
ShowAddAddressForm();
end;
procedure TFOrderEntryCorrugated.SendAddressToServer(AddressJSON: TJSONObject);
var
Response: TXDataClientResponse;
notification: TJSObject;
begin
Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddShippingAddress',
[AddressJSON.ToString]));
notification := TJSObject(Response.Result);
ShowNotification(string(notification['status']));
xdwdsShipTo.Close;
xdwdsShipTo.SetJSONData(notification['ADDRESS']);
xdwdsShipTo.Open;
end;
procedure TFOrderEntryCorrugated.ShowAddAddressForm;
// displays the search pop-up that allows the user to filter the order list
var
newform: TFViewAddAddress;
AddressJSON: TJSONObject;
ship_block: string;
begin
newform := TFViewAddAddress.CreateNew;
newform.Caption := 'Input Shipping Information';
newForm.Popup := True;
newForm.Border := fbDialog;
// used to manage Back button handling to close subform
window.location.hash := 'subform';
newform.ShowModal(
procedure(AValue: TModalResult)
var
searchOptions: string;
begin
if newform.confirm then
begin
AddressJSON := TJSONObject.Create;
AddressJSON.AddPair('address', newform.edtAddress.Text);
AddressJSON.AddPair('city', newform.edtCity.Text);
AddressJSON.AddPair('state', newform.edtState.Text);
AddressJSON.AddPair('zip', newform.edtZip.Text);
AddressJSON.AddPair('contact', newform.edtContact.Text);
AddressJSON.AddPair('customer_id', customerID);
ship_block := newform.edtFirstLine.Text + slinebreak +
edtCompanyName.Text + slinebreak +
newform.edtContact.Text + slinebreak +
newform.edtAddress.Text + slinebreak +
newform.edtCity.Text + ', ' + newform.edtState.Text + ' ' + newform.edtZip.Text;
AddressJSON.AddPair('ship_block', ship_block);
AddressJSON.AddPair('mode', 'ADD');
sendAddressToServer(AddressJSON);
end;
end
);
end;
procedure TFOrderEntryCorrugated.btnAddClick(Sender: TObject);
var
newform: TFAddOrder;
......
......@@ -386,6 +386,18 @@ object FOrderEntryCuttingDie: TFOrderEntryCuttingDie
WidthPercent = 100.000000000000000000
OnClick = btnAddClick
end
object WebButton2: TWebButton
Left = 186
Top = 429
Width = 96
Height = 25
Caption = 'Add Address'
ChildOrder = 85
ElementID = 'btnaddaddress'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = WebButton2Click
end
object WebDataSource1: TWebDataSource
DataSet = XDataWebDataSet1
Left = 22
......@@ -470,13 +482,13 @@ object FOrderEntryCuttingDie: TFOrderEntryCuttingDie
end
object wdsShipTo: TWebDataSource
DataSet = xdwdsShipTo
Left = 212
Top = 436
Left = 302
Top = 418
end
object xdwdsShipTo: TXDataWebDataSet
AfterEdit = xdwdsShipToAfterEdit
Left = 270
Top = 436
Left = 288
Top = 370
object xdwdsShipToADDRESS: TStringField
FieldName = 'ADDRESS'
end
......
......@@ -52,7 +52,7 @@
</div>
</div>
<div class="col-auto">
<label for="wdbe_first_name" style="font-weight: 700; font-size: 15px;" class="form-label mt-2">>In Quickbooks?:</label>
<label for="wdbe_first_name" style="font-weight: 700; font-size: 15px;" class="form-label mt-2">In Quickbooks?:</label>
<input id="edtinquickbooks"type="text" class="form-control" style="width: 150px"/>
</div>
</div>
......@@ -103,6 +103,9 @@
<div class="invalid-feedback" style="font-size: 15px;">
Please Provide a Ship To Address.
</div>
<div class="mt-2">
<button id="btnaddaddress" class="btn btn-primary btn-sm">Add Address</button>
</div>
</div>
<div class="col-auto">
<label for="wdbe_first_name" style="font-weight: 700; font-size: 15px;" class="form-label mt-2">PO Number:</label>
......
......@@ -73,6 +73,7 @@ type
tmrReturn: TWebTimer;
btnEdit: TWebButton;
btnAdd: TWebButton;
WebButton2: TWebButton;
procedure btnSaveClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure WebFormCreate(Sender: TObject);
......@@ -101,6 +102,9 @@ type
procedure dtpOrderDateChange(Sender: TObject);
procedure btnEditClick(Sender: TObject);
procedure ViewMode();
procedure WebButton2Click(Sender: TObject);
procedure ShowAddAddressForm();
[async] procedure SendAddressToServer(AddressJSON: TJSONObject);
private
FAgencyCode: string;
FCurrentReportType: string;
......@@ -121,7 +125,73 @@ implementation
{$R *.dfm}
uses
View.Home, View.Main, View.AddOrder;
View.Home, View.Main, View.AddOrder, View.AddAddress;
procedure TFOrderEntryCuttingDie.WebButton2Click(Sender: TObject);
begin
ShowAddAddressForm();
end;
procedure TFOrderEntryCuttingDie.SendAddressToServer(AddressJSON: TJSONObject);
var
Response: TXDataClientResponse;
notification: TJSObject;
begin
Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddShippingAddress',
[AddressJSON.ToString]));
notification := TJSObject(Response.Result);
ShowNotification(string(notification['status']));
xdwdsShipTo.Close;
xdwdsShipTo.SetJSONData(notification['ADDRESS']);
xdwdsShipTo.Open;
end;
procedure TFOrderEntryCuttingDie.ShowAddAddressForm;
// displays the search pop-up that allows the user to filter the order list
var
newform: TFViewAddAddress;
AddressJSON: TJSONObject;
ship_block: string;
begin
newform := TFViewAddAddress.CreateNew;
newform.Caption := 'Shipping Information';
newForm.Popup := True;
newForm.Border := fbDialog;
// used to manage Back button handling to close subform
window.location.hash := 'subform';
newform.ShowModal(
procedure(AValue: TModalResult)
var
searchOptions: string;
begin
if newform.confirm then
begin
AddressJSON := TJSONObject.Create;
AddressJSON.AddPair('address', newform.edtAddress.Text);
AddressJSON.AddPair('city', newform.edtCity.Text);
AddressJSON.AddPair('state', newform.edtState.Text);
AddressJSON.AddPair('zip', newform.edtZip.Text);
AddressJSON.AddPair('contact', newform.edtContact.Text);
AddressJSON.AddPair('customer_id', customerID);
ship_block := newform.edtFirstLine.Text + slinebreak +
edtCompanyName.Text + slinebreak +
newform.edtContact.Text + slinebreak +
newform.edtAddress.Text + slinebreak +
newform.edtCity.Text + ', ' + newform.edtState.Text + ' ' + newform.edtZip.Text;
AddressJSON.AddPair('ship_block', ship_block);
AddressJSON.AddPair('mode', 'ADD');
sendAddressToServer(AddressJSON);
end;
end
);
end;
function TFOrderEntryCuttingDie.VerifyOrder: Boolean;
var
......
......@@ -1284,6 +1284,18 @@ object FOrderEntryWeb: TFOrderEntryWeb
WidthPercent = 100.000000000000000000
OnClick = btnAddClick
end
object WebButton2: TWebButton
Left = 174
Top = 372
Width = 96
Height = 25
Caption = 'Add Address'
ChildOrder = 85
ElementID = 'btnaddaddress'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = WebButton2Click
end
object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection
Left = 160
......
......@@ -103,6 +103,9 @@
<div class="invalid-feedback" style="font-size: 15px;">
Please Provide a Ship To Address.
</div>
<div class="mt-2">
<button id="btnaddaddress" class="btn btn-primary btn-sm">Add Address</button>
</div>
</div>
<div class="col-auto">
<label style="font-weight: 700; font-size: 15px;" class="form-label mt-2">PO Number:</label>
......
......@@ -206,6 +206,7 @@ type
tmrReturn: TWebTimer;
btnEdit: TWebButton;
btnAdd: TWebButton;
WebButton2: TWebButton;
procedure WebFormCreate(Sender: TObject);
procedure HideNotification();
procedure ShowNotification(Notification: string);
......@@ -235,6 +236,9 @@ type
procedure XDataWebDataSet1AfterEdit(DataSet: TDataSet);
procedure dtpOrderDateChange(Sender: TObject);
procedure ViewMode();
procedure WebButton2Click(Sender: TObject);
procedure ShowAddAddressForm();
[async] procedure SendAddressToServer(AddressJSON: TJSONObject);
private
FAgencyCode: string;
FCurrentReportType: string;
......@@ -256,7 +260,73 @@ implementation
{$R *.dfm}
uses
View.Home, View.Main, View.AddOrder;
View.Home, View.Main, View.AddOrder, View.AddAddress;
procedure TFOrderEntryWeb.WebButton2Click(Sender: TObject);
begin
ShowAddAddressForm();
end;
procedure TFOrderEntryWeb.SendAddressToServer(AddressJSON: TJSONObject);
var
Response: TXDataClientResponse;
notification: TJSObject;
begin
Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddShippingAddress',
[AddressJSON.ToString]));
notification := TJSObject(Response.Result);
ShowNotification(string(notification['status']));
xdwdsShipTo.Close;
xdwdsShipTo.SetJSONData(notification['ADDRESS']);
xdwdsShipTo.Open;
end;
procedure TFOrderEntryWeb.ShowAddAddressForm;
// displays the search pop-up that allows the user to filter the order list
var
newform: TFViewAddAddress;
AddressJSON: TJSONObject;
ship_block: string;
begin
newform := TFViewAddAddress.CreateNew;
newform.Caption := 'Input Shipping Information';
newForm.Popup := True;
newForm.Border := fbDialog;
// used to manage Back button handling to close subform
window.location.hash := 'subform';
newform.ShowModal(
procedure(AValue: TModalResult)
var
searchOptions: string;
begin
if newform.confirm then
begin
AddressJSON := TJSONObject.Create;
AddressJSON.AddPair('address', newform.edtAddress.Text);
AddressJSON.AddPair('city', newform.edtCity.Text);
AddressJSON.AddPair('state', newform.edtState.Text);
AddressJSON.AddPair('zip', newform.edtZip.Text);
AddressJSON.AddPair('contact', newform.edtContact.Text);
AddressJSON.AddPair('customer_id', customerID);
ship_block := newform.edtFirstLine.Text + slinebreak +
edtCompanyName.Text + slinebreak +
newform.edtContact.Text + slinebreak +
newform.edtAddress.Text + slinebreak +
newform.edtCity.Text + ', ' + newform.edtState.Text + ' ' + newform.edtZip.Text;
AddressJSON.AddPair('ship_block', ship_block);
AddressJSON.AddPair('mode', 'ADD');
sendAddressToServer(AddressJSON);
end;
end
);
end;
procedure TFOrderEntryWeb.btnSaveClick(Sender: TObject);
begin
......
......@@ -735,7 +735,7 @@ end;
procedure TFViewOrders.btnSearchClick(Sender: TObject);
var
filterSection: TJSHTMLElement;
filterSection: TJSHTMLElement;
begin
ShowSearchForm();
end;
......
object FAddOrder: TFAddOrder
Width = 894
Height = 633
Align = alClient
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Style = []
ParentFont = False
object FSelectCustomer: TFSelectCustomer
Width = 765
Height = 480
OnCreate = WebFormCreate
OnShow = WebFormShow
object cbWebPlate: TWebCheckBox
Left = 172
Top = 55
Width = 113
Height = 22
Caption = 'Web Plate'
ChildOrder = 5
HeightStyle = ssAuto
object WebLabel1: TWebLabel
Left = 4
Top = 81
Width = 95
Height = 15
Caption = 'Search Customers'
HeightPercent = 100.000000000000000000
WidthStyle = ssAuto
WidthPercent = 100.000000000000000000
OnClick = cbWebPlateClick
end
object cbCorrugatedPlate: TWebCheckBox
Left = 40
Top = 55
object WebLabel2: TWebLabel
Left = 143
Top = 81
Width = 113
Height = 22
Caption = 'Corrugated Plate'
Checked = True
ChildOrder = 5
HeightStyle = ssAuto
Height = 15
Caption = 'Selected Customer ID'
HeightPercent = 100.000000000000000000
State = cbChecked
WidthStyle = ssAuto
WidthPercent = 100.000000000000000000
OnClick = cbCorrugatedPlateClick
end
object edtSearch: TWebEdit
Left = 306
Top = 55
Width = 146
Left = 4
Top = 102
Width = 121
Height = 22
ChildOrder = 8
HeightStyle = ssAuto
ChildOrder = 2
HeightPercent = 100.000000000000000000
WidthStyle = ssAuto
WidthPercent = 100.000000000000000000
OnChange = edtSearchChange
end
object edtID: TWebEdit
Left = 475
Top = 55
Width = 121
Left = 143
Top = 102
Width = 142
Height = 22
ChildOrder = 8
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
WidthStyle = ssAuto
WidthPercent = 100.000000000000000000
end
object btnConfirm: TWebButton
Left = 612
Top = 52
Width = 96
Height = 25
Caption = 'Confirm'
ChildOrder = 9
HeightStyle = ssAuto
ChildOrder = 1
Enabled = False
HeightPercent = 100.000000000000000000
WidthStyle = ssAuto
WidthPercent = 100.000000000000000000
OnClick = btnConfirmClick
end
object btnCancel: TWebButton
Left = 730
Top = 52
Width = 96
Height = 25
Caption = 'Cancel'
ChildOrder = 9
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
WidthStyle = ssAuto
WidthPercent = 100.000000000000000000
OnClick = btnCancelClick
end
object TMSFNCGrid1: TTMSFNCGrid
Left = 0
Top = 220
Width = 894
Height = 413
Top = 163
Width = 765
Height = 317
Align = alBottom
ParentDoubleBuffered = False
DoubleBuffered = True
TabOrder = 6
TabOrder = 2
DefaultRowHeight = 40.000000000000000000
FixedColumns = 0
ColumnCount = 3
ColumnCount = 4
Options.Bands.Enabled = True
Options.ColumnSize.Stretch = True
Options.Editing.CalcFormat = '%g'
......@@ -121,7 +75,7 @@ object FAddOrder: TFAddOrder
Font.Name = 'Segoe UI'
Font.Style = []
ID = ''
Width = 327.000000000000000000
Width = 90.000000000000000000
end
item
BorderWidth = 1
......@@ -136,7 +90,7 @@ object FAddOrder: TFAddOrder
Font.Name = 'Segoe UI'
Font.Style = []
ID = ''
Width = 327.000000000000000000
Width = 150.000000000000000000
end
item
BorderWidth = 1
......@@ -151,7 +105,37 @@ object FAddOrder: TFAddOrder
Font.Name = 'Segoe UI'
Font.Style = []
ID = ''
Width = 239.000000000000000000
Width = 200.000000000000000000
end
item
BorderWidth = 1
FixedFont.Charset = DEFAULT_CHARSET
FixedFont.Color = 4539717
FixedFont.Height = -11
FixedFont.Name = 'Segoe UI'
FixedFont.Style = [fsBold]
Font.Charset = DEFAULT_CHARSET
Font.Color = 8026746
Font.Height = -11
Font.Name = 'Segoe UI'
Font.Style = []
ID = ''
Width = 306.000000000000000000
end
item
BorderWidth = 1
FixedFont.Charset = DEFAULT_CHARSET
FixedFont.Color = 4539717
FixedFont.Height = -11
FixedFont.Name = 'Segoe UI'
FixedFont.Style = [fsBold]
Font.Charset = DEFAULT_CHARSET
Font.Color = 8026746
Font.Height = -11
Font.Name = 'Segoe UI'
Font.Style = []
ID = ''
Width = 90.000000000000000000
end>
DefaultFont.Charset = DEFAULT_CHARSET
DefaultFont.Color = clWindowText
......@@ -211,30 +195,110 @@ object FAddOrder: TFAddOrder
LeftCol = 0
ScrollMode = scmItemScrolling
DesignTimeSampleData = True
ExplicitWidth = 982
ExplicitLeft = -231
ExplicitTop = 160
ExplicitWidth = 871
end
object cbCorrugatedPlate: TWebCheckBox
Left = 4
Top = 49
Width = 113
Height = 22
Caption = 'Corrugated Plate'
ChildOrder = 3
ElementID = 'cbcorrugatedplate'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object cbWebPlate: TWebCheckBox
Left = 134
Top = 49
Width = 83
Height = 22
Caption = 'Web Plate'
ChildOrder = 3
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object btnCancel: TWebButton
Left = 436
Top = 105
Width = 96
Height = 25
Caption = 'Cancel'
ChildOrder = 5
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object btnConfirm: TWebButton
Left = 328
Top = 105
Width = 96
Height = 25
Caption = 'Select'
ChildOrder = 5
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object cbCuttingDie: TWebCheckBox
Left = 239
Top = 49
Width = 83
Height = 22
Caption = 'Cutting Die'
ChildOrder = 3
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object edtNotification: TWebEdit
Left = 4
Top = 16
Width = 510
Height = 22
HelpType = htKeyword
TabStop = False
ChildOrder = 8
ElementFont = efCSS
Enabled = False
Font.Charset = ANSI_CHARSET
Font.Color = clRed
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
HeightPercent = 100.000000000000000000
HideSelection = False
ParentFont = False
TabOrder = 1
WidthPercent = 100.000000000000000000
end
object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection
Left = 370
Top = 562
Left = 560
Top = 61
end
object xdwdsCustomers: TXDataWebDataSet
Connection = DMConnection.ApiConnection
Left = 206
Top = 564
object xdwdsCustomersID: TIntegerField
FieldName = 'ID'
Left = 70
Top = 129
object xdwdsCustomersBillAddr: TStringField
FieldName = 'BillAddr'
end
object xdwdsCustomersCompanyName: TStringField
FieldName = 'CompanyName'
end
object xdwdsCustomersId: TStringField
FieldName = 'Id'
end
object xdwdsCustomersNAME: TStringField
FieldName = 'NAME'
object xdwdsCustomersPrimaryPhone: TStringField
FieldName = 'PrimaryPhone'
end
object xdwdsCustomersSHORT_NAME: TStringField
FieldName = 'SHORT_NAME'
object xdwdsCustomersShipAddr: TStringField
FieldName = 'ShipAddr'
end
end
object wdsCustomers: TWebDataSource
DataSet = xdwdsCustomers
Left = 38
Top = 562
Left = 18
Top = 127
end
end
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>TMS Web Project</title>
<style>
</style>
</head>
<body>
</body>
</html>
\ No newline at end of file
unit View.SelectCustomer;
interface
uses
System.SysUtils, System.Generics.Collections, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, WEBLib.Menus, WEBLib.ExtCtrls, WEBLib.StdCtrls,
WEBLib.JSON, Auth.Service, XData.Web.Client, WebLib.Storage,
ConnectionModule, App.Types, Vcl.StdCtrls, Vcl.Controls, WEBLib.DBCtrls,
Data.DB, XData.Web.JsonDataset, XData.Web.Dataset, WEBLib.DB, VCL.TMSFNCTypes, VCL.TMSFNCUtils,
VCL.TMSFNCGraphics, VCL.TMSFNCGraphicsTypes, VCL.TMSFNCGridCell,
VCL.TMSFNCGridOptions, VCL.TMSFNCCustomControl, VCL.TMSFNCCustomScrollControl,
VCL.TMSFNCGridData, VCL.TMSFNCCustomGrid, VCL.TMSFNCGrid;
type
TFSelectCustomer = class(TWebForm)
WebLabel1: TWebLabel;
WebLabel2: TWebLabel;
edtSearch: TWebEdit;
edtID: TWebEdit;
TMSFNCGrid1: TTMSFNCGrid;
cbCorrugatedPlate: TWebCheckBox;
cbWebPlate: TWebCheckBox;
btnCancel: TWebButton;
btnConfirm: TWebButton;
cbCuttingDie: TWebCheckBox;
edtNotification: TWebEdit;
XDataWebClient1: TXDataWebClient;
xdwdsCustomers: TXDataWebDataSet;
wdsCustomers: TWebDataSource;
xdwdsCustomersBillAddr: TStringField;
xdwdsCustomersCompanyName: TStringField;
xdwdsCustomersId: TStringField;
xdwdsCustomersPrimaryPhone: TStringField;
xdwdsCustomersShipAddr: TStringField;
procedure WebFormCreate(Sender: TObject);
procedure WebFormShow(Sender: TObject);
private
{ Private declarations }
[Async] procedure GetCustomers();
procedure PopulateGridManually();
public
{ Public declarations }
end;
var
FSelectCustomer: TFSelectCustomer;
implementation
{$R *.dfm
}
procedure TFSelectCustomer.WebFormCreate(Sender: TObject);
begin
if not DMConnection.ApiConnection.Connected then
begin
DMConnection.ApiConnection.OpenAsync;
console.log('report requirements connection open')
end;
end;
procedure TFSelectCustomer.WebFormShow(Sender: TObject);
begin
getCustomers();
end;
[async] procedure TFSelectCustomer.getCustomers();
// retrieves customer list from server
var
xdcResponse: TXDataClientResponse;
customerList: TJSObject;
i: integer;
begin
// Fetch data from XData service
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.getQBCustomers', []));
customerList := TJSObject(xdcResponse.Result);
//console.log(customerList);
// Load data into TXDataWebDataset
xdwdsCustomers.Close;
xdwdsCustomers.SetJsonData(customerList);
xdwdsCustomers.Open;
console.log(customerList);
// Manually populate the grid
PopulateGridManually;
end;
procedure TFSelectCustomer.PopulateGridManually;
// populates the grid with customers manually.
var
RowIndex: Integer;
begin
TMSFNCGrid1.BeginUpdate;
try
TMSFNCGrid1.Clear; // Clear any existing data
// Set up column headers
TMSFNCGrid1.ColumnCount := 4;
TMSFNCGrid1.RowCount := 1;
TMSFNCGrid1.Cells[0, 0] := 'Quickbooks ID';
TMSFNCGrid1.Cells[1, 0] := 'Customer ID';
TMSFNCGrid1.Cells[2, 0] := 'Customer Name';
TMSFNCGrid1.Cells[3, 0] := 'Address';
// Populate the grid with data from the dataset
xdwdsCustomers.First;
RowIndex := 1;
while not xdwdsCustomers.EOF do
begin
TMSFNCGrid1.RowCount := RowIndex + 1;
TMSFNCGrid1.Cells[0, RowIndex] := xdwdsCustomers.FieldByName('Id').AsString;
// TMSFNCGrid1.Cells[1, RowIndex] := xdwdsCustomers.FieldByName('SHORT_NAME').AsString;
TMSFNCGrid1.Cells[2, RowIndex] := xdwdsCustomers.FieldByName('CompanyName').AsString;
TMSFNCGrid1.Cells[3, RowIndex] := xdwdsCustomers.FieldByName('BillAddr').AsString;
Inc(RowIndex);
xdwdsCustomers.Next;
end;
finally
TMSFNCGrid1.EndUpdate;
end;
end;
end.
\ No newline at end of file
......@@ -28,7 +28,6 @@
<th scope="col">Email Address</th>
<th scope="col">Access Type</th>
<th scope="col">System Rights</th>
<th scope="col">Perspective ID</th>
<th scope="col">QB ID</th>
<th scope="col">Edit</th>
</tr>
......
......@@ -433,12 +433,6 @@ begin
Cell.innerText := IntToStr(Rights);
NewRow.appendChild(Cell);
// Perspective ID Cell
Cell := TJSHTMLElement(document.createElement('td'));
Cell.setAttribute('data-label', 'Perspective ID');
Cell.innerText := PID;
NewRow.appendChild(Cell);
// QB ID Cell
Cell := TJSHTMLElement(document.createElement('td'));
Cell.setAttribute('data-label', 'QB ID');
......
program webKGOrders;
uses
......@@ -25,7 +26,9 @@ uses
View.OrderEntryCuttingDie in 'View.OrderEntryCuttingDie.pas' {FOrderEntryCuttingDie: TWebForm} {*.html},
View.OrderEntryWeb in 'View.OrderEntryWeb.pas' {FOrderEntryWeb: TWebForm} {*.html},
View.Customers in 'View.Customers.pas' {FViewCustomers: TWebForm} {*.html},
AddCustomer in 'AddCustomer.pas' {FViewAddCustomer: TWebForm} {*.html};
AddCustomer in 'AddCustomer.pas' {FViewAddCustomer: TWebForm} {*.html},
View.AddAddress in 'View.AddAddress.pas' {FViewAddAddress: TWebForm} {*.html},
View.SelectCustomer in 'View.SelectCustomer.pas' {FSelectCustomer: TWebForm} {*.html};
{$R *.res}
......
......@@ -196,6 +196,16 @@
<FormType>dfm</FormType>
<DesignClass>TWebForm</DesignClass>
</DCCReference>
<DCCReference Include="View.AddAddress.pas">
<Form>FViewAddAddress</Form>
<FormType>dfm</FormType>
<DesignClass>TWebForm</DesignClass>
</DCCReference>
<DCCReference Include="View.SelectCustomer.pas">
<Form>FSelectCustomer</Form>
<FormType>dfm</FormType>
<DesignClass>TWebForm</DesignClass>
</DCCReference>
<None Include="index.html"/>
<None Include="css\app.css"/>
<None Include="config\config.json"/>
......
unit QBService;
interface
uses
XData.Service.Common,
Aurelius.Mapping.Attributes,
System.JSON,
System.Generics.Collections,
System.Classes;
type
[ServiceContract]
IQBService = interface(IInvokable)
['{D119A273-0644-484B-B75E-B6FE57BB422C}']
[HttpGet] function getCustomers(): TJSONArray;
end;
implementation
initialization
RegisterServiceType(TypeInfo(IQBService));
end.
unit QBServiceImplementation;
interface
uses
XData.Server.Module,
XData.Service.Common,
Api.Database, Data.DB, frxClass, frxExportPDF, JS, System.Hash, System.JSON,
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, MemDS, DBAccess, Uni,
hyiedefs, hyieutils, iexBitmaps, iesettings, iexLayers, iexRulers,
iexToolbars, iexUserInteractions, imageenio, imageenproc, QuickRpt, QRCtrls,
dbimageen, Vcl.ExtCtrls, ieview, imageenview, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdFTP,
iexProcEffects, frCoreClasses, Common.Logging,
DateUtils, QBService, WEBLib.REST, WEBLib.WebTools,System.Net.HttpClient,
System.Net.URLClient, System.Net.HttpClientComponent, System.netencoding,
IdHTTP, IdSSLOpenSSL, IdSSLOpenSSLHeaders, System.IniFiles, REST.Client, REST.Types;
type
[ServiceImplementation]
TQBService = class(TInterfacedObject, IQBService)
private
procedure SaveTokens(AccessToken, RefreshToken: string);
function getCustomers(): TJSONArray;
function refreshAccessToken(): string;
var
AccessToken,RefreshToken,CompanyID,Client,Secret: string;
LastRefresh: TDateTime;
end;
implementation
function TQBService.getCustomers: TJSONArray;
var
restClient: TRESTClient;
restRequest: TRESTRequest;
restResponse: TRESTResponse;
param: TRESTRequestParameter;
res: string;
jsValue: TJSONValue;
Customer: TJSONValue;
jsObj: TJSONObject;
CustomerList: TJSONArray;
pair: TJSONPair;
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;
//GET /v3/company/<realmId>/customer/<customerId>
res := '/v3/company/' + companyid + '/customer/58';
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);
CustomerList := TJSONArray( TJSONObject( jsObj.GetValue('QueryResponse') ).GetValue('Customer')) ;
result := CustomerList;
// LoadJSONArray( CustomerList );
restClient.Free;
restRequest.Free;
restResponse.Free;
end;
function TQBService.RefreshAccessToken: string;
// Refresh Token changes so make sure to save refresh token.
var
IdHTTP: TIdHTTP;
SSLIO: TIdSSLIOHandlerSocketOpenSSL;
RequestStream: TStringStream;
EncodedAuth, EncodedAuth2, PostData, response: string;
f: TStringList;
fi: string;
JSObj: TJSONObject;
iniFile: TIniFile;
Encoder: TBase64Encoding;
begin
// 1. Encode credentials (same as working Postman request)
// TNetEncoding.Base64.Encode adds a new line every 72 chars, this stops that
Encoder := TBase64Encoding.Create(0);
if( (Client = '') or (Secret = '') ) then
begin
Logger.Log(1, 'Missing Client ID or Client Secret in INI File');
Exit();
end;
EncodedAuth := Encoder.Encode(Client + ':' + Secret);
if RefreshToken = '' then
begin
Logger.Log(3, 'Missing Refresh Token, Please Manually Get a New One and Store in INI File');
Exit();
end;
// 2. Prepare POST data (EXACTLY as in Postman)
PostData := 'grant_type=refresh_token&refresh_token=' + RefreshToken;
// 3. Configure HTTP client
IdHTTP := TIdHTTP.Create(nil);
SSLIO := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
try
// Force TLS 1.2
SSLIO.SSLOptions.Method := sslvTLSv1_2;
SSLIO.SSLOptions.SSLVersions := [sslvTLSv1_2];
IdHTTP.IOHandler := SSLIO;
// Set headers (EXACT match with Postman)
IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP.Request.Accept := 'application/json';
IdHTTP.Request.CustomHeaders.AddValue('Authorization', 'Basic ' + EncodedAuth);
// 4. Create and send request
RequestStream := TStringStream.Create(PostData, TEncoding.UTF8);
try
// Execute POST
try
response := IdHTTP.Post('https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer', RequestStream);
JSObj := TJSONObject.ParseJSONValue(response) as TJSONObject;
RefreshToken := JSObj.GetValue('refresh_token').ToString.Trim(['"']);
AccessToken := JSObj.GetValue('access_token').ToString.Trim(['"']);
SaveTokens(AccessToken, RefreshToken);
Result := AccessToken;
Logger.Log(1, 'qbAPI - Tokens Successfully Saved');
except
on E: EIdHTTPProtocolException do
// Memo2.Lines.Add('Error: ' + E.Message + #13#10 + 'Response: ' + E.ErrorMessage);
end;
finally
RequestStream.Free;
end;
finally
SSLIO.Free;
IdHTTP.Free;
end;
end;
procedure TQBService.SaveTokens(AccessToken, RefreshToken: string);
var
f: TStringList;
iniStr, line: string;
iniFile: TIniFile;
begin
iniFile := TIniFile.Create( ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini' );
try
iniFile.WriteString('Quickbooks', 'RefreshToken', RefreshToken);
LastRefresh := Now;
Logger.Log(1, 'Tokens Successfully Saved');
finally
IniFile.Free;
end;
f := TStringList.Create;
// Save to file (overwrites existing file)
f.SaveToFile('QB.txt');
f.Free;
end;
initialization
RegisterServiceType(TQBService);
end.
......@@ -132,10 +132,11 @@ type
START_DATE: String;
END_DATE: string;
QB_LIST_ID: string;
FAX: string;
FFAX: string;
REP_USER_ID: string;
ADDRESS_LIST: TList<TAddressItem>;
ITEMS: TItemList;
USERS: TList<TUserItem>
end;
TCustomerList = class
......@@ -392,6 +393,7 @@ type
[HttpGet] function GenerateOrderCorrugatedPDF(orderID: string): string;
[HttpGet] function GenerateOrderWebPDF(orderID: string): string;
[HttpGet] function GenerateOrderCuttingPDF(orderID: string): string;
[HttpGet] function getQBCustomers(): TJSONArray;
function AddUser(userInfo: string): string;
......
......@@ -205,4 +205,13 @@ object fQB: TfQB
TabOrder = 5
OnClick = Button3Click
end
object Button4: TButton
Left = 460
Top = 18
Width = 95
Height = 25
Caption = 'Add Estimate'
TabOrder = 6
OnClick = Button4Click
end
end
......@@ -22,10 +22,12 @@ type
Button2: TButton;
asgData: TAdvStringGrid;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
httpReqTokenRefresh: TWebHttpRequest;
......@@ -88,7 +90,7 @@ begin
end;
procedure TfQB.Button3Click(Sender: TObject);
var
var
restClient: TRESTClient;
restRequest: TRESTRequest;
restResponse: TRESTResponse;
......@@ -146,7 +148,7 @@ begin
end;
procedure TfQB.getCustomers();
procedure TfQB.Button4Click(Sender: TObject);
var
restClient: TRESTClient;
restRequest: TRESTRequest;
......@@ -158,7 +160,9 @@ var
jsObj: TJSONObject;
CustomerList: TJSONArray;
pair: TJSONPair;
estimateJSON: TJSONObject;
begin
///v3/company/<realmID>/estimate
restClient := TRESTClient.Create(nil);
restClient.BaseURL := 'https://sandbox-quickbooks.api.intuit.com';
......@@ -174,12 +178,9 @@ begin
RefreshAccessToken();
end;
restRequest.Method := rmGET;
//res := '/v3/company/' + companyID + '/preferences';
res := '/v3/company/' + companyID + '/query?query=select * from Customer where CompanyName = ' + quotedStr('TYOGA CONTAINER') + '&minorversion=75'; // '/customer/58';
restRequest.Method := rmPOST;
res := '/v3/company/' + companyID + '/estimate';
restRequest.Resource := res;
///query?query=select * from Customer where CompanyName = ' + quotedStr('TYOGA CONTAINER') + '&minorversion=75';
param := restRequest.Params.AddItem;
param.Name := 'Authorization';
......@@ -205,6 +206,101 @@ begin
restClient.Free;
restRequest.Free;
restResponse.Free;
end;
procedure TfQB.getCustomers();
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;
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);
{Memo2.Lines.Add(res);
Memo2.Lines.Add( jsObj.Format(2) ); }
//CustomerList := TJSONArray(restResponse.JSONValue);
CustomerList := TJSONArray( TJSONObject( jsObj.GetValue('QueryResponse') ).GetValue('Customer')) ;
ModifiedList := TJSONArray.Create;
for I := 0 to CustomerList.Count - 1 do
begin
Customer := CustomerList.Items[I] as TJSONObject;
ParsedCustomer := TJSONObject.Create;
try
// Directly add values without cloning
ParsedCustomer.AddPair('id', Customer.GetValue('Id'));
ParsedCustomer.AddPair('name', Customer.GetValue('DisplayName'));
if Customer.GetValue('BillAddr') <> nil then
begin
BillAddr := Customer.GetValue('BillAddr') as TJSONObject;
ParsedCustomer.AddPair('BillAddr_line1', BillAddr.GetValue('Line1', ''));
ParsedCustomer.AddPair('BillAddr_City', BillAddr.GetValue('City', ''));
ParsedCustomer.AddPair('BillAddr_State', BillAddr.GetValue('CountrySubDivisionCode', ''));
ParsedCustomer.AddPair('BillAddr_Zip', BillAddr.GetValue('PostalCode', ''));
ParsedCustomer.AddPair('BillAddr', BillAddr.GetValue('Line1', '') + ', '
+ BillAddr.GetValue('City', '') + ', '
+ BillAddr.GetValue('CountrySubDivisionCode', '') + ' '
+ BillAddr.GetValue('PostalCode', '') );
end;
except
ParsedCustomer.Free;
raise;
end;
end;
LoadJSONArray( ModifiedList );
restClient.Free;
restRequest.Free;
restResponse.Free;
end;
......
......@@ -26,7 +26,9 @@ uses
rOrderCorrugated in 'Source\rOrderCorrugated.pas' {rptOrderCorrugated: TDataModule},
rOrderWeb in 'Source\rOrderWeb.pas' {rptOrderWeb: TDataModule},
rOrderCutting in 'Source\rOrderCutting.pas' {rptOrderCutting: TDataModule},
qbAPI in 'Source\qbAPI.pas' {fQB};
qbAPI in 'Source\qbAPI.pas' {fQB},
QBService in 'QBService.pas',
QBServiceImplementation in 'QBServiceImplementation.pas';
type
TMemoLogAppender = class( TInterfacedObject, ILogAppender )
......
......@@ -201,6 +201,8 @@
<Form>fQB</Form>
<FormType>dfm</FormType>
</DCCReference>
<DCCReference Include="QBService.pas"/>
<DCCReference Include="QBServiceImplementation.pas"/>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
......
......@@ -2,7 +2,7 @@
MemoLogLevel=3
FileLogLevel=5
webClientVersion=0.9.2
LogFileNum=555
LogFileNum=591
[Database]
Server=192.168.159.131
......@@ -17,5 +17,6 @@ Password=emsys01
CompanyID=9341454272655710
ClientID=ABgO14uvjh8XqLud7spQ8lkb98AUpcdA7HbyMJfCAtl65sQ5yy
ClientSecret=bQ06TRemHeAGFzVHRaTUvUoBU9jpU9itK6MOMgqN
RefreshToken=RT1-86-H0-17551964757vq6lk1eu183mmu09c1o
RefreshToken=RT1-25-H0-1756568183wceqmvmfoz1ccfcr1fcq
AccessToken=eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwieC5vcmciOiJIMCJ9..oXhfeeG4jA22E97aNL7zcg.ie7-Ny9UQ8NuozYWGP5YLDk1KZqrMc8U1qD4hQWBV7-J4To2zk1CBvp3of53lbQTqH2tUu8QoMAwJy7RkuwQ9-Y3PmPesu_LxgGTW-6b2K-W5fUSat03C62ExFr1e1RLgaQGcnJSJOVUyGP3DlwwmKk0YyHMeWkSwkKNYVpdgnUpOHFzXBDbYlF0vI6M6oY6PwEooEWK-K6TCo6tW_AhqxBiMAW4CDPvEKw1iGlrwJDouemK-ttd4PL2-mNaKcpAL6KWT8qeIIgHNySf3Y3Kd5EVmlp6v_NaHu4cYidmIsk1FhKlPRLoiCZoK4Rm0WA3OWKu55_T4rbbqUf6ZpLZZMzZfnzQPslZxV8N6L0fqyik6u4arkY1oCIOvM0TyCyRxP-mdd0rDyEOvrOusehoTrtVi-DG0C8t2rdYxsm8bVAWQew_S77-aWq_y8MQGaQ1TY9gtlTmIeVPLfK6wPZ4jZ3jiC6Yc4SQsIosz_hC5qE.YIBYv0DUUeO2d_6s6SiIOA
LastRefresh=5/21/2025 11:39:37 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