Commit 45495f71 by Cam Hayes

Customers are no longer displayed when they are already in the database.

Not ready for deployment still some error handling to take care of
parent 03b02ef4
......@@ -428,13 +428,11 @@ begin
if mode = 'EDIT' then
customerJSON.AddPair('CUSTOMER_ID', customerID);
console.log('working');
Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddCustomer',
[customerJSON.ToString]));
notification := TJSObject(Response.Result);
console.log(response.Result);
msg := string(notification['status']);
if CustomerID = '' then
CustomerID := string(notification['CustomerID']);
......
......@@ -215,14 +215,13 @@ end;
procedure TFViewCustomers.wdbtcCustomersDblClickCell(Sender: TObject; ACol,
ARow: Integer);
begin
console.log(wdbtcCustomers.Cells[0, ARow]);
FViewMain.ViewAddCustomer(wdbtcCustomers.Cells[0, ARow], '') ;
end;
procedure TFViewCustomers.btnAddCustomerClick(Sender: TObject);
begin
//ShowSelectCustomerForm();
FViewMain.ViewAddCustomer('', '');
ShowSelectCustomerForm();
//FViewMain.ViewAddCustomer(string(notification['CustomerID']), string(notification['status']));
end;
procedure TFViewCustomers.edtFilterChange(Sender: TObject);
......
......@@ -4,7 +4,7 @@ object FSelectCustomer: TFSelectCustomer
OnCreate = WebFormCreate
OnShow = WebFormShow
object WebLabel1: TWebLabel
Left = 4
Left = 8
Top = 81
Width = 95
Height = 15
......@@ -15,9 +15,9 @@ object FSelectCustomer: TFSelectCustomer
object WebLabel2: TWebLabel
Left = 143
Top = 81
Width = 113
Width = 134
Height = 15
Caption = 'Selected Customer ID'
Caption = 'Selected Customer Name'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
......@@ -195,30 +195,9 @@ object FSelectCustomer: TFSelectCustomer
LeftCol = 0
ScrollMode = scmItemScrolling
DesignTimeSampleData = True
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
OnCellDblClick = TMSFNCGrid1CellDblClick
ExplicitLeft = 12
ExplicitTop = 185
end
object btnCancel: TWebButton
Left = 436
......@@ -239,16 +218,7 @@ object FSelectCustomer: TFSelectCustomer
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
OnClick = btnConfirmClick
end
object edtNotification: TWebEdit
Left = 4
......@@ -278,7 +248,7 @@ object FSelectCustomer: TFSelectCustomer
end
object xdwdsCustomers: TXDataWebDataSet
Connection = DMConnection.ApiConnection
Left = 70
Left = 166
Top = 129
object xdwdsCustomersBillAddr: TStringField
FieldName = 'BillAddr'
......@@ -295,10 +265,34 @@ object FSelectCustomer: TFSelectCustomer
object xdwdsCustomersShipAddr: TStringField
FieldName = 'ShipAddr'
end
object xdwdsCustomersShipAddrLine1: TStringField
FieldName = 'ShipAddrLine1'
end
object xdwdsCustomersShipAddrCity: TStringField
FieldName = 'ShipAddrCity'
end
object xdwdsCustomersShipAddrState: TStringField
FieldName = 'ShipAddrState'
end
object xdwdsCustomersShipAddrZip: TStringField
FieldName = 'ShipAddrZip'
end
object xdwdsCustomersBillAddrLine1: TStringField
FieldName = 'BillAddrLine1'
end
object xdwdsCustomersBillAddrCity: TStringField
FieldName = 'BillAddrCity'
end
object xdwdsCustomersBillAddrState: TStringField
FieldName = 'BillAddrState'
end
object xdwdsCustomersBillAddrZip: TStringField
FieldName = 'BillAddrZip'
end
end
object wdsCustomers: TWebDataSource
DataSet = xdwdsCustomers
Left = 18
Top = 127
Left = 104
Top = 135
end
end
......@@ -19,11 +19,8 @@ type
edtSearch: TWebEdit;
edtID: TWebEdit;
TMSFNCGrid1: TTMSFNCGrid;
cbCorrugatedPlate: TWebCheckBox;
cbWebPlate: TWebCheckBox;
btnCancel: TWebButton;
btnConfirm: TWebButton;
cbCuttingDie: TWebCheckBox;
edtNotification: TWebEdit;
XDataWebClient1: TXDataWebClient;
xdwdsCustomers: TXDataWebDataSet;
......@@ -33,11 +30,22 @@ type
xdwdsCustomersId: TStringField;
xdwdsCustomersPrimaryPhone: TStringField;
xdwdsCustomersShipAddr: TStringField;
xdwdsCustomersShipAddrLine1: TStringField;
xdwdsCustomersShipAddrCity: TStringField;
xdwdsCustomersShipAddrState: TStringField;
xdwdsCustomersShipAddrZip: TStringField;
xdwdsCustomersBillAddrLine1: TStringField;
xdwdsCustomersBillAddrCity: TStringField;
xdwdsCustomersBillAddrState: TStringField;
xdwdsCustomersBillAddrZip: TStringField;
procedure WebFormCreate(Sender: TObject);
procedure WebFormShow(Sender: TObject);
procedure TMSFNCGrid1CellDblClick(Sender: TObject; ACol, ARow: Integer);
procedure btnConfirmClick(Sender: TObject);
private
{ Private declarations }
[Async] procedure GetCustomers();
[Async] procedure SendCustomerToServer();
procedure PopulateGridManually();
public
{ Public declarations }
......@@ -51,6 +59,8 @@ implementation
{$R *.dfm
}
uses View.Main;
procedure TFSelectCustomer.WebFormCreate(Sender: TObject);
begin
if not DMConnection.ApiConnection.Connected then
......@@ -62,9 +72,20 @@ end;
procedure TFSelectCustomer.WebFormShow(Sender: TObject);
begin
asm
startSpinner();
end;
getCustomers();
end;
procedure TFSelectCustomer.btnConfirmClick(Sender: TObject);
begin
if edtID.Text = '' then
edtNotification.Text := 'Please Select a Customer'
else
SendCustomerToServer();
end;
[async] procedure TFSelectCustomer.getCustomers();
// retrieves customer list from server
var
......@@ -82,10 +103,12 @@ begin
xdwdsCustomers.Close;
xdwdsCustomers.SetJsonData(customerList);
xdwdsCustomers.Open;
console.log(customerList);
// Manually populate the grid
PopulateGridManually;
asm
endSpinner();
end;
end;
procedure TFSelectCustomer.PopulateGridManually;
......@@ -125,4 +148,51 @@ begin
end;
end;
procedure TFSelectCustomer.TMSFNCGrid1CellDblClick(Sender: TObject; ACol,
ARow: Integer);
begin
edtID.Text := TMSFNCGrid1.Cells[2, ARow];
xdwdsCustomers.Locate('Id', TMSFNCGrid1.Cells[0, ARow], [] );
end;
procedure TFSelectCustomer.SendCustomerToServer;
var
CustomerJSON: TJSONObject;
Response: TXDataClientResponse;
notification: TJSObject;
begin
CustomerJSON := TJSONObject.Create;
CustomerJSON.AddPair('NAME', xdwdsCustomers.FieldByName('CompanyName').AsString);
CustomerJSON.AddPair('QB_LIST_ID', xdwdsCustomers.FieldByName('Id').AsString);
CustomerJSON.AddPair('PHONE', xdwdsCustomers.FieldByName('PrimaryPhone').AsString);
CustomerJSON.AddPair('BILL_ADDRESS', xdwdsCustomers.FieldByName('BillAddrLine1').AsString);
CustomerJSON.AddPair('BILL_CITY', xdwdsCustomers.FieldByName('BillAddrCity').AsString);
CustomerJSON.AddPair('BILL_STATE', xdwdsCustomers.FieldByName('BillAddrState').AsString);
CustomerJSON.AddPair('BILL_ZIP', xdwdsCustomers.FieldByName('BillAddrZip').AsString);
CustomerJSON.AddPair('BILL_ADDRESS_BLOCK', xdwdsCustomers.FieldByName('BillAddr').AsString);
CustomerJSON.AddPair('address', xdwdsCustomers.FieldByName('ShipAddrLine1').AsString);
CustomerJSON.AddPair('city', xdwdsCustomers.FieldByName('ShipAddrCity').AsString);
CustomerJSON.AddPair('state', xdwdsCustomers.FieldByName('ShipAddrState').AsString);
CustomerJSON.AddPair('zip', xdwdsCustomers.FieldByName('ShipAddrZip').AsString);
CustomerJSON.AddPair('ship_block', xdwdsCustomers.FieldByName('ShipAddr').AsString);
CustomerJSON.AddPair('name', xdwdsCustomers.FieldByName('CompanyName').AsString);
CustomerJSON.AddPair('mode', 'ADD');
asm
startSpinner()
end;
Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.ImportQBCustomer',
[customerJSON.ToString]));
notification := TJSObject(Response.Result);
asm
endSpinner();
end;
FViewMain.ViewAddCustomer(string(notification['CustomerID']), string(notification['status']));
Close();
end;
end.
\ No newline at end of file
......@@ -409,6 +409,7 @@ type
function AddStatusSchedule(StatusType: string; order: TJSONObject; ORDER_ID: integer): string;
function SetStatus(statusOptions: string): string;
function AddCustomer(customerInfo: string): TJSONObject;
function ImportQBCustomer(CustomerInfo: string): TJSONObject;
end;
implementation
......
......@@ -75,6 +75,9 @@ type
procedure AddToRevisionsTable(OrderID, table: string; order: TJSONObject);
procedure SaveTokens(AccessToken, RefreshToken: string);
function RefreshAccessToken: string;
function ImportQBCustomer(CustomerInfo: string): TJSONObject;
procedure AddAddrBlock(prefix: string; AddrJSON: TJSONObject);
end;
implementation
......@@ -2313,6 +2316,7 @@ var
AccessToken, RefreshToken, CompanyID, Client, Secret: string;
LastRefresh: TDateTime;
I: integer;
SQL: string;
begin
Result := TJSONArray.Create;
iniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini');
......@@ -2365,31 +2369,65 @@ begin
for I := 0 to CustomerList.Count - 1 do
begin
Customer := CustomerList.Items[I] as TJSONObject;
ParsedCustomer := TJSONObject.Create;
try
ParsedCustomer.AddPair('Id', Customer.GetValue('Id').Clone as TJSONValue);
ParsedCustomer.AddPair('CompanyName', Customer.GetValue('DisplayName').Clone as TJSONValue);
sql := 'select CUSTOMER_ID from customers where QB_LIST_ID = ' + Customer.GetValue<string>('Id');
doQuery(ordersDB.UniQuery1, SQL);
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', BillAddr.GetValue('Line1', '') + ', '
+ BillAddr.GetValue('City', '') + ', '
+ BillAddr.GetValue('CountrySubDivisionCode', '') + ' '
+ BillAddr.GetValue('PostalCode', '') );
end;
if ordersDB.UniQuery1.IsEmpty then
begin
try
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;
Result.AddElement(ParsedCustomer);
except
ParsedCustomer.Free;
raise;
except
ParsedCustomer.Free;
raise;
end;
end;
end;
finally
......@@ -2400,6 +2438,11 @@ begin
end;
end;
procedure TLookupService.AddAddrBlock(prefix: string; AddrJSON: TJSONObject);
begin
//TODO
end;
function TLookupService.RefreshAccessToken: string;
// Refresh Token changes so make sure to save refresh token.
......@@ -2506,6 +2549,119 @@ begin
f.Free;
end;
function TLookupService.ImportQBCustomer(CustomerInfo: string): TJSONObject;
var
JSONData: TJSONObject;
SQL: string;
Pair: TJSONPair;
Field: TField;
DateFormat: TFormatSettings;
CustomerID: integer;
mode: string;
temp: string;
msg: string;
unique: boolean;
begin
DateFormat := TFormatSettings.Create;
DateFormat.ShortDateFormat := 'yyyy-mm-dd';
DateFormat.DateSeparator := '-';
JSONData := TJSONObject.ParseJSONValue(customerInfo) as TJSONObject;
if JSONData = nil then
raise Exception.Create('Invalid JSON format'); // If parsing fails, raise an exception
mode := JSONData.GetValue<string>('mode');
if mode = 'ADD' then
begin
// Update RevisionID
SQL := 'UPDATE idfield set KEYVALUE = KEYVALUE + 1 WHERE KEYNAME = ' + quotedStr('GEN_CUSTOMER_ID');
OrdersDB.UniQuery1.SQL.Text := SQL;
OrdersDB.UniQuery1.ExecSQL;
// Retrieve updated RevisionID
SQL := 'select KEYVALUE from idfield where KEYNAME = ' + quotedStr('GEN_CUSTOMER_ID');
doQuery(OrdersDB.UniQuery1, SQL);
CustomerID := OrdersDB.UniQuery1.FieldByName('KEYVALUE').AsInteger;
end
else
CustomerID := JSONData.GetValue<integer>('CUSTOMER_ID');
if mode = 'ADD' then
SQL := 'select * from customers where CUSTOMER_ID = 0 and CUSTOMER_ID <> 0'
else
begin
SQL := 'select * from customers where CUSTOMER_ID = ' + IntToStr(CustomerID);
end;
doQuery(ordersDB.UniQuery1, SQL);
try
if mode = 'ADD' then
ordersDB.UniQuery1.Insert
else
ordersDB.UniQuery1.Edit;
for Pair in JSONData do
begin
Field := ordersDB.UniQuery1.FindField(Pair.JsonString.Value); // Checks if the field exists in the dataset
if Assigned(Field) then
begin
if (Field is TDateTimeField) then
begin
if (Pair.JsonValue.Value = '') or (Pair.JsonValue.Value = 'null') or (Pair.JsonValue.Value = '12/30/1899') then
Field.Clear // This sets the field to NULL (empty)
else
TDateTimeField(Field).AsDateTime := StrToDate(Pair.JsonValue.Value);
end
else if Pair.JsonValue.Value <> '' then
Field.AsString := Pair.JsonValue.Value;
end;
end;
ordersDB.UniQuery1.FieldByName('CUSTOMER_ID').AsInteger := CustomerID;
JSONData.AddPair('customer_id', CustomerID);
// Post the record to the database
ordersDB.UniQuery1.Post;
if mode = 'ADD' then
msg := 'Success:Customer Successfully Added'
else
msg := 'Success:Customer Successfully Edited';
Result := TJSONObject.Create.AddPair('status', msg);
Result.AddPair('CustomerID', CustomerID);
TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);
//Add Shipping Information
SQL := 'select * from customers_ship where customer_id = 0 and customer_id <> 0';
doQuery(ordersDB.UniQuery1, SQL);
ordersDB.UniQuery1.Insert;
for Pair in JSONData do
begin
Field := ordersDB.UniQuery1.FindField(Pair.JsonString.Value); // Checks if the field exists in the dataset
if Assigned(Field) then
begin
if (Field is TDateTimeField) then
begin
if (Pair.JsonValue.Value = '') or (Pair.JsonValue.Value = 'null') or (Pair.JsonValue.Value = '12/30/1899') then
Field.Clear // This sets the field to NULL (empty)
else
TDateTimeField(Field).AsDateTime := StrToDate(Pair.JsonValue.Value);
end
else if Pair.JsonValue.Value <> '' then
Field.AsString := Pair.JsonValue.Value;
end;
end;
ordersDB.UniQuery1.Post;
except
on E: Exception do
begin
Result := TJSONObject.Create.AddPair('error', E.Message);
end
end;
end;
initialization
RegisterServiceType(TLookupService);
end.
......
......@@ -2,7 +2,7 @@
MemoLogLevel=3
FileLogLevel=5
webClientVersion=0.9.2
LogFileNum=591
LogFileNum=596
[Database]
Server=192.168.159.131
......@@ -17,6 +17,6 @@ Password=emsys01
CompanyID=9341454272655710
ClientID=ABgO14uvjh8XqLud7spQ8lkb98AUpcdA7HbyMJfCAtl65sQ5yy
ClientSecret=bQ06TRemHeAGFzVHRaTUvUoBU9jpU9itK6MOMgqN
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
RefreshToken=RT1-208-H0-17567544350xgx6z1cqtacxchwp91p
AccessToken=eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwieC5vcmciOiJIMCJ9..7j1C_IbyEFT7N_dCC4YUMg.PgS3pkfr9Ze_N2m-D-GlXCZOHoAcCyN0Oym1nJpozlVqoMmEr340Oc8Qr3mcvWVyv1OxWx0kiVJMPWZ-gHazOP80IypMLc7e9HZPYm0qYbwex_9JGIfZq0vQX1Y6oJQSTM9h-v_oGIN_5b7hFMLzVPCPLwXMcimXLqaXEN9b-AGX2La-FeahLDz6MmrGL-HoYB-4ZintdaxWE4NYXEg71HgecTrfkxbNlJQBziGQgnXVPmwuyqI0gJKGIL1w3X651nGcZMB_nuY0y__BPH2zOnzuibqGylOwr9ZuFXobkjgvtqllRE0JgMbCD28FArwnA_-BGsz_g6fueCvsI3ewd61tmTLyvW1IWoOoowKd5bicHQPal34KO16wORmM5_RzjCO522w_n94m9gK6JYQbS3Kn-8omnDIBZjwSBnz4mCXm-CTpexrLJRgk5h1f-lx3Ow1d9A_91qriqwNkKln35nUO4ivNvmIkDvqYMaPVXAs.LVOKao4eo0CZQ8sSO9nHoA
LastRefresh=5/23/2025 3:20:36 PM
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