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
Height = 22
ChildOrder = 12
ElementID = 'edtcompanyaccountname'
Enabled = False
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnChange = edtShortNameChange
DataField = 'SHORT_NAME'
DataSource = WebDataSource1
end
......@@ -155,18 +155,6 @@ object FViewAddCustomer: TFViewAddCustomer
WidthPercent = 100.000000000000000000
OnClick = btnCloseClick
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
Left = 151
Top = 12
......@@ -419,6 +407,7 @@ object FViewAddCustomer: TFViewAddCustomer
ElementID = 'wdblcbrep'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnChange = wdblcbRepChange
DataField = 'REP_USER_ID'
DataSource = WebDataSource1
KeyField = 'userID'
......
......@@ -12,11 +12,8 @@
<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="btnupdate" class="btn btn-primary btn-sm">Edit</button>
<button id="btnupdate" class="btn btn-primary btn-sm">Update</button>
</li>
<li class="nav-item pe-2">
<button id="btnlink" class="btn btn-primary btn-sm">Link</button>
......
......@@ -290,6 +290,12 @@ object FSelectCustomer: TFSelectCustomer
object xdwdsCustomersInKGOrders: TBooleanField
FieldName = 'In KGOrders'
end
object xdwdsCustomersBillAddrContact: TStringField
FieldName = 'BillAddrContact'
end
object xdwdsCustomersShipAddrContact: TStringField
FieldName = 'ShipAddrContact'
end
end
object wdsCustomers: TWebDataSource
DataSet = xdwdsCustomers
......
......@@ -40,6 +40,8 @@ type
WebLabel3: TWebLabel;
edtID: TWebEdit;
xdwdsCustomersInKGOrders: TBooleanField;
xdwdsCustomersBillAddrContact: TStringField;
xdwdsCustomersShipAddrContact: TStringField;
procedure WebFormCreate(Sender: TObject);
procedure WebFormShow(Sender: TObject);
procedure btnConfirmClick(Sender: TObject);
......@@ -119,12 +121,15 @@ begin
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('BILL_CONTACT', xdwdsCustomers.FieldByName('BillAddrContact').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('contact', xdwdsCustomers.FieldByName('ShipAddrContact').AsString);
CustomerJSON.AddPair('name', xdwdsCustomers.FieldByName('CompanyName').AsString);
CustomerJSON.AddPair('mode', 'ADD');
......
......@@ -53,6 +53,7 @@ type
procedure EditMode();
procedure DisablePagination();
procedure EnablePagination();
[async] procedure UpdateItem();
[async] procedure GetItems(searchOptions: string);
[async] procedure AddItem();
[async] procedure InitializeForm;
......@@ -491,6 +492,9 @@ begin
FViewMain.change := false;
ViewMode();
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.First;
getItems(GenerateSearchOptions());
......@@ -511,37 +515,71 @@ var
begin
if AuthService.TokenPayload.Properties['qb_enabled'] then
begin
newform := TFViewAddItem.CreateNew;
UpdateItem();
end
else
ShowNotificationModal('QuickBooks interface is not currently active.');
end;
newform.Caption := 'Select Item to Update';
newForm.Popup := True;
newForm.position:= poScreenCenter;
newForm.Border := fbDialog;
procedure TFViewItems.UpdateItem();
var
item: TJSObject;
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
window.location.hash := 'subform';
input := TJSHTMLInputElement(document.getElementById('edtname'));
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(
procedure(AValue: TModalResult)
begin
if newform.confirm then
begin
xdwdsItems.Edit;
input := TJSHTMLInputElement(document.getElementById('edtdescription'));
if string(item['description']) <> xdwdsItemsdescription.AsString then
begin
input.classList.add('changed-field');
change := true;
end
else
input.classList.remove('changed-field');
xdwdsItemsdescription.AsString := string(item['description']);
xdwdsItems.FieldByName('QB_ID').AsString := newform.QB_ID;
xdwdsItems.FieldByName('name').AsString := newform.name;
xdwdsItems.FieldByName('description').AsString := newform.description;
xdwdsItems.FieldByName('status').AsString := newform.status;
input := TJSHTMLInputElement(document.getElementById('lblactive'));
if string(item['status']) <> xdwdsItemsstatus.AsString then
begin
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;
EditMode();
lblFormState.Caption := 'Edit Mode';
end;
end
);
end
else
ShowNotificationModal('QuickBooks interface is not currently active.');
xdwdsItems.Post;
Utils.HideSpinner('spinner');
if change then
begin
EditMode;
ShowToast('Update successful. Changes have been highlighted');
end
else
ShowToast('Update successful. No Changes needed');
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal(E.ErrorResult.ErrorMessage);
end;
end;
procedure TFViewItems.btnSaveClick(Sender: TObject);
......@@ -578,6 +616,9 @@ begin
getItems(GenerateSearchOptions());
item := TJSObject(xdcResponse.Result);
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
on E: EXDataClientRequestException do
......
......@@ -30,7 +30,18 @@ input[type=number] {
-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;
}
......
......@@ -488,6 +488,7 @@ type
[HttpGet] function getQBItems(): TJSONArray;
[HttpGet] function GetRepUsers(): TList<TUserItem>;
[HttpGet] function UpdateCustomer(QB_ID: string): TCustomerItem;
[HttpGet] function UpdateItem(itemName: string): TItemItem;
function AddUser(userInfo: string): string;
......
......@@ -40,6 +40,7 @@ type
function GetQBItems: TJSONArray;
function GetRepUsers(): TList<TUserItem>;
function UpdateCustomer(QB_ID: string): TCustomerItem;
function UpdateItem(itemName: string): TItemItem;
function EditUser(const editOptions: string): string;
......@@ -810,7 +811,7 @@ begin
else
TDateTimeField(Field).AsDateTime := StrToDate(Pair.JsonValue.Value);
end
else if Pair.JsonValue.Value <> '' then
else
Field.AsString := Pair.JsonValue.Value;
end;
end;
......@@ -2821,6 +2822,7 @@ begin
else
begin
ParsedCustomer.AddPair('BillAddrLine1', TJSONString.Create(Line1));
ParsedCustomer.AddPair('BillAddrContact', '');
ParsedCustomer.AddPair('BillAddr',
TJSONString.Create(
Customer.GetValue<string>('DisplayName') + sLineBreak +
......@@ -2837,14 +2839,14 @@ begin
// Handle Ship Address
if Customer.GetValue('ShipAddr') is TJSONObject then
begin
BillAddr := Customer.GetValue('BillAddr') as TJSONObject;
BillAddr := Customer.GetValue('ShipAddr') as TJSONObject;
Line1 := BillAddr.GetValue<string>('Line1', '');
Line2 := BillAddr.GetValue<string>('Line2', '');
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('BillAddrZip', TJSONString.Create(BillAddr.GetValue<string>('PostalCode', '')));
ParsedCustomer.AddPair('ShipAddrZip', TJSONString.Create(BillAddr.GetValue<string>('PostalCode', '')));
if Line2 <> '' then
begin
......@@ -2864,6 +2866,7 @@ begin
else
begin
ParsedCustomer.AddPair('ShipAddrLine1', TJSONString.Create(Line1));
ParsedCustomer.AddPair('ShipAddrContact', '');
ParsedCustomer.AddPair('ShipAddr',
TJSONString.Create(
Customer.GetValue<string>('DisplayName') + sLineBreak +
......@@ -2984,7 +2987,7 @@ begin
except
on E: Exception do
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!');
end;
end;
......@@ -2997,6 +3000,105 @@ begin
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;
var
iniFile: TIniFile;
......@@ -3068,6 +3170,7 @@ begin
Exit;
Customer := CustomerList.Items[I] as TJSONObject;
logger.Log(3, 'Customer JSON recieved from QB: ' + Customer.ToJSON);
ParsedCustomer := TJSONObject.Create;
custItem := TCustomerItem.Create;
......@@ -3080,7 +3183,6 @@ begin
custItem.CUSTOMER_ID := ordersDB.UniQuery1.FieldByName('CUSTOMER_ID').AsInteger;
custItem.SHORT_NAME := ordersDB.UniQuery1.FieldByName('SHORT_NAME').AsString;
custItem.REP_USER_ID := ordersDB.UniQuery1.FieldByName('REP_USER_ID').AsString;
// Handle Bill Address
if Customer.GetValue('BillAddr') is TJSONObject then
begin
......@@ -3105,6 +3207,7 @@ begin
else
begin
custItem.BILL_ADDRESS := Line1;
custItem.BILL_CONTACT := '';
custItem.staff_fields_invoice_to := Customer.GetValue<string>('DisplayName') + sLineBreak +
BillAddr.GetValue('Line1', '') + sLineBreak +
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