Commit 85750ff1 by Cam Hayes

Updated Items to be more similar to customers with the update button.

parent ec0623e0
...@@ -19,9 +19,9 @@ object FViewAddCustomer: TFViewAddCustomer ...@@ -19,9 +19,9 @@ object FViewAddCustomer: TFViewAddCustomer
Height = 22 Height = 22
ChildOrder = 12 ChildOrder = 12
ElementID = 'edtcompanyaccountname' ElementID = 'edtcompanyaccountname'
Enabled = False
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
OnChange = edtShortNameChange
DataField = 'SHORT_NAME' DataField = 'SHORT_NAME'
DataSource = WebDataSource1 DataSource = WebDataSource1
end end
...@@ -155,18 +155,6 @@ object FViewAddCustomer: TFViewAddCustomer ...@@ -155,18 +155,6 @@ object FViewAddCustomer: TFViewAddCustomer
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
OnClick = btnCloseClick OnClick = btnCloseClick
end end
object btnEdit: TWebButton
Left = 19
Top = 504
Width = 96
Height = 25
Caption = 'Edit'
ChildOrder = 83
ElementID = 'btnedit'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = btnEditClick
end
object edtCustomerID: TWebDBEdit object edtCustomerID: TWebDBEdit
Left = 151 Left = 151
Top = 12 Top = 12
...@@ -419,6 +407,7 @@ object FViewAddCustomer: TFViewAddCustomer ...@@ -419,6 +407,7 @@ object FViewAddCustomer: TFViewAddCustomer
ElementID = 'wdblcbrep' ElementID = 'wdblcbrep'
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
OnChange = wdblcbRepChange
DataField = 'REP_USER_ID' DataField = 'REP_USER_ID'
DataSource = WebDataSource1 DataSource = WebDataSource1
KeyField = 'userID' KeyField = 'userID'
......
...@@ -12,11 +12,8 @@ ...@@ -12,11 +12,8 @@
<li class="nav-item pe-2"> <li class="nav-item pe-2">
<button id="btnadd" class="btn btn-primary btn-sm">Add</button> <button id="btnadd" class="btn btn-primary btn-sm">Add</button>
</li> </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"> <li class="nav-item pe-2">
<button id="btnupdate" class="btn btn-primary btn-sm">Edit</button> <button id="btnupdate" class="btn btn-primary btn-sm">Update</button>
</li> </li>
<li class="nav-item pe-2"> <li class="nav-item pe-2">
<button id="btnlink" class="btn btn-primary btn-sm">Link</button> <button id="btnlink" class="btn btn-primary btn-sm">Link</button>
......
...@@ -290,6 +290,12 @@ object FSelectCustomer: TFSelectCustomer ...@@ -290,6 +290,12 @@ object FSelectCustomer: TFSelectCustomer
object xdwdsCustomersInKGOrders: TBooleanField object xdwdsCustomersInKGOrders: TBooleanField
FieldName = 'In KGOrders' FieldName = 'In KGOrders'
end end
object xdwdsCustomersBillAddrContact: TStringField
FieldName = 'BillAddrContact'
end
object xdwdsCustomersShipAddrContact: TStringField
FieldName = 'ShipAddrContact'
end
end end
object wdsCustomers: TWebDataSource object wdsCustomers: TWebDataSource
DataSet = xdwdsCustomers DataSet = xdwdsCustomers
......
...@@ -40,6 +40,8 @@ type ...@@ -40,6 +40,8 @@ type
WebLabel3: TWebLabel; WebLabel3: TWebLabel;
edtID: TWebEdit; edtID: TWebEdit;
xdwdsCustomersInKGOrders: TBooleanField; xdwdsCustomersInKGOrders: TBooleanField;
xdwdsCustomersBillAddrContact: TStringField;
xdwdsCustomersShipAddrContact: TStringField;
procedure WebFormCreate(Sender: TObject); procedure WebFormCreate(Sender: TObject);
procedure WebFormShow(Sender: TObject); procedure WebFormShow(Sender: TObject);
procedure btnConfirmClick(Sender: TObject); procedure btnConfirmClick(Sender: TObject);
...@@ -119,12 +121,15 @@ begin ...@@ -119,12 +121,15 @@ begin
CustomerJSON.AddPair('BILL_STATE', xdwdsCustomers.FieldByName('BillAddrState').AsString); CustomerJSON.AddPair('BILL_STATE', xdwdsCustomers.FieldByName('BillAddrState').AsString);
CustomerJSON.AddPair('BILL_ZIP', xdwdsCustomers.FieldByName('BillAddrZip').AsString); CustomerJSON.AddPair('BILL_ZIP', xdwdsCustomers.FieldByName('BillAddrZip').AsString);
CustomerJSON.AddPair('BILL_ADDRESS_BLOCK', xdwdsCustomers.FieldByName('BillAddr').AsString); CustomerJSON.AddPair('BILL_ADDRESS_BLOCK', xdwdsCustomers.FieldByName('BillAddr').AsString);
CustomerJSON.AddPair('BILL_CONTACT', xdwdsCustomers.FieldByName('BillAddrContact').AsString);
CustomerJSON.AddPair('address', xdwdsCustomers.FieldByName('ShipAddrLine1').AsString); CustomerJSON.AddPair('address', xdwdsCustomers.FieldByName('ShipAddrLine1').AsString);
CustomerJSON.AddPair('city', xdwdsCustomers.FieldByName('ShipAddrCity').AsString); CustomerJSON.AddPair('city', xdwdsCustomers.FieldByName('ShipAddrCity').AsString);
CustomerJSON.AddPair('state', xdwdsCustomers.FieldByName('ShipAddrState').AsString); CustomerJSON.AddPair('state', xdwdsCustomers.FieldByName('ShipAddrState').AsString);
CustomerJSON.AddPair('zip', xdwdsCustomers.FieldByName('ShipAddrZip').AsString); CustomerJSON.AddPair('zip', xdwdsCustomers.FieldByName('ShipAddrZip').AsString);
CustomerJSON.AddPair('ship_block', xdwdsCustomers.FieldByName('ShipAddr').AsString); CustomerJSON.AddPair('ship_block', xdwdsCustomers.FieldByName('ShipAddr').AsString);
CustomerJSON.AddPair('contact', xdwdsCustomers.FieldByName('ShipAddrContact').AsString);
CustomerJSON.AddPair('name', xdwdsCustomers.FieldByName('CompanyName').AsString); CustomerJSON.AddPair('name', xdwdsCustomers.FieldByName('CompanyName').AsString);
CustomerJSON.AddPair('mode', 'ADD'); CustomerJSON.AddPair('mode', 'ADD');
......
...@@ -53,6 +53,7 @@ type ...@@ -53,6 +53,7 @@ type
procedure EditMode(); procedure EditMode();
procedure DisablePagination(); procedure DisablePagination();
procedure EnablePagination(); procedure EnablePagination();
[async] procedure UpdateItem();
[async] procedure GetItems(searchOptions: string); [async] procedure GetItems(searchOptions: string);
[async] procedure AddItem(); [async] procedure AddItem();
[async] procedure InitializeForm; [async] procedure InitializeForm;
...@@ -491,6 +492,9 @@ begin ...@@ -491,6 +492,9 @@ begin
FViewMain.change := false; FViewMain.change := false;
ViewMode(); ViewMode();
ShowToast('failure:Changes Discarded'); ShowToast('failure:Changes Discarded');
TJSHTMLInputElement(document.getElementById('edtname')).classList.remove('changed-field');
TJSHTMLInputElement(document.getElementById('edtdescription')).classList.remove('changed-field');
TJSHTMLInputElement(document.getElementById('lblactive')).classList.remove('changed-field-label');
xdwdsItems.Cancel; xdwdsItems.Cancel;
xdwdsItems.First; xdwdsItems.First;
getItems(GenerateSearchOptions()); getItems(GenerateSearchOptions());
...@@ -511,37 +515,71 @@ var ...@@ -511,37 +515,71 @@ var
begin begin
if AuthService.TokenPayload.Properties['qb_enabled'] then if AuthService.TokenPayload.Properties['qb_enabled'] then
begin begin
newform := TFViewAddItem.CreateNew; UpdateItem();
end
else
ShowNotificationModal('QuickBooks interface is not currently active.');
end;
newform.Caption := 'Select Item to Update'; procedure TFViewItems.UpdateItem();
newForm.Popup := True; var
newForm.position:= poScreenCenter; item: TJSObject;
newForm.Border := fbDialog; xdcResponse: TXDataClientResponse;
msg, temp: string;
change: boolean;
input: TJSHTMLInputElement;
begin
try
Utils.ShowSpinner('spinner');
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.UpdateItem', [xdwdsItemsname.AsString]));
item := TJSObject(xdcResponse.Result);
change := false;
xdwdsItems.Edit;
// used to manage Back button handling to close subform input := TJSHTMLInputElement(document.getElementById('edtname'));
window.location.hash := 'subform'; if string(item['name']) <> xdwdsItemsname.AsString then
begin
input.classList.add('changed-field');
change := true;
end
else
input.classList.remove('changed-field');
xdwdsItemsname.AsString := string(item['name']);
newform.ShowModal( input := TJSHTMLInputElement(document.getElementById('edtdescription'));
procedure(AValue: TModalResult) if string(item['description']) <> xdwdsItemsdescription.AsString then
begin begin
if newform.confirm then input.classList.add('changed-field');
begin change := true;
xdwdsItems.Edit; end
else
input.classList.remove('changed-field');
xdwdsItemsdescription.AsString := string(item['description']);
xdwdsItems.FieldByName('QB_ID').AsString := newform.QB_ID; input := TJSHTMLInputElement(document.getElementById('lblactive'));
xdwdsItems.FieldByName('name').AsString := newform.name; if string(item['status']) <> xdwdsItemsstatus.AsString then
xdwdsItems.FieldByName('description').AsString := newform.description; begin
xdwdsItems.FieldByName('status').AsString := newform.status; input.classList.add('changed-field-label');
change := true;
end
else
input.classList.remove('changed-field-label');
xdwdsItemsstatus.AsString := string(item['status']);
xdwdsItemsQB_ID.AsString := string(item['QB_ID']);
xdwdsItems.Post; xdwdsItems.Post;
EditMode(); Utils.HideSpinner('spinner');
lblFormState.Caption := 'Edit Mode'; if change then
end; begin
end EditMode;
); ShowToast('Update successful. Changes have been highlighted');
end end
else else
ShowNotificationModal('QuickBooks interface is not currently active.'); ShowToast('Update successful. No Changes needed');
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal(E.ErrorResult.ErrorMessage);
end;
end; end;
procedure TFViewItems.btnSaveClick(Sender: TObject); procedure TFViewItems.btnSaveClick(Sender: TObject);
...@@ -578,6 +616,9 @@ begin ...@@ -578,6 +616,9 @@ begin
getItems(GenerateSearchOptions()); getItems(GenerateSearchOptions());
item := TJSObject(xdcResponse.Result); item := TJSObject(xdcResponse.Result);
showToast(string(item['msg'])); showToast(string(item['msg']));
TJSHTMLInputElement(document.getElementById('edtname')).classList.remove('changed-field');
TJSHTMLInputElement(document.getElementById('edtdescription')).classList.remove('changed-field');
TJSHTMLInputElement(document.getElementById('lblactive')).classList.remove('changed-field-label');
except except
on E: EXDataClientRequestException do on E: EXDataClientRequestException do
......
...@@ -30,7 +30,18 @@ input[type=number] { ...@@ -30,7 +30,18 @@ input[type=number] {
-moz-appearance: textfield; -moz-appearance: textfield;
} }
is-invalid .form-check-input {
.changed-field {
border: 1px solid #ffc107 !important;
}
.changed-field-label {
background-color: #fff3cd;
border-radius: 4px;
padding: 2px 6px;
}
.is-invalid .form-check-input {
border: 1px solid #dc3545 !important; border: 1px solid #dc3545 !important;
} }
......
...@@ -488,6 +488,7 @@ type ...@@ -488,6 +488,7 @@ type
[HttpGet] function getQBItems(): TJSONArray; [HttpGet] function getQBItems(): TJSONArray;
[HttpGet] function GetRepUsers(): TList<TUserItem>; [HttpGet] function GetRepUsers(): TList<TUserItem>;
[HttpGet] function UpdateCustomer(QB_ID: string): TCustomerItem; [HttpGet] function UpdateCustomer(QB_ID: string): TCustomerItem;
[HttpGet] function UpdateItem(itemName: string): TItemItem;
function AddUser(userInfo: string): string; function AddUser(userInfo: string): string;
......
...@@ -40,6 +40,7 @@ type ...@@ -40,6 +40,7 @@ type
function GetQBItems: TJSONArray; function GetQBItems: TJSONArray;
function GetRepUsers(): TList<TUserItem>; function GetRepUsers(): TList<TUserItem>;
function UpdateCustomer(QB_ID: string): TCustomerItem; function UpdateCustomer(QB_ID: string): TCustomerItem;
function UpdateItem(itemName: string): TItemItem;
function EditUser(const editOptions: string): string; function EditUser(const editOptions: string): string;
...@@ -810,7 +811,7 @@ begin ...@@ -810,7 +811,7 @@ begin
else else
TDateTimeField(Field).AsDateTime := StrToDate(Pair.JsonValue.Value); TDateTimeField(Field).AsDateTime := StrToDate(Pair.JsonValue.Value);
end end
else if Pair.JsonValue.Value <> '' then else
Field.AsString := Pair.JsonValue.Value; Field.AsString := Pair.JsonValue.Value;
end; end;
end; end;
...@@ -2821,6 +2822,7 @@ begin ...@@ -2821,6 +2822,7 @@ begin
else else
begin begin
ParsedCustomer.AddPair('BillAddrLine1', TJSONString.Create(Line1)); ParsedCustomer.AddPair('BillAddrLine1', TJSONString.Create(Line1));
ParsedCustomer.AddPair('BillAddrContact', '');
ParsedCustomer.AddPair('BillAddr', ParsedCustomer.AddPair('BillAddr',
TJSONString.Create( TJSONString.Create(
Customer.GetValue<string>('DisplayName') + sLineBreak + Customer.GetValue<string>('DisplayName') + sLineBreak +
...@@ -2837,14 +2839,14 @@ begin ...@@ -2837,14 +2839,14 @@ begin
// Handle Ship Address // Handle Ship Address
if Customer.GetValue('ShipAddr') is TJSONObject then if Customer.GetValue('ShipAddr') is TJSONObject then
begin begin
BillAddr := Customer.GetValue('BillAddr') as TJSONObject; BillAddr := Customer.GetValue('ShipAddr') as TJSONObject;
Line1 := BillAddr.GetValue<string>('Line1', ''); Line1 := BillAddr.GetValue<string>('Line1', '');
Line2 := BillAddr.GetValue<string>('Line2', ''); Line2 := BillAddr.GetValue<string>('Line2', '');
ParsedCustomer.AddPair('ShipAddrLine1', TJSONString.Create(BillAddr.GetValue<string>('Line1', ''))); ParsedCustomer.AddPair('ShipAddrLine1', TJSONString.Create(BillAddr.GetValue<string>('Line1', '')));
ParsedCustomer.AddPair('ShipAddrCity', TJSONString.Create(BillAddr.GetValue<string>('City', ''))); ParsedCustomer.AddPair('ShipAddrCity', TJSONString.Create(BillAddr.GetValue<string>('City', '')));
ParsedCustomer.AddPair('ShipAddrState', TJSONString.Create(BillAddr.GetValue<string>('CountrySubDivisionCode', ''))); ParsedCustomer.AddPair('ShipAddrState', TJSONString.Create(BillAddr.GetValue<string>('CountrySubDivisionCode', '')));
ParsedCustomer.AddPair('BillAddrZip', TJSONString.Create(BillAddr.GetValue<string>('PostalCode', ''))); ParsedCustomer.AddPair('ShipAddrZip', TJSONString.Create(BillAddr.GetValue<string>('PostalCode', '')));
if Line2 <> '' then if Line2 <> '' then
begin begin
...@@ -2864,6 +2866,7 @@ begin ...@@ -2864,6 +2866,7 @@ begin
else else
begin begin
ParsedCustomer.AddPair('ShipAddrLine1', TJSONString.Create(Line1)); ParsedCustomer.AddPair('ShipAddrLine1', TJSONString.Create(Line1));
ParsedCustomer.AddPair('ShipAddrContact', '');
ParsedCustomer.AddPair('ShipAddr', ParsedCustomer.AddPair('ShipAddr',
TJSONString.Create( TJSONString.Create(
Customer.GetValue<string>('DisplayName') + sLineBreak + Customer.GetValue<string>('DisplayName') + sLineBreak +
...@@ -2984,7 +2987,7 @@ begin ...@@ -2984,7 +2987,7 @@ begin
except except
on E: Exception do on E: Exception do
begin begin
Logger.Log(2, 'Error in getQBCustomers: ' + E.Message); Logger.Log(2, 'Error in getQBItems: ' + E.Message);
raise EXDataHttpException.Create(500, 'Unable to retrieve QuickBooks Items: A QuickBooks interface error has occurred!'); raise EXDataHttpException.Create(500, 'Unable to retrieve QuickBooks Items: A QuickBooks interface error has occurred!');
end; end;
end; end;
...@@ -2997,6 +3000,105 @@ begin ...@@ -2997,6 +3000,105 @@ begin
end; end;
end; end;
function TLookupService.UpdateItem(itemName: string): TItemItem;
var
restClient: TRESTClient;
restRequest: TRESTRequest;
restResponse: TRESTResponse;
param: TRESTRequestParameter;
res: string;
jsValue: TJSONValue;
jsObj: TJSONObject;
ItemList: TJSONArray;
ParsedItem, Item: TJSONObject;
I: integer;
AccessToken, RefreshToken, CompanyID, Client, Secret, SQL, desc, BaseUrl: string;
LastRefresh: TDateTime;
iniFile: TIniFile;
begin
logger.Log(3, 'TLookupService.UpdateItem - start');
iniFile := nil;
restClient := nil;
restRequest := nil;
restResponse := nil;
try
try
Result := TItemItem.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', '');
BaseUrl := iniFile.ReadString('Quickbooks', 'BaseUrl', '');
restClient.BaseURL := BaseUrl;
restRequest.Method := rmGET;
res := '/v3/company/' + companyID + '/query?query=select * from Item where Name = ' + quotedStr(itemName) + '&minorversion=75';
restRequest.Resource := res;
param := restRequest.Params.AddItem;
param.Name := 'Authorization';
param.Kind := pkHTTPHEADER;
param.Options := param.Options + [TRESTRequestParameterOption.poDoNotEncode];
param.Value := 'Bearer ' + AccessToken;
restRequest.Execute;
jsValue := restResponse.JSONValue;
jsObj := TJSONObject(jsValue);
ItemList := TJSONArray(TJSONObject(jsObj.GetValue('QueryResponse')).GetValue('Item'));
Item := ItemList.Items[0] 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);
result.ID := ordersDB.UniQuery1.FieldByName('qb_items_id').AsString;
result.name := Item.GetValue<string>('Name');
if Item.TryGetValue<string>('Description', desc) then
result.description := desc
else
result.description := 'N/A';
result.status := Item.GetValue<string>('Active');
if StrToBool(Item.GetValue<string>('Active')) then
result.status := 'ACTIVE'
else
result.status := 'INACTIV';
result.QB_ID := Item.GetValue<string>('Id');
except
on E: Exception do
begin
Logger.Log(2, 'Error in UpdateItem: ' + E.Message);
raise EXDataHttpException.Create(500, 'Unable to retrieve QuickBooks Items: A QuickBooks interface error has occurred!');
end;
end;
finally
iniFile.Free;
restClient.Free;
restRequest.Free;
restResponse.Free;
end;
logger.Log(3, 'TLookupService.UpdateItem - end');
end;
function TLookupService.UpdateCustomer(QB_ID: string): TCustomerItem; function TLookupService.UpdateCustomer(QB_ID: string): TCustomerItem;
var var
iniFile: TIniFile; iniFile: TIniFile;
...@@ -3068,6 +3170,7 @@ begin ...@@ -3068,6 +3170,7 @@ begin
Exit; Exit;
Customer := CustomerList.Items[I] as TJSONObject; Customer := CustomerList.Items[I] as TJSONObject;
logger.Log(3, 'Customer JSON recieved from QB: ' + Customer.ToJSON);
ParsedCustomer := TJSONObject.Create; ParsedCustomer := TJSONObject.Create;
custItem := TCustomerItem.Create; custItem := TCustomerItem.Create;
...@@ -3080,7 +3183,6 @@ begin ...@@ -3080,7 +3183,6 @@ begin
custItem.CUSTOMER_ID := ordersDB.UniQuery1.FieldByName('CUSTOMER_ID').AsInteger; custItem.CUSTOMER_ID := ordersDB.UniQuery1.FieldByName('CUSTOMER_ID').AsInteger;
custItem.SHORT_NAME := ordersDB.UniQuery1.FieldByName('SHORT_NAME').AsString; custItem.SHORT_NAME := ordersDB.UniQuery1.FieldByName('SHORT_NAME').AsString;
custItem.REP_USER_ID := ordersDB.UniQuery1.FieldByName('REP_USER_ID').AsString; custItem.REP_USER_ID := ordersDB.UniQuery1.FieldByName('REP_USER_ID').AsString;
// Handle Bill Address // Handle Bill Address
if Customer.GetValue('BillAddr') is TJSONObject then if Customer.GetValue('BillAddr') is TJSONObject then
begin begin
...@@ -3105,6 +3207,7 @@ begin ...@@ -3105,6 +3207,7 @@ begin
else else
begin begin
custItem.BILL_ADDRESS := Line1; custItem.BILL_ADDRESS := Line1;
custItem.BILL_CONTACT := '';
custItem.staff_fields_invoice_to := Customer.GetValue<string>('DisplayName') + sLineBreak + custItem.staff_fields_invoice_to := Customer.GetValue<string>('DisplayName') + sLineBreak +
BillAddr.GetValue('Line1', '') + sLineBreak + BillAddr.GetValue('Line1', '') + sLineBreak +
BillAddr.GetValue('City', '') + ', ' + BillAddr.GetValue('City', '') + ', ' +
......
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