Commit 84caa500 by Mac Stephens

Merged to test - checking try except on add items

parents bd2cab6e 284ccb7b
object fViewAddItem: TfViewAddItem
Width = 640
Height = 480
OnCreate = WebFormCreate
OnShow = WebFormShow
object WebLabel1: TWebLabel
Left = 8
Top = 81
Width = 95
Height = 15
Caption = 'Search Customers'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object WebLabel3: TWebLabel
Left = 131
Top = 81
Width = 137
Height = 15
Caption = 'Selected Quickbooks Item'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object edtSearch: TWebEdit
Left = 4
Top = 102
Width = 121
Height = 22
ChildOrder = 2
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object TMSFNCGrid1: TTMSFNCGrid
Left = 0
Top = 163
Width = 640
Height = 317
Align = alBottom
ParentDoubleBuffered = False
DoubleBuffered = True
TabOrder = 1
DefaultRowHeight = 40.000000000000000000
FixedColumns = 0
ColumnCount = 4
Options.Bands.Enabled = True
Options.ColumnSize.Stretch = True
Options.Editing.CalcFormat = '%g'
Options.Grouping.CalcFormat = '%g'
Options.Grouping.GroupCountFormat = '(%d)'
Options.IO.XMLEncoding = 'ISO-8859-1'
Options.Mouse.ClickMargin = 0
Options.Mouse.ColumnSizeMargin = 6
Options.Mouse.RowSizeMargin = 6
Columns = <
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
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 = 150.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 = 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 = 181.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
DefaultFont.Height = -11
DefaultFont.Name = 'Segoe UI'
DefaultFont.Style = []
TopRow = 1
Appearance.FixedLayout.Fill.Color = 16380654
Appearance.FixedLayout.Font.Charset = DEFAULT_CHARSET
Appearance.FixedLayout.Font.Color = 4539717
Appearance.FixedLayout.Font.Height = -13
Appearance.FixedLayout.Font.Name = 'Segoe UI'
Appearance.FixedLayout.Font.Style = [fsBold]
Appearance.NormalLayout.Fill.Color = 16578806
Appearance.NormalLayout.Font.Charset = DEFAULT_CHARSET
Appearance.NormalLayout.Font.Color = 8026746
Appearance.NormalLayout.Font.Height = -11
Appearance.NormalLayout.Font.Name = 'Segoe UI'
Appearance.NormalLayout.Font.Style = []
Appearance.GroupLayout.Fill.Color = 12817262
Appearance.GroupLayout.Font.Charset = DEFAULT_CHARSET
Appearance.GroupLayout.Font.Color = clBlack
Appearance.GroupLayout.Font.Height = -11
Appearance.GroupLayout.Font.Name = 'Segoe UI'
Appearance.GroupLayout.Font.Style = []
Appearance.SummaryLayout.Fill.Color = 14009785
Appearance.SummaryLayout.Font.Charset = DEFAULT_CHARSET
Appearance.SummaryLayout.Font.Color = clBlack
Appearance.SummaryLayout.Font.Height = -11
Appearance.SummaryLayout.Font.Name = 'Segoe UI'
Appearance.SummaryLayout.Font.Style = []
Appearance.SelectedLayout.Fill.Color = 16441019
Appearance.SelectedLayout.Font.Charset = DEFAULT_CHARSET
Appearance.SelectedLayout.Font.Color = 4539717
Appearance.SelectedLayout.Font.Height = -11
Appearance.SelectedLayout.Font.Name = 'Segoe UI'
Appearance.SelectedLayout.Font.Style = []
Appearance.FocusedLayout.Fill.Color = 16039284
Appearance.FocusedLayout.Font.Charset = DEFAULT_CHARSET
Appearance.FocusedLayout.Font.Color = 4539717
Appearance.FocusedLayout.Font.Height = -11
Appearance.FocusedLayout.Font.Name = 'Segoe UI'
Appearance.FocusedLayout.Font.Style = []
Appearance.FixedSelectedLayout.Fill.Color = clLightsteelblue
Appearance.FixedSelectedLayout.Font.Charset = DEFAULT_CHARSET
Appearance.FixedSelectedLayout.Font.Color = clBlack
Appearance.FixedSelectedLayout.Font.Height = -11
Appearance.FixedSelectedLayout.Font.Name = 'Segoe UI'
Appearance.FixedSelectedLayout.Font.Style = []
Appearance.BandLayout.Fill.Color = 16711679
Appearance.BandLayout.Font.Charset = DEFAULT_CHARSET
Appearance.BandLayout.Font.Color = 8026746
Appearance.BandLayout.Font.Height = -11
Appearance.BandLayout.Font.Name = 'Segoe UI'
Appearance.BandLayout.Font.Style = []
Appearance.ProgressLayout.Format = '%.0f%%'
LeftCol = 0
ScrollMode = scmItemScrolling
DesignTimeSampleData = True
OnCellClick = TMSFNCGrid1CellClick
ExplicitLeft = -125
ExplicitWidth = 765
end
object btnCancel: TWebButton
Left = 544
Top = 101
Width = 96
Height = 25
Caption = 'Cancel'
ChildOrder = 5
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object btnConfirm: TWebButton
Left = 446
Top = 101
Width = 96
Height = 25
Caption = 'Select'
ChildOrder = 5
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = btnConfirmClick
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 edtName: TWebEdit
Left = 131
Top = 102
Width = 142
Height = 22
ChildOrder = 1
Enabled = False
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection
Left = 612
Top = 47
end
object xdwdsCustomers: TXDataWebDataSet
Connection = DMConnection.ApiConnection
Left = 166
Top = 129
object xdwdsCustomersqb_items_id: TStringField
FieldName = 'qb_items_id'
end
object xdwdsCustomersqb_item_name: TStringField
FieldName = 'qb_item_name'
end
object xdwdsCustomersitem_desc: TStringField
FieldName = 'item_desc'
end
object xdwdsCustomersstatus: TStringField
FieldName = 'status'
end
end
object wdsCustomers: TWebDataSource
DataSet = xdwdsCustomers
Left = 104
Top = 135
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.AddItem;
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
TfViewAddItem = class(TWebForm)
WebLabel1: TWebLabel;
WebLabel3: TWebLabel;
edtSearch: TWebEdit;
TMSFNCGrid1: TTMSFNCGrid;
btnCancel: TWebButton;
btnConfirm: TWebButton;
edtNotification: TWebEdit;
edtName: TWebEdit;
XDataWebClient1: TXDataWebClient;
xdwdsCustomers: TXDataWebDataSet;
wdsCustomers: TWebDataSource;
xdwdsCustomersqb_items_id: TStringField;
xdwdsCustomersqb_item_name: TStringField;
xdwdsCustomersitem_desc: TStringField;
xdwdsCustomersstatus: TStringField;
procedure WebFormCreate(Sender: TObject);
procedure WebFormShow(Sender: TObject);
procedure TMSFNCGrid1CellClick(Sender: TObject; ACol, ARow: Integer);
procedure btnConfirmClick(Sender: TObject);
private
{ Private declarations }
[async] procedure getItems();
procedure PopulateGridManually();
[async] procedure SendItemToServer();
public
{ Public declarations }
notification: string;
end;
var
fViewAddItem: TfViewAddItem;
implementation
{$R *.dfm}
procedure TfViewAddItem.WebFormCreate(Sender: TObject);
begin
if not DMConnection.ApiConnection.Connected then
begin
DMConnection.ApiConnection.OpenAsync;
console.log('report requirements connection open')
end;
end;
procedure TfViewAddItem.WebFormShow(Sender: TObject);
begin
//Utils.ShowSpinner('spinner');
getItems();
end;
procedure TfViewAddItem.btnConfirmClick(Sender: TObject);
begin
xdwdsCustomers.Locate('qb_item_name', edtName.Text, []);
if edtName.Text = '' then
edtNotification.Text := 'Please Select a Customer'
else if xdwdsCustomers.FieldByName('qb_items_id').AsString <> '' then
edtNotification.Text := 'Customer Already In Database'
else
SendItemToServer();
end;
procedure TfViewAddItem.getItems;
var
xdcResponse: TXDataClientResponse;
customerList: TJSObject;
i: integer;
begin
// Fetch data from XData service
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.getQBItems', []));
customerList := TJSObject(xdcResponse.Result);
// Load data into TXDataWebDataset
xdwdsCustomers.Close;
xdwdsCustomers.SetJsonData(customerList);
xdwdsCustomers.Open;
// Manually populate the grid
PopulateGridManually;
//Utils.HideSpinner('spinner');
end;
procedure TFViewAddItem.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] := 'KGOrders ID';
TMSFNCGrid1.Cells[1, 0] := 'Item Name';
TMSFNCGrid1.Cells[2, 0] := 'Item Description';
TMSFNCGrid1.Cells[3, 0] := 'Status';
// 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('qb_items_id').AsString;
TMSFNCGrid1.Cells[1, RowIndex] := xdwdsCustomers.FieldByName('qb_item_name').AsString;
TMSFNCGrid1.Cells[2, RowIndex] := xdwdsCustomers.FieldByName('item_desc').AsString;
TMSFNCGrid1.Cells[3, RowIndex] := xdwdsCustomers.FieldByName('status').AsString;
Inc(RowIndex);
xdwdsCustomers.Next;
end;
finally
TMSFNCGrid1.EndUpdate;
end;
end;
procedure TfViewAddItem.TMSFNCGrid1CellClick(Sender: TObject; ACol,
ARow: Integer);
begin
edtName.Text := TMSFNCGrid1.Cells[1, ARow];
end;
procedure TFViewAddItem.SendItemToServer;
var
ItemJSON: TJSONObject;
Response: TXDataClientResponse;
jsObj: TJSObject;
begin
ItemJSON := TJSONObject.Create;
ItemJSON.AddPair('qb_item_name', xdwdsCustomers.FieldByName('qb_item_name').AsString);
ItemJSON.AddPair('item_desc', xdwdsCustomers.FieldByName('item_desc').AsString);
ItemJSON.AddPair('status', xdwdsCustomers.FieldByName('status').AsString);
ItemJSON.AddPair('mode', 'ADD');
// Utils.ShowSpinner('spinner');
Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddItem',
[ItemJSON.ToString]));
jsObj := TJSObject(Response.Result);
notification := string(jsObj['msg']);
// Utils.HideSpinner('spinner');
Close();
end;
end.
\ No newline at end of file
...@@ -41,20 +41,20 @@ object FViewItems: TFViewItems ...@@ -41,20 +41,20 @@ object FViewItems: TFViewItems
'25' '25'
'50') '50')
end end
object btnApply: TWebButton object btnAdd: TWebButton
Left = 478 Left = 565
Top = 128 Top = 318
Width = 96 Width = 96
Height = 25 Height = 25
Caption = 'Apply' Caption = 'Add'
ChildOrder = 7 ChildOrder = 7
ElementClassName = 'btn btn-light' ElementClassName = 'btn btn-light'
ElementID = 'btnapply' ElementID = 'btnadd'
ElementFont = efCSS ElementFont = efCSS
HeightStyle = ssAuto HeightStyle = ssAuto
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
OnClick = btnApplyClick OnClick = btnAddClick
end end
object edtName: TWebEdit object edtName: TWebEdit
Left = 342 Left = 342
...@@ -97,6 +97,114 @@ object FViewItems: TFViewItems ...@@ -97,6 +97,114 @@ object FViewItems: TFViewItems
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
end end
object pnlMessage: TWebPanel
Left = 0
Top = 27
Width = 121
Height = 33
ElementClassName = 'card'
ElementID = 'view.login.message'
ChildOrder = 5
ElementBodyClassName = 'card-body'
ElementFont = efCSS
ElementPosition = epRelative
Role = 'null'
TabOrder = 5
object lblMessage: TWebLabel
Left = 28
Top = 9
Width = 42
Height = 13
Caption = 'Message'
ElementID = 'view.login.message.label'
ElementFont = efCSS
ElementPosition = epRelative
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object btnCloseNotification: TWebButton
Left = 96
Top = 3
Width = 22
Height = 25
ChildOrder = 1
ElementClassName = 'btn btn-light'
ElementID = 'view.login.message.button'
ElementFont = efCSS
ElementPosition = epRelative
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
Role = 'null'
WidthStyle = ssAuto
WidthPercent = 100.000000000000000000
OnClick = btnCloseNotificationClick
end
end
object btnSave: TWebButton
Left = 565
Top = 228
Width = 96
Height = 25
Caption = 'Save'
ChildOrder = 79
ElementClassName = 'btn btn-light'
ElementID = 'btnconfirm'
ElementFont = efCSS
ElementPosition = epRelative
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
Role = 'null'
WidthPercent = 100.000000000000000000
OnClick = btnSaveClick
end
object btnCancel: TWebButton
Left = 565
Top = 259
Width = 96
Height = 25
Caption = 'Cancel'
ChildOrder = 79
ElementClassName = 'btn btn-light'
ElementID = 'btncancel'
ElementFont = efCSS
ElementPosition = epRelative
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
Role = 'null'
WidthPercent = 100.000000000000000000
OnClick = btnCancelClick
end
object btnDelete: TWebButton
Left = 565
Top = 197
Width = 96
Height = 25
Caption = 'Delete'
ChildOrder = 79
ElementClassName = 'btn btn-light'
ElementID = 'btndelete'
ElementFont = efCSS
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = btnDeleteClick
end
object btnEdit: TWebButton
Left = 565
Top = 287
Width = 96
Height = 25
Caption = 'Edit'
ChildOrder = 83
ElementClassName = 'btn btn-light'
ElementID = 'btnedit'
ElementFont = efCSS
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = btnEditClick
end
object XDataWebClient1: TXDataWebClient object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection Connection = DMConnection.ApiConnection
Left = 426 Left = 426
......
<nav class="navbar navbar-expand navbar-light bg-light sticky-top" style="z-index: 100;">
<div class="container-fluid ps-0">
<div id="view.login.message" class="alert alert-danger"
style="padding: 0.25rem 0.5rem; font-size: 0.875rem; line-height: 1.5; display: flex; align-items: center; margin: 0 0 0 60px; height: 32px; width: 400px;">
<button id="view.login.message.button" type="button" class="btn-close" aria-label="Close"></button>
<span id="view.login.message.label"></span>
</div>
<ul class="navbar-nav me-auto ps-2">
<li class="nav-item pe-2">
<button id="btnadd" class="btn btn-primary btn-sm">Add</button>
</li>
<li class="nav-item pe-2">
<button id="btnedit" class="btn btn-primary btn-sm">Edit</button>
</li>
<li class="nav-item pe-2">
<button id="btndelete" class="btn btn-danger btn-sm">Delete</button>
</li>
<li class="nav-item pe-2">
<button id="btnconfirm" class="btn btn-success btn-sm">Save</button>
</li>
<li class="nav-item pe-2">
<button id="btncancel" class="btn btn-danger btn-sm">Cancel</button>
</li>
<li class="nav-item">
<button id="btnclose" class="btn btn-primary btn-sm">Close</button>
</li>
</ul>
</div>
</nav>
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<div class="container mt-4"> <div class="container mt-4">
...@@ -30,9 +59,6 @@ ...@@ -30,9 +59,6 @@
<div class="col-sm-5"> <div class="col-sm-5">
<label class="py-2" style="font-weight: 700;">Show <select class="custom-select" id="wcbpagesize" style="font-size: 1.00rem;"></select> entries</label> <label class="py-2" style="font-weight: 700;">Show <select class="custom-select" id="wcbpagesize" style="font-size: 1.00rem;"></select> entries</label>
</div> </div>
<div class="col-sm-5">
<button class= "ps-3" id="btnapply"></button>
</div>
</div> </div>
</form> </form>
......
...@@ -20,21 +20,36 @@ type ...@@ -20,21 +20,36 @@ type
XDataWebDataSet1: TXDataWebDataSet; XDataWebDataSet1: TXDataWebDataSet;
lblEntries: TWebLabel; lblEntries: TWebLabel;
wcbPageSize: TWebComboBox; wcbPageSize: TWebComboBox;
btnApply: TWebButton; btnAdd: TWebButton;
edtName: TWebEdit; edtName: TWebEdit;
edtDescription: TWebEdit; edtDescription: TWebEdit;
cbStatus: TWebCheckBox; cbStatus: TWebCheckBox;
pnlMessage: TWebPanel;
lblMessage: TWebLabel;
btnCloseNotification: TWebButton;
btnSave: TWebButton;
btnCancel: TWebButton;
btnDelete: TWebButton;
btnEdit: TWebButton;
procedure WebFormCreate(Sender: TObject); procedure WebFormCreate(Sender: TObject);
procedure btnApplyClick(Sender: TObject); procedure btnAddClick(Sender: TObject);
procedure wcbPageSizeChange(Sender: TObject); procedure wcbPageSizeChange(Sender: TObject);
procedure btnCloseNotificationClick(Sender: TObject);
procedure btnEditClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
private private
FChildForm: TWebForm; FChildForm: TWebForm;
procedure AddRowToTable(ID, Name, Description, Status: string); procedure AddRowToTable(ID, Name, Description, Status: string);
procedure ClearTable(); procedure ClearTable();
procedure GeneratePagination(TotalPages: Integer); procedure GeneratePagination(TotalPages: Integer);
function GenerateSearchOptions(): string; function GenerateSearchOptions(): string;
procedure HideNotification();
procedure ShowNotification(Notification: string);
procedure ViewMode();
procedure EditMode();
[async] procedure GetItems(searchOptions: string); [async] procedure GetItems(searchOptions: string);
[async] procedure getUser();
[async] procedure AddItem(itemOptions: string); [async] procedure AddItem(itemOptions: string);
var var
PageNumber: integer; PageNumber: integer;
...@@ -55,7 +70,7 @@ implementation ...@@ -55,7 +70,7 @@ implementation
uses uses
JS, XData.Model.Classes, JS, XData.Model.Classes,
ConnectionModule, Auth.Service, Utils; ConnectionModule, Auth.Service, Utils, View.AddItem, View.Main;
{$R *.dfm} {$R *.dfm}
...@@ -72,15 +87,33 @@ begin ...@@ -72,15 +87,33 @@ begin
getItems(GenerateSearchOptions()); getItems(GenerateSearchOptions());
end; end;
procedure TFViewItems.getUser(); procedure TFViewItems.ViewMode();
var
xdcResponse: TXDataClientResponse;
userList, user: TJSObject;
data: TJSArray;
begin begin
btnAdd.Enabled := true;
btnDelete.Enabled := true;
btnSave.Enabled := false;
btnCancel.Enabled := false;
btnEdit.Enabled := true;
FViewMain.change := false;
edtName.Enabled := false;
edtDescription.enabled := false;
cbStatus.Checked := false;
end; end;
procedure TFViewItems.EditMode();
begin
FViewMain.change := true;
btnAdd.Enabled := false;
btnDelete.Enabled := false;
btnSave.Enabled := true;
btnCancel.Enabled := True;
btnEdit.Enabled := false;
edtName.Enabled := true;
edtDescription.Enabled := true;
cbStatus.enabled := true;
end;
procedure TFViewItems.AddRowToTable(ID, Name, Description, Status: string); procedure TFViewItems.AddRowToTable(ID, Name, Description, Status: string);
// Adds rows to the table // Adds rows to the table
...@@ -341,20 +374,96 @@ begin ...@@ -341,20 +374,96 @@ begin
end; end;
end; end;
procedure TFViewItems.btnAddClick(Sender: TObject);
procedure TFViewItems.btnApplyClick(Sender: TObject);
// Button that effectively functions as a GetItems() button // Button that effectively functions as a GetItems() button
var var
itemOptions: string; itemOptions: string;
newform: TFViewAddItem;
begin begin
PageNumber := 1; {PageNumber := 1;
PageSize := StrToInt(wcbPageSize.Text); PageSize := StrToInt(wcbPageSize.Text);
itemOptions := '&name=' + edtName.Text + itemOptions := '&name=' + edtName.Text +
'&description=' + edtDescription.Text + '&description=' + edtDescription.Text +
'&status=' + BoolToStr(cbStatus.Checked); '&status=' + BoolToStr(cbStatus.Checked);
console.log('GetItems'); console.log('GetItems');
AddItem(itemOptions); AddItem(itemOptions); }
newform := TFViewAddItem.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
end
);
end;
procedure TFViewItems.btnCancelClick(Sender: TObject);
begin
ShowMessage('Editting Items is not yet implemented');
end;
procedure TFViewItems.btnCloseNotificationClick(Sender: TObject);
begin
HideNotification();
end;
procedure TFViewItems.btnDeleteClick(Sender: TObject);
begin
ShowMessage('Deleting Items is no yet implemented');
end;
procedure TFViewItems.btnEditClick(Sender: TObject);
begin
ShowMessage('Editting Items is not yet implemented');
//EditMode();
end;
procedure TFViewItems.btnSaveClick(Sender: TObject);
//TODO implement editting items
begin
ShowMessage('Editting Items is not yet implemented');
//ViewMode();
end;
procedure TFViewItems.ShowNotification(Notification: string);
var
splitNotification: TArray<string>;
begin
if Notification <> '' then
begin
splitNotification := Notification.Split([':']);
if(splitNotification[0] = 'Success') then
begin
asm
var messageDiv = document.getElementById('view.login.message');
messageDiv.classList.remove('alert-danger');
messageDiv.classList.add('alert-success');
end;
end
else
begin
asm
var messageDiv = document.getElementById('view.login.message');
messageDiv.classList.remove('alert-success');
messageDiv.classList.add('alert-danger');
end;
end;
lblMessage.Caption := splitNotification[1];
pnlMessage.ElementHandle.hidden := False;
end;
end;
procedure TFViewItems.HideNotification;
begin
pnlMessage.ElementHandle.hidden := True;
end; end;
procedure TFViewItems.AddItem(itemOptions: string); procedure TFViewItems.AddItem(itemOptions: string);
......
...@@ -29,7 +29,8 @@ uses ...@@ -29,7 +29,8 @@ uses
AddCustomer in 'AddCustomer.pas' {FViewAddCustomer: TWebForm} {*.html}, AddCustomer in 'AddCustomer.pas' {FViewAddCustomer: TWebForm} {*.html},
View.AddAddress in 'View.AddAddress.pas' {FViewAddAddress: TWebForm} {*.html}, View.AddAddress in 'View.AddAddress.pas' {FViewAddAddress: TWebForm} {*.html},
View.SelectCustomer in 'View.SelectCustomer.pas' {FSelectCustomer: TWebForm} {*.html}, View.SelectCustomer in 'View.SelectCustomer.pas' {FSelectCustomer: TWebForm} {*.html},
Utils in 'Utils.pas'; Utils in 'Utils.pas',
View.AddItem in 'View.AddItem.pas' {fViewAddItem: TWebForm} {*.html};
{$R *.res} {$R *.res}
......
...@@ -206,6 +206,11 @@ ...@@ -206,6 +206,11 @@
<DesignClass>TWebForm</DesignClass> <DesignClass>TWebForm</DesignClass>
</DCCReference> </DCCReference>
<DCCReference Include="Utils.pas"/> <DCCReference Include="Utils.pas"/>
<DCCReference Include="View.AddItem.pas">
<Form>fViewAddItem</Form>
<FormType>dfm</FormType>
<DesignClass>TWebForm</DesignClass>
</DCCReference>
<None Include="index.html"/> <None Include="index.html"/>
<None Include="css\app.css"/> <None Include="css\app.css"/>
<None Include="config\config.json"/> <None Include="config\config.json"/>
......
...@@ -488,10 +488,11 @@ type ...@@ -488,10 +488,11 @@ type
[HttpGet] function GenerateOrderWebPDF(orderID: string): string; [HttpGet] function GenerateOrderWebPDF(orderID: string): string;
[HttpGet] function GenerateOrderCuttingPDF(orderID: string): string; [HttpGet] function GenerateOrderCuttingPDF(orderID: string): string;
[HttpGet] function getQBCustomers(): TJSONArray; [HttpGet] function getQBCustomers(): TJSONArray;
[HttpGet] function getQBItems(): TJSONArray;
function AddUser(userInfo: string): string; function AddUser(userInfo: string): string;
function AddItem(itemInfo: string): string; function AddItem(itemInfo: string): TJSONObject;
function AddShippingAddress(Addressinfo: string): TJSONObject; function AddShippingAddress(Addressinfo: string): TJSONObject;
function DelShippingAddress(AddressID, CustomerID: string): TJSONObject; function DelShippingAddress(AddressID, CustomerID: string): TJSONObject;
function DelUser(username: string): string; function DelUser(username: string): string;
......
...@@ -40,6 +40,7 @@ type ...@@ -40,6 +40,7 @@ type
function GetWebOrder(orderInfo: string): TWebOrder; function GetWebOrder(orderInfo: string): TWebOrder;
function GetCuttingDieOrder(orderInfo: string): TCuttingDie; function GetCuttingDieOrder(orderInfo: string): TCuttingDie;
function GetQBCustomers: TJSONArray; function GetQBCustomers: TJSONArray;
function GetQBItems: TJSONArray;
function EditUser(const editOptions: string): string; function EditUser(const editOptions: string): string;
...@@ -51,7 +52,7 @@ type ...@@ -51,7 +52,7 @@ type
function AddUser(userInfo: string): string; function AddUser(userInfo: string): string;
function AddCustomer(customerInfo: string): TJSONObject; function AddCustomer(customerInfo: string): TJSONObject;
function AddItem(itemInfo: string): string; function AddItem(itemInfo: string): TJSONObject;
function DelUser(username: string): string; function DelUser(username: string): string;
function AddCorrugatedOrder(orderInfo: string): TJSONObject; function AddCorrugatedOrder(orderInfo: string): TJSONObject;
function AddWebOrder(orderInfo: string): TJSONObject; function AddWebOrder(orderInfo: string): TJSONObject;
...@@ -1966,50 +1967,48 @@ begin ...@@ -1966,50 +1967,48 @@ begin
end; end;
end; end;
function TLookupService.AddItem(itemInfo: string): TJSONObject;
function TLookupService.AddItem(itemInfo: string): string;
// Adds an item to the database // Adds an item to the database
// itemInfo: item info to add to database // itemInfo: item info to add to database
var var
params: TStringList; JSONData: TJSONObject;
Name: string; Name: string;
Description: string; Description, mode: string;
Status: boolean; Status: boolean;
SQL: string; SQL: string;
begin begin
try result := TJSONObject.Create;
params := TStringList.Create; JSONData := TJSONObject.ParseJSONValue(itemInfo) as TJSONObject;
params.StrictDelimiter := true; if JSONData = nil then
// parse the searchOptions raise Exception.Create('Invalid JSON format'); // If parsing fails, raise an exception
params.Delimiter := '&'; mode := JSONData.GetValue<string>('mode');
params.DelimitedText := itemInfo;
Name := params.Values['name']; Name := JSONData.GetValue<string>('qb_item_name');
Description := params.Values['description']; Description := JSONData.GetValue<string>('item_desc');
Status := StrToBool(params.Values['status']); Status := StrToBool(JSONData.GetValue<string>('status'));
SQL := 'select * from qb_items where qb_item_name = ' + QuotedStr(Name); SQL := 'select * from qb_items where qb_item_name = ' + QuotedStr(Name);
if mode = 'ADD' then
begin
doQuery(ordersDB.UniQuery1, SQL); doQuery(ordersDB.UniQuery1, SQL);
if ordersDB.UniQuery1.IsEmpty then if true then //ordersDB.UniQuery1.IsEmpty then
begin begin
ordersDB.UniQuery1.Insert; ordersDB.UniQuery1.Insert;
ordersDB.UniQuery1.FieldByName('qb_item_name').AsString := Name; ordersDB.UniQuery1.FieldByName('qb_item_name').AsString := Name;
ordersDB.UniQuery1.FieldByName('item_desc').AsString := Description; ordersDB.UniQuery1.FieldByName('item_desc').AsString := Description;
if Status then if status then
ordersDB.UniQuery1.FieldByName('status').AsString := 'ACTIVE' ordersDB.UniQuery1.FieldByName('status').AsString := 'ACTIVE'
else else
ordersDB.UniQuery1.FieldByName('status').AsString := 'INACTIVE'; ordersDB.UniQuery1.FieldByName('status').AsString := 'INACTIVE';
ordersDB.UniQuery1.Post; ordersDB.UniQuery1.Post;
Result := 'Success:Item successfully added'; Result.AddPair('msg', 'Success:Item successfully added');
end end
else else
Result := 'Failure: Item already exists'; Result.AddPair('msg', 'Failure: Item already exists');
except
on E: Exception do
raise EXDataHttpException.Create(500, 'AddItem failed: ' + E.Message);
end; end;
end; end;
...@@ -2564,8 +2563,106 @@ begin ...@@ -2564,8 +2563,106 @@ begin
end; end;
end; end;
function TLookupService.GetQBItems: TJSONArray;
var
restClient: TRESTClient;
restRequest: TRESTRequest;
restResponse: TRESTResponse;
param: TRESTRequestParameter;
res: string;
jsValue: TJSONValue;
jsObj: TJSONObject;
ItemList: TJSONArray;
pair: TJSONPair;
ModifiedList: TJSONArray;
ParsedItem, Item: TJSONObject;
I: integer;
AccessToken, RefreshToken, CompanyID, Client, Secret, SQL, desc: string;
LastRefresh: TDateTime;
iniFile: TIniFile;
begin
Result := TJSONArray.Create;
iniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini');
restClient := TRESTClient.Create(nil);
restRequest := TRESTRequest.Create(nil);
restResponse := TRESTResponse.Create(nil);
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', '');
restClient.BaseURL := 'https://sandbox-quickbooks.api.intuit.com';
if MinutesBetween(Now, LastRefresh) > 58 then
begin
RefreshAccessToken();
end;
restRequest.Method := rmGET;
res := '/v3/company/' + companyID + '/query?query=select * from Item&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;
//memo1.Lines.Add(restresponse.Content);
jsValue := restResponse.JSONValue;
jsObj := TJSONObject(jsValue);
//CustomerList := TJSONArray(restResponse.JSONValue);
//Memo1.Lines.Add( jsObj.Format(2) );
ItemList := TJSONArray( TJSONObject( jsObj.GetValue('QueryResponse') ).GetValue('Item'));
for I := 0 to ItemList.Count - 1 do
begin
Item := ItemList.Items[I] as TJSONObject;
ParsedItem := TJSONObject.Create;
SQL := 'select qb_items_id from qb_items where qb_item_name = ' + quotedStr(Item.GetValue<string>('Name'));
doQuery(ordersDB.UniQuery1, SQL);
ParsedItem.AddPair('qb_items_id', ordersDB.UniQuery1.FieldByName('qb_items_id').AsString);
ParsedItem.AddPair('qb_item_name', item.GetValue<string>('Name'));
if item.TryGetValue<string>('Description', desc) then
ParsedItem.AddPair('item_desc', desc)
else
ParsedItem.AddPair('item_desc', 'N/A');
ParsedItem.AddPair('status', item.GetValue<string>('Active'));
Result.AddElement(ParsedItem);
end;
// Load customer info
restClient.Free;
restRequest.Free;
restResponse.Free;
iniFile.Free
end;
procedure TLookupService.AddAddrBlock(prefix: string; AddrJSON: TJSONObject); procedure TLookupService.AddAddrBlock(prefix: string; AddrJSON: TJSONObject);
// the point of this function would be to save space in import QB Customer
begin begin
//TODO //TODO
end; end;
......
...@@ -77,7 +77,6 @@ object fQB: TfQB ...@@ -77,7 +77,6 @@ object fQB: TfQB
'') '')
ScrollBars = ssVertical ScrollBars = ssVertical
TabOrder = 4 TabOrder = 4
ExplicitTop = 56
end end
object Button6: TButton object Button6: TButton
Left = 538 Left = 538
...@@ -115,8 +114,6 @@ object fQB: TfQB ...@@ -115,8 +114,6 @@ object fQB: TfQB
Caption = 'Panel1' Caption = 'Panel1'
TabOrder = 8 TabOrder = 8
OnResize = Panel1Resize OnResize = Panel1Resize
ExplicitLeft = -16
ExplicitTop = 182
object asgData2: TAdvStringGrid object asgData2: TAdvStringGrid
Left = 0 Left = 0
Top = 0 Top = 0
...@@ -398,9 +395,6 @@ object fQB: TfQB ...@@ -398,9 +395,6 @@ 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 = 0
ExplicitTop = 2
ExplicitWidth = 982
ColWidths = ( ColWidths = (
64 64
64 64
...@@ -420,6 +414,15 @@ object fQB: TfQB ...@@ -420,6 +414,15 @@ object fQB: TfQB
22) 22)
end end
end end
object Button8: TButton
Left = 844
Top = 5
Width = 75
Height = 25
Caption = 'Get Items'
TabOrder = 10
OnClick = Button8Click
end
object uq: TUniQuery object uq: TUniQuery
Connection = ApiDatabase.ucKG Connection = ApiDatabase.ucKG
SQL.Strings = ( SQL.Strings = (
......
...@@ -116,6 +116,7 @@ type ...@@ -116,6 +116,7 @@ type
Splitter1: TSplitter; Splitter1: TSplitter;
asgData: TAdvStringGrid; asgData: TAdvStringGrid;
Splitter2: TSplitter; Splitter2: TSplitter;
Button8: 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);
...@@ -129,6 +130,7 @@ type ...@@ -129,6 +130,7 @@ type
procedure asgDataClickCell(Sender: TObject; ARow, ACol: Integer); procedure asgDataClickCell(Sender: TObject; ARow, ACol: Integer);
procedure Panel1Resize(Sender: TObject); procedure Panel1Resize(Sender: TObject);
procedure Panel2Resize(Sender: TObject); procedure Panel2Resize(Sender: TObject);
procedure Button8Click(Sender: TObject);
private private
{ Private declarations } { Private declarations }
strict private strict private
...@@ -536,6 +538,72 @@ begin ...@@ -536,6 +538,72 @@ begin
end; end;
procedure TfQB.Button8Click(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;
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 Item&minorversion=75'; // '/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;
//memo1.Lines.Add(restresponse.Content);
jsValue := restResponse.JSONValue;
jsObj := TJSONObject(jsValue);
//CustomerList := TJSONArray(restResponse.JSONValue);
Memo1.Lines.Add( jsObj.Format(2) );
CustomerList := TJSONArray( TJSONObject( jsObj.GetValue('QueryResponse') ).GetValue('Customer')) ;
// Load customer info
restClient.Free;
restRequest.Free;
restResponse.Free;
end;
procedure TfQB.getCustomers(); procedure TfQB.getCustomers();
var var
restClient: TRESTClient; restClient: TRESTClient;
......
...@@ -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-7-H0-1758919884sgbdvdaawcewm26l9f9k RefreshToken=RT1-60-H0-1758811104981v5rmhboxz6ul6wqho
AccessToken=eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwieC5vcmciOiJIMCJ9..OvT3ztJMwwJz7VSYEwhdBg.9iJ-2Gigq5PPVxIDTNVmIyQJOXn0UBlrFYXov83TIjLu8KvS7E4s4FSlgIc11AG-jYWu4fWHwFVwRIqeOPqEtzSrMk_hAGc07jotA9mi6MD8UpAWl_1Y1fPKuBYSe9X_00DlhCclLIMP04fn77iU71DdxC0MweciovuHDK3Gy-X26DDR_yueejvjPoHsEwhMSVshbmElgaNe2dOqtDPIuwre22piNPST7ws9o6v0wuq3juYEtW1h7qZM-S-c5yZgG25RzzFG0mShbzdfnpHimhW2n6-IGr7-ESveMOfeMHuW5M0q-QGK0IuMLIqTrRKyDl_3LXOHZSQWuAuvFpLE_EXcuRrm1JXgl43nh5U2y0MzG6JnN2pQhY_tjKdvNZmvj2XCHLKOmifLUanOhWq20bg__aZLM69iJC3VBlZeKvhqZMgNeAffle3yOX6d5cVNHCmGoZnqMXUebPzKqp-dgvoDx7qaa780Tozh2l32DDFmAStTgIYtuUxI9y5g18SnD9en2RcrUIksSEyOUMZrbfyEcN3zA0DSw6K6sqhcFAW_rMFoUqZK2sV0rZYGwmOpCN82ka_8uXke28fInem7aXpxaqOQOuxFEbBUpZxS-oTJ879-LtRs6gE8OzrwjIgF.sqyNz-sm9cjo343x7HnRvw AccessToken=eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwieC5vcmciOiJIMCJ9..hI-QSxEZMoG2Qi45pLU5OA.ywVfm3qU2BZG9FxKwt53lhdw_kKqWffGCx94ZnQTEKllmirgRjz4s-Ws6xWCeqXFEls_3Sd88hqn-XPIimc2R7xsVfrN4DODE65-dEgE1XnoyGldakGFrtY3zRRFt0A_9ZcHhEDKvEvI2ZAGfwS0yLZjz1TQxmzYtMK4TDopQf_jXHRills8oLfj5wK9S0rVEFOZTk3jJ43AYOBPWd2JyRSQlvn-PrsEZiqdbUH6PAEveGTfob9geAMScSJXQFzikUNwJlJPNjgBCOpROZU1Jy-QQF1Y3lw5wRJYakCILC3X85jORuCkXv4-ujrWLStUPt2bDGokwXW2ulg3yuhurlnhVsc5VAQDtANdWcMBWEFsm86iTjEe6UZajlN3EPrR8Ekp3qBz4YrGnAvUcJuKd89zYSQZroTTyBINHQcNJEtBRo_ZQCjLRi8go5IbC9puG52tA7DayT6AqBv2Bz8c0zX22Avx_lM82aAHrM5oOgNoTAn6wrXv10xbrUfdTBcb8zwLpegquTO78P48SPNHk1fO1ZNtB_4DDno6IvfYBBn42HfjV6HbUOjIi5HQz_Yov3UgVKIxQoZg5qfjHO1P-exWh194MjCp_qZpVjG1lZUHRDLs8ZMPTZTbqRSk9C2k.nuB0qgHOuT70EE0d3Cs6rA
LastRefresh=6/17/2025 4:51:25 PM LastRefresh=6/17/2025 10:30:26 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