Commit baa3b955 by Elias Sarraf

Merge remote-tracking branch 'origin/cam'

parents 245de583 bb45ab03
...@@ -109,6 +109,7 @@ procedure TAuthService.Login(AUser, APassword: string; ASuccess: TOnLoginSuccess ...@@ -109,6 +109,7 @@ procedure TAuthService.Login(AUser, APassword: string; ASuccess: TOnLoginSuccess
end; end;
begin begin
console.log('login');
if (AUser = '') or (APassword = '') then if (AUser = '') or (APassword = '') then
begin begin
AError('Please enter a username and a password'); AError('Please enter a username and a password');
......
unit ConnectionModule; unit ConnectionModule;
interface interface
uses uses
System.SysUtils, System.Classes, WEBLib.Modules, XData.Web.Connection, System.SysUtils, System.Classes, WEBLib.Modules, WEBLib.Dialogs,
App.Types, App.Config, XData.Web.Client; App.Types, App.Config, XData.Web.Connection, XData.Web.Client;
type type
TDMConnection = class(TWebDataModule) TDMConnection = class(TWebDataModule)
...@@ -19,7 +19,7 @@ type ...@@ -19,7 +19,7 @@ type
FUnauthorizedAccessProc: TUnauthorizedAccessProc; FUnauthorizedAccessProc: TUnauthorizedAccessProc;
public public
const clientVersion = '0.9.15.1'; const clientVersion = '0.9.15.5';
procedure InitApp(SuccessProc: TSuccessProc; procedure InitApp(SuccessProc: TSuccessProc;
UnauthorizedAccessProc: TUnauthorizedAccessProc); UnauthorizedAccessProc: TUnauthorizedAccessProc);
procedure SetClientConfig(Callback: TVersionCheckCallback); procedure SetClientConfig(Callback: TVersionCheckCallback);
...@@ -42,8 +42,17 @@ uses ...@@ -42,8 +42,17 @@ uses
{$R *.dfm} {$R *.dfm}
procedure TDMConnection.ApiConnectionError(Error: TXDataWebConnectionError); procedure TDMConnection.ApiConnectionError(Error: TXDataWebConnectionError);
var
errorMsg: string;
begin begin
TFViewErrorPage.DisplayConnectionError(Error); errorMsg := Error.ErrorMessage;
if errorMsg = '' then
errorMsg := 'Connection error';
if Assigned(FUnauthorizedAccessProc) then
FUnauthorizedAccessProc(errorMsg)
else
ShowMessage(errorMsg);
end; end;
...@@ -63,8 +72,19 @@ end; ...@@ -63,8 +72,19 @@ end;
procedure TDMConnection.AuthConnectionError(Error: TXDataWebConnectionError); procedure TDMConnection.AuthConnectionError(Error: TXDataWebConnectionError);
var
errorMsg: string;
begin begin
TFViewErrorPage.DisplayConnectionError(Error); errorMsg := Error.ErrorMessage;
if errorMsg = '' then
errorMsg := 'Connection error';
if errorMsg = 'Error connecting to XData server' then
ShowMessage( 'Error connecting to kgOrdersServer' + sLineBreak + 'Please contact EM Systems support' )
else if Assigned(FUnauthorizedAccessProc) then
FUnauthorizedAccessProc(errorMsg)
else
ShowMessage(errorMsg);
end; end;
...@@ -87,13 +107,12 @@ begin ...@@ -87,13 +107,12 @@ begin
LoadConfig(@ConfigLoaded); LoadConfig(@ConfigLoaded);
end; end;
procedure TDMConnection.SetClientConfig(Callback: TVersionCheckCallback); procedure TDMConnection.SetClientConfig(Callback: TVersionCheckCallback);
begin begin
XDataWebClient1.Connection := AuthConnection; XDataWebClient1.Connection := AuthConnection;
console.log('ClientConfig');
XDataWebClient1.RawInvoke('IAuthService.VerifyVersion', [clientVersion], XDataWebClient1.RawInvoke('IAuthService.VerifyVersion', [clientVersion],
procedure(Response: TXDataClientResponse) procedure(Response: TXDataClientResponse) //this is the success callback
var var
jsonResult: TJSObject; jsonResult: TJSObject;
error: string; error: string;
...@@ -101,14 +120,17 @@ begin ...@@ -101,14 +120,17 @@ begin
jsonResult := TJSObject(Response.Result); jsonResult := TJSObject(Response.Result);
if jsonResult.HasOwnProperty('error') then if jsonResult.HasOwnProperty('error') then
error := string(jsonResult['error']) begin
else error := string(jsonResult['error']);
error := ''; Callback(False, error);
end
if error <> '' then
Callback(False, error)
else else
Callback(True, ''); Callback(True, '');
end,
procedure(Error: TXDataClientError) //this is the error callback
begin
Callback(False, Error.ErrorMessage);
end); end);
end; end;
......
...@@ -92,6 +92,12 @@ end; ...@@ -92,6 +92,12 @@ end;
procedure ShowErrorModal(msg: string); procedure ShowErrorModal(msg: string);
begin begin
HideSpinner('spinner'); HideSpinner('spinner');
if msg = '' then
begin
msg := 'Error connecting to EM Sytems Server.' + slinebreak +
'Please contact EM Systems Support.'
end;
asm asm
var modal = document.getElementById('main_errormodal'); var modal = document.getElementById('main_errormodal');
var label = document.getElementById('main_lblmodal_body'); var label = document.getElementById('main_lblmodal_body');
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
<label for="wdbe_first_name" style="font-weight: 700; font-size: 15px;" class="form-label mt-2">Customer ID:</label> <label for="wdbe_first_name" style="font-weight: 700; font-size: 15px;" class="form-label mt-2">Customer ID:</label>
<input id="edtcompanyaccountname"type="text" class="form-control" style="width: 150px" required/> <input id="edtcompanyaccountname"type="text" class="form-control" style="width: 150px" required/>
<div class="invalid-feedback" id="shortnamefeedback" style="font-size: 15px;"> <div class="invalid-feedback" id="shortnamefeedback" style="font-size: 15px;">
Please Provide a Company ID. Please Provide a Customer ID.
</div> </div>
</div> </div>
<div class="col-auto"> <div class="col-auto">
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
<div class="row"> <div class="row">
<div class="overflow-auto mt-2" <div class="overflow-auto mt-2"
style="max-height: calc(100vh - 250px); padding-bottom: 0; width: 100%;"> style="max-height: calc(100vh - 250px); padding-bottom: 0; width: 100%;">
<table id="tblPhoneGrid" class="table table-striped table-bordered" style="width: 100%;"> <table id="tblShippingAddress" class="table table-striped table-bordered" style="width: 100%;">
<thead class="sticky-top thead-light"> <thead class="sticky-top thead-light">
<tr style="font-size: 0.875rem;"> <tr style="font-size: 0.875rem;">
<!-- headers --> <!-- headers -->
......
...@@ -206,7 +206,6 @@ object FSelectCustomer: TFSelectCustomer ...@@ -206,7 +206,6 @@ object FSelectCustomer: TFSelectCustomer
ScrollMode = scmItemScrolling ScrollMode = scmItemScrolling
DesignTimeSampleData = True DesignTimeSampleData = True
OnCellClick = TMSFNCGrid1CellClick OnCellClick = TMSFNCGrid1CellClick
ExplicitLeft = 4
end end
object btnCancel: TWebButton object btnCancel: TWebButton
Left = 556 Left = 556
......
...@@ -86,13 +86,12 @@ begin ...@@ -86,13 +86,12 @@ begin
ShowToast('Please Select a Customer', 'danger') ShowToast('Please Select a Customer', 'danger')
else else
begin begin
if ( string(self.Caption).ToLower.Contains('add') and xdwdsCustomers.FieldByName('InKGOrders').AsBoolean) then if ( xdwdsCustomers.FieldByName('InKGOrders').AsBoolean ) then
ShowToast('failure:Customer Already in Database') ShowToast('failure:Customer Already in Database')
else else
begin begin
confirm := true; confirm := true;
QB_ID := xdwdsCustomers.FieldByName('Id').AsString; QB_ID := xdwdsCustomers.FieldByName('Id').AsString;
FViewMain.ViewAddCustomer('', QB_ID);
Close(); Close();
end; end;
end; end;
......
...@@ -112,6 +112,7 @@ object FViewCustomers: TFViewCustomers ...@@ -112,6 +112,7 @@ object FViewCustomers: TFViewCustomers
Header.ListItemElementClassName = 'page-item' Header.ListItemElementClassName = 'page-item'
Header.ListLinkElementClassName = 'page-link' Header.ListLinkElementClassName = 'page-link'
WordWrap = True WordWrap = True
OnClickCell = wdbtcCustomersClickCell
OnDblClickCell = wdbtcCustomersDblClickCell OnDblClickCell = wdbtcCustomersDblClickCell
Columns = < Columns = <
item item
......
...@@ -38,6 +38,7 @@ type ...@@ -38,6 +38,7 @@ type
procedure wdbtcCustomersDblClickCell(Sender: TObject; ACol, ARow: Integer); procedure wdbtcCustomersDblClickCell(Sender: TObject; ACol, ARow: Integer);
procedure edtFilterChange(Sender: TObject); procedure edtFilterChange(Sender: TObject);
procedure wcbPageSizeChange(Sender: TObject); procedure wcbPageSizeChange(Sender: TObject);
procedure wdbtcCustomersClickCell(Sender: TObject; ACol, ARow: Integer);
private private
{ Private declarations } { Private declarations }
procedure GeneratePagination(TotalPages: Integer); procedure GeneratePagination(TotalPages: Integer);
...@@ -82,7 +83,8 @@ begin ...@@ -82,7 +83,8 @@ begin
newform.ShowModal( newform.ShowModal(
procedure(AValue: TModalResult) procedure(AValue: TModalResult)
begin begin
if newform.confirm then
FViewMain.ViewAddCustomer('', newform.QB_ID);
end end
); );
end; end;
...@@ -169,6 +171,12 @@ begin ...@@ -169,6 +171,12 @@ begin
getCustomers(GenerateSearchOptions()); getCustomers(GenerateSearchOptions());
end; end;
procedure TFViewCustomers.wdbtcCustomersClickCell(Sender: TObject; ACol,
ARow: Integer);
begin
console.log(xdwdsCustomersSHORT_NAME.AsString);
end;
procedure TFViewCustomers.wdbtcCustomersDblClickCell(Sender: TObject; ACol, procedure TFViewCustomers.wdbtcCustomersDblClickCell(Sender: TObject; ACol,
ARow: Integer); ARow: Integer);
begin begin
......
...@@ -22,18 +22,11 @@ object FViewHome: TFViewHome ...@@ -22,18 +22,11 @@ object FViewHome: TFViewHome
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
Lines.Strings = ( Lines.Strings = (
'Change Log:' 'Change Log:'
'1) Setting a status now autofills due dates.' '1) Updated access type'
'2) Fixed order dates displaying on 3 lines rather than 2.' '2) Removed user profile')
'3) Adjusted pdfs so that special instructions would have enough ' +
'space.'
'4) Fixed issue with PDF generation.'
'5) Removed ability to put 0 or a negative number for price and q' +
'uantity on order entry fields.')
ReadOnly = True ReadOnly = True
SelLength = 0 SelLength = 0
SelStart = 323 SelStart = 62
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
end end
end end
...@@ -91,10 +91,8 @@ begin ...@@ -91,10 +91,8 @@ begin
QB_ID := xdwdsCustomers.FieldByName('qb_items_qb_id').AsString; QB_ID := xdwdsCustomers.FieldByName('qb_items_qb_id').AsString;
name := xdwdsCustomers.FieldByName('qb_item_name').AsString; name := xdwdsCustomers.FieldByName('qb_item_name').AsString;
description := xdwdsCustomers.FieldByName('item_desc').AsString; description := xdwdsCustomers.FieldByName('item_desc').AsString;
if xdwdsCustomers.FieldByName('status').AsBoolean then status := xdwdsCustomers.FieldByName('status').AsString;
status := 'ACTIVE'
else
status := 'INACTIVE';
confirm := true; confirm := true;
Close; Close;
end; end;
......
...@@ -439,37 +439,46 @@ end; ...@@ -439,37 +439,46 @@ end;
procedure TFViewItems.btnAddClick(Sender: TObject); procedure TFViewItems.btnAddClick(Sender: TObject);
var var
itemOptions: string; itemOptions, AccessType: string;
newform: TFViewAddItem; newform: TFViewAddItem;
begin begin
newform := TFViewAddItem.CreateNew; AccessType := JS.toString(AuthService.TokenPayload.Properties['user_access_type']);
if( ( AccessType = 'ADMIN' ) or ( AccessType = 'QBUSR' ) ) then
begin
newform := TFViewAddItem.CreateNew;
newform.Caption := 'Select Item to Add'; newform.Caption := 'Select Item to Add';
newForm.Popup := True; newForm.Popup := True;
newForm.position:= poScreenCenter; newForm.position:= poScreenCenter;
newForm.Border := fbDialog; newForm.Border := fbDialog;
// used to manage Back button handling to close subform // used to manage Back button handling to close subform
window.location.hash := 'subform'; window.location.hash := 'subform';
newform.ShowModal( newform.ShowModal(
procedure(AValue: TModalResult) procedure(AValue: TModalResult)
begin
if newform.confirm then
begin begin
xdwdsItems.Append; if newform.confirm then
begin
xdwdsItems.FieldByName('QB_ID').AsString := newform.QB_ID; xdwdsItems.Append;
xdwdsItems.FieldByName('name').AsString := newform.name;
xdwdsItems.FieldByName('description').AsString := newform.description; xdwdsItems.FieldByName('QB_ID').AsString := newform.QB_ID;
xdwdsItems.FieldByName('status').AsString := newform.status; xdwdsItems.FieldByName('name').AsString := newform.name;
xdwdsItems.FieldByName('description').AsString := newform.description;
xdwdsItems.FieldByName('status').AsString := newform.status;
console.log(xdwdsItems.FieldByName('status').AsString);
console.log(newform.status);
xdwdsItems.Post;
EditMode();
lblFormState.Caption := 'Add Mode';
end;
end
);
end
else
ShowToast('Failure:User not authorized to add item from QuickBooks', 'failure');
xdwdsItems.Post;
EditMode();
lblFormState.Caption := 'Add Mode';
end;
end
);
end; end;
procedure TFViewItems.btnCancelClick(Sender: TObject); procedure TFViewItems.btnCancelClick(Sender: TObject);
...@@ -498,15 +507,22 @@ end; ...@@ -498,15 +507,22 @@ end;
procedure TFViewItems.btnDeleteClick(Sender: TObject); procedure TFViewItems.btnDeleteClick(Sender: TObject);
begin begin
ShowNotificationModal('Deleting items is not yet implemented.'); ShowToast('Deleting items is not yet implemented.', 'info');
end; end;
procedure TFViewItems.btnUpdateClick(Sender: TObject); procedure TFViewItems.btnUpdateClick(Sender: TObject);
var var
itemOptions: string; itemOptions, AccessType: string;
newform: TFViewAddItem; newform: TFViewAddItem;
begin begin
UpdateItem(); AccessType := JS.toString(AuthService.TokenPayload.Properties['user_access_type']);
if( ( AccessType = 'ADMIN' ) or ( AccessType = 'QBUSR' ) ) then
begin
UpdateItem();
end
else
ShowToast('Failure:User not authorized to update item from QuickBooks', 'failure');
end; end;
procedure TFViewItems.UpdateItem(); procedure TFViewItems.UpdateItem();
...@@ -560,10 +576,10 @@ begin ...@@ -560,10 +576,10 @@ begin
if change then if change then
begin begin
EditMode; EditMode;
ShowToast('Update successful. Changes have been highlighted'); ShowToast('Changes have been highlighted');
end end
else else
ShowToast('Update successful. No Changes needed'); ShowToast('No Changes needed');
except except
on E: EXDataClientRequestException do on E: EXDataClientRequestException do
Utils.ShowErrorModal(E.ErrorResult.ErrorMessage); Utils.ShowErrorModal(E.ErrorResult.ErrorMessage);
......
...@@ -54,7 +54,7 @@ procedure TFViewLogin.btnLoginClick(Sender: TObject); ...@@ -54,7 +54,7 @@ procedure TFViewLogin.btnLoginClick(Sender: TObject);
procedure LoginError(AMsg: string); procedure LoginError(AMsg: string);
begin begin
ShowNotification('Login Error: ' + AMsg); ShowNotification(AMsg);
end; end;
var var
hashPW: string; hashPW: string;
......
...@@ -22,17 +22,6 @@ object FViewMain: TFViewMain ...@@ -22,17 +22,6 @@ object FViewMain: TFViewMain
Transparent = False Transparent = False
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
end end
object wllblUserProfile: TWebLinkLabel
Left = 529
Top = 21
Width = 59
Height = 14
ElementID = 'dropdown.menu.userprofile'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = wllblUserProfileClick
Caption = ' User Profile'
end
object wllblLogout: TWebLinkLabel object wllblLogout: TWebLinkLabel
Left = 554 Left = 554
Top = 148 Top = 148
...@@ -74,6 +63,7 @@ object FViewMain: TFViewMain ...@@ -74,6 +63,7 @@ object FViewMain: TFViewMain
Height = 14 Height = 14
ElementID = 'dropdown.menu.itemlist' ElementID = 'dropdown.menu.itemlist'
ElementFont = efCSS ElementFont = efCSS
Enabled = False
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
OnClick = lblItemsListClick OnClick = lblItemsListClick
...@@ -86,6 +76,7 @@ object FViewMain: TFViewMain ...@@ -86,6 +76,7 @@ object FViewMain: TFViewMain
Height = 14 Height = 14
ElementID = 'dropdown.menu.users' ElementID = 'dropdown.menu.users'
ElementFont = efCSS ElementFont = efCSS
Enabled = False
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
OnClick = lblUsersClick OnClick = lblUsersClick
...@@ -114,6 +105,7 @@ object FViewMain: TFViewMain ...@@ -114,6 +105,7 @@ object FViewMain: TFViewMain
ElementID = 'lblcustomers' ElementID = 'lblcustomers'
ElementFont = efCSS ElementFont = efCSS
ElementPosition = epRelative ElementPosition = epRelative
Enabled = False
HeightStyle = ssAuto HeightStyle = ssAuto
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
...@@ -140,6 +132,7 @@ object FViewMain: TFViewMain ...@@ -140,6 +132,7 @@ object FViewMain: TFViewMain
Caption = 'QB Info' Caption = 'QB Info'
ElementID = 'dropdown.menu.linktoqb' ElementID = 'dropdown.menu.linktoqb'
ElementFont = efCSS ElementFont = efCSS
Enabled = False
HeightStyle = ssAuto HeightStyle = ssAuto
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
...@@ -153,8 +146,14 @@ object FViewMain: TFViewMain ...@@ -153,8 +146,14 @@ object FViewMain: TFViewMain
Caption = 'TEST MODE' Caption = 'TEST MODE'
ElementID = 'view.main.test' ElementID = 'view.main.test'
ElementFont = efCSS ElementFont = efCSS
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Style = []
HeightStyle = ssAuto HeightStyle = ssAuto
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
ParentFont = False
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
end end
object WebPanel1: TWebPanel object WebPanel1: TWebPanel
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">
<a id="view.main.apptitle" class="navbar-brand" href="index.html">Koehler-Gibson Orders</a> <a id="view.main.apptitle" class="navbar-brand" href="index.html">Koehler-Gibson Orders</a>
<span id="view.main.version" class="small text-muted ms-2 me-5"></span> <span id="view.main.version" class="small text-muted ms-2 me-5"></span>
<span id="view.main.test" class="test-warning fw-bold mb-1" style="display: none;">TEST MODE</span> <span id="view.main.test" class="test-warning fw-bold mb-1 text-nowrap" style="display: none; font-size: 0.85rem;">TEST MODE</span>
</div> </div>
<ul class="navbar-nav ml-auto"> <ul class="navbar-nav ml-auto">
<li class="nav-item"> <li class="nav-item">
...@@ -28,9 +28,6 @@ ...@@ -28,9 +28,6 @@
<a class="dropdown-item" id="dropdown.menu.home" href="#"><i class="fa fa-home fa-fw"></i><span> Home</span></a> <a class="dropdown-item" id="dropdown.menu.home" href="#"><i class="fa fa-home fa-fw"></i><span> Home</span></a>
</li> </li>
<li> <li>
<a class="dropdown-item" id="dropdown.menu.userprofile" href="#"><i class="fa fa-user fa-fw"></i><span> User Profile</span></a>
</li>
<li>
<a class="dropdown-item" id="dropdown.menu.users" href="#"><i class="fas fa-address-book fa-fw"></i><span> Users</span></a> <a class="dropdown-item" id="dropdown.menu.users" href="#"><i class="fas fa-address-book fa-fw"></i><span> Users</span></a>
</li> </li>
<li> <li>
......
...@@ -12,7 +12,6 @@ uses ...@@ -12,7 +12,6 @@ uses
type type
TFViewMain = class(TWebForm) TFViewMain = class(TWebForm)
lblUsername: TWebLabel; lblUsername: TWebLabel;
wllblUserProfile: TWebLinkLabel;
wllblLogout: TWebLinkLabel; wllblLogout: TWebLinkLabel;
WebPanel1: TWebPanel; WebPanel1: TWebPanel;
lblHome: TWebLinkLabel; lblHome: TWebLinkLabel;
...@@ -29,7 +28,6 @@ type ...@@ -29,7 +28,6 @@ type
WebLabel1: TWebLabel; WebLabel1: TWebLabel;
procedure WebFormCreate(Sender: TObject); procedure WebFormCreate(Sender: TObject);
procedure mnuLogoutClick(Sender: TObject); procedure mnuLogoutClick(Sender: TObject);
procedure wllblUserProfileClick(Sender: TObject);
procedure wllblLogoutClick(Sender: TObject); procedure wllblLogoutClick(Sender: TObject);
procedure lblHomeClick(Sender: TObject); procedure lblHomeClick(Sender: TObject);
procedure lblItemsListClick(Sender: TObject); procedure lblItemsListClick(Sender: TObject);
...@@ -75,7 +73,6 @@ implementation ...@@ -75,7 +73,6 @@ implementation
uses uses
Auth.Service, Auth.Service,
View.Login, View.Login,
View.UserProfile,
View.Home, View.Home,
View.Items, View.Items,
View.Users, View.Users,
...@@ -92,7 +89,7 @@ uses ...@@ -92,7 +89,7 @@ uses
procedure TFViewMain.WebFormCreate(Sender: TObject); procedure TFViewMain.WebFormCreate(Sender: TObject);
var var
userName: string; userName, AccessType: string;
test: boolean; test: boolean;
begin begin
FUserInfo := GetUserInfo; FUserInfo := GetUserInfo;
...@@ -100,13 +97,20 @@ begin ...@@ -100,13 +97,20 @@ begin
lblUsername.Caption := ' ' + userName.ToLower + ' '; lblUsername.Caption := ' ' + userName.ToLower + ' ';
FChildForm := nil; FChildForm := nil;
change := false; change := false;
AccessType := JS.toString(AuthService.TokenPayload.Properties['user_access_type']);
if (not (JS.toString(AuthService.TokenPayload.Properties['user_access_type']) = 'ADMIN')) then if ( AccessType = 'ADMIN' ) then
begin begin
lblUsers.enabled := false; lblUsers.enabled := true;
lblQBInfo.Enabled := false;
lblCustomers.Enabled := false;
end; end;
if( ( AccessType = 'ADMIN' ) or ( AccessType = 'QBUSR' ) ) then
begin
lblQBInfo.Enabled := true;
lblCustomers.Enabled := true;
lblItemsList.Enabled := true;
end;
lblAppTitle.Caption := 'Koehler-Gibson Orders'; lblAppTitle.Caption := 'Koehler-Gibson Orders';
lblVersion.Caption := 'v' + DMConnection.clientVersion; lblVersion.Caption := 'v' + DMConnection.clientVersion;
ShowForm(TFViewOrders); ShowForm(TFViewOrders);
...@@ -266,14 +270,6 @@ begin ...@@ -266,14 +270,6 @@ begin
end; end;
procedure TFViewMain.wllblUserProfileClick(Sender: TObject);
begin
ShowCrudForm(TFViewUserProfile);
lblAppTitle.Caption := 'Koehler-Gibson User Profile';
setActive('User Profile');
end;
function TFViewMain.GetUserInfo: string; function TFViewMain.GetUserInfo: string;
var var
userStr: string; userStr: string;
......
...@@ -390,8 +390,10 @@ procedure TFOrderEntryCorrugated.btnQBClick(Sender: TObject); ...@@ -390,8 +390,10 @@ procedure TFOrderEntryCorrugated.btnQBClick(Sender: TObject);
var var
orderJSON: TJSONObject; orderJSON: TJSONObject;
qbEnabled: boolean; qbEnabled: boolean;
AccessType: string;
begin begin
if JS.toString(AuthService.TokenPayload.Properties['user_qb_id']) <> '' then AccessType := JS.toString(AuthService.TokenPayload.Properties['user_access_type']);
if( ( AccessType = 'ADMIN' ) or ( AccessType = 'QBUSR' ) ) then
begin begin
if ( VerifyQBOrder() )then if ( VerifyQBOrder() )then
begin begin
...@@ -513,6 +515,10 @@ begin ...@@ -513,6 +515,10 @@ begin
xdwdsOrder.Close; xdwdsOrder.Close;
xdwdsOrder.SetJsonData(jsObj); xdwdsOrder.SetJsonData(jsObj);
xdwdsOrder.Open; xdwdsOrder.Open;
cbLoose.Checked := ( xdwdsOrder.FieldByName('mounting_loose').AsString <> '' );
cbStripMount.Checked := ( xdwdsOrder.FieldByName('mounting_strip_mount').AsString <> '' );
OrderID := xdwdsOrderORDER_ID.AsString;
mode := 'EDIT'; mode := 'EDIT';
ShowToast(string(jsObj.Properties['status'])); ShowToast(string(jsObj.Properties['status']));
...@@ -630,7 +636,7 @@ begin ...@@ -630,7 +636,7 @@ begin
notification := TJSObject(Response.Result); notification := TJSObject(Response.Result);
ShowToast(string(notification['status'])); ShowToast(string(notification['status']));
xdwdsShipTo.Close; xdwdsShipTo.Close;
xdwdsShipTo.SetJSONData(notification['ADDRESS']); xdwdsShipTo.SetJSONData(TJSObject(notification['customer'])['SHIPPING_ADDRESS_LIST']);
xdwdsShipTo.Open; xdwdsShipTo.Open;
end; end;
...@@ -666,7 +672,7 @@ begin ...@@ -666,7 +672,7 @@ begin
AddressJSON.AddPair('state', newform.edtState.Text); AddressJSON.AddPair('state', newform.edtState.Text);
AddressJSON.AddPair('zip', newform.edtZip.Text); AddressJSON.AddPair('zip', newform.edtZip.Text);
AddressJSON.AddPair('contact', newform.edtContact.Text); AddressJSON.AddPair('contact', newform.edtContact.Text);
AddressJSON.AddPair('customer_id', customerID); AddressJSON.AddPair('customer_id', xdwdsOrder.FieldByName('COMPANY_ID').AsString);
ship_block := newform.edtFirstLine.Text + slinebreak + ship_block := newform.edtFirstLine.Text + slinebreak +
edtCompanyName.Text + slinebreak + edtCompanyName.Text + slinebreak +
...@@ -676,6 +682,7 @@ begin ...@@ -676,6 +682,7 @@ begin
AddressJSON.AddPair('ship_block', ship_block); AddressJSON.AddPair('ship_block', ship_block);
AddressJSON.AddPair('mode', 'ADD'); AddressJSON.AddPair('mode', 'ADD');
console.log(AddressJSON);
sendAddressToServer(AddressJSON); sendAddressToServer(AddressJSON);
end; end;
end end
...@@ -787,7 +794,7 @@ begin ...@@ -787,7 +794,7 @@ begin
container := TJSHTMLElement(document.getElementById('additionalFields')); container := TJSHTMLElement(document.getElementById('additionalFields'));
if Assigned(container) then if Assigned(container) then
container.innerHTML := ''; // Wipe previous content container.innerHTML := ''; // Wipe previous colors
if xdwdsOrdercolors_colors.Value <> '' then if xdwdsOrdercolors_colors.Value <> '' then
begin begin
...@@ -800,6 +807,7 @@ begin ...@@ -800,6 +807,7 @@ begin
end; end;
end; end;
if xdwdsOrder.FieldByName('mounting_loose').AsString <> '' then if xdwdsOrder.FieldByName('mounting_loose').AsString <> '' then
cbLoose.Checked := true; cbLoose.Checked := true;
......
...@@ -194,8 +194,10 @@ procedure TFOrderEntryCuttingDie.btnQBClick(Sender: TObject); ...@@ -194,8 +194,10 @@ procedure TFOrderEntryCuttingDie.btnQBClick(Sender: TObject);
var var
orderJSON: TJSONObject; orderJSON: TJSONObject;
qbEnabled: boolean; qbEnabled: boolean;
AccessType: string;
begin begin
if JS.toString(AuthService.TokenPayload.Properties['user_qb_id']) <> '' then AccessType := JS.toString(AuthService.TokenPayload.Properties['user_access_type']);
if( ( AccessType = 'ADMIN' ) or ( AccessType = 'QBUSR' ) ) then
begin begin
if ( VerifyQBOrder() )then if ( VerifyQBOrder() )then
begin begin
...@@ -231,7 +233,7 @@ begin ...@@ -231,7 +233,7 @@ begin
notification := TJSObject(Response.Result); notification := TJSObject(Response.Result);
ShowToast(string(notification['status'])); ShowToast(string(notification['status']));
xdwdsShipTo.Close; xdwdsShipTo.Close;
xdwdsShipTo.SetJSONData(notification['ADDRESS']); xdwdsShipTo.SetJSONData(TJSObject(notification['customer'])['SHIPPING_ADDRESS_LIST']);
xdwdsShipTo.Open; xdwdsShipTo.Open;
end; end;
...@@ -428,6 +430,7 @@ begin ...@@ -428,6 +430,7 @@ begin
xdwdsOrder.Close; xdwdsOrder.Close;
xdwdsOrder.SetJsonData(jsObj); xdwdsOrder.SetJsonData(jsObj);
xdwdsOrder.Open; xdwdsOrder.Open;
OrderID := xdwdsOrderORDER_ID.AsString;
mode := 'EDIT'; mode := 'EDIT';
ShowToast(String(jsObj.Properties['status'])); ShowToast(String(jsObj.Properties['status']));
...@@ -488,8 +491,8 @@ begin ...@@ -488,8 +491,8 @@ begin
if confirmed then if confirmed then
begin begin
FViewMain.change := false; FViewMain.change := false;
if xdwdsOrder.FieldByName('ORDER_ID').AsString <> '' then if orderID <> '' then
FViewMain.ViewOrderEntryCuttingDie(xdwdsOrder.FieldByName('ORDER_ID').AsString, '', 'EDIT', 'Failure: Changes Discarded') FViewMain.ViewOrderEntryCuttingDie(orderID, '', 'EDIT', 'Failure: Changes Discarded')
else else
FViewMain.ViewOrders(''); FViewMain.ViewOrders('');
end; end;
......
...@@ -323,7 +323,7 @@ begin ...@@ -323,7 +323,7 @@ begin
notification := TJSObject(Response.Result); notification := TJSObject(Response.Result);
ShowToast(string(notification['status'])); ShowToast(string(notification['status']));
xdwdsShipTo.Close; xdwdsShipTo.Close;
xdwdsShipTo.SetJSONData(notification['ADDRESS']); xdwdsShipTo.SetJSONData(TJSObject(notification['customer'])['SHIPPING_ADDRESS_LIST']);
xdwdsShipTo.Open; xdwdsShipTo.Open;
end; end;
...@@ -358,7 +358,7 @@ begin ...@@ -358,7 +358,7 @@ begin
AddressJSON.AddPair('state', newform.edtState.Text); AddressJSON.AddPair('state', newform.edtState.Text);
AddressJSON.AddPair('zip', newform.edtZip.Text); AddressJSON.AddPair('zip', newform.edtZip.Text);
AddressJSON.AddPair('contact', newform.edtContact.Text); AddressJSON.AddPair('contact', newform.edtContact.Text);
AddressJSON.AddPair('customer_id', customerID); AddressJSON.AddPair('customer_id', xdwdsOrderCOMPANY_ID.AsString);
ship_block := newform.edtFirstLine.Text + slinebreak + ship_block := newform.edtFirstLine.Text + slinebreak +
edtCompanyName.Text + slinebreak + edtCompanyName.Text + slinebreak +
...@@ -454,8 +454,10 @@ procedure TFOrderEntryWeb.btnQBClick(Sender: TObject); ...@@ -454,8 +454,10 @@ procedure TFOrderEntryWeb.btnQBClick(Sender: TObject);
var var
orderJSON: TJSONObject; orderJSON: TJSONObject;
qbEnabled: boolean; qbEnabled: boolean;
AccessType: string;
begin begin
if JS.toString(AuthService.TokenPayload.Properties['user_qb_id']) <> '' then AccessType := JS.toString(AuthService.TokenPayload.Properties['user_access_type']);
if( ( AccessType = 'ADMIN' ) or ( AccessType = 'QBUSR' ) ) then
begin begin
if ( VerifyQBOrder() )then if ( VerifyQBOrder() )then
begin begin
...@@ -597,6 +599,7 @@ begin ...@@ -597,6 +599,7 @@ begin
xdwdsOrder.Open; xdwdsOrder.Open;
mode := 'EDIT'; mode := 'EDIT';
OrderID := xdwdsOrderORDER_ID.AsString;
ShowToast(String(jsObj.Properties['status'])); ShowToast(String(jsObj.Properties['status']));
except except
on E: EXDataClientRequestException do on E: EXDataClientRequestException do
...@@ -768,6 +771,7 @@ var ...@@ -768,6 +771,7 @@ var
colorList: TJSArray; colorList: TJSArray;
color: TJSObject; color: TJSObject;
items: TJSObject; items: TJSObject;
container: TJSHTMLElement;
begin begin
Utils.ShowSpinner('spinner'); Utils.ShowSpinner('spinner');
try try
...@@ -779,6 +783,10 @@ begin ...@@ -779,6 +783,10 @@ begin
xdwdsOrder.SetJsonData(order); xdwdsOrder.SetJsonData(order);
xdwdsOrder.Open; xdwdsOrder.Open;
container := TJSHTMLElement(document.getElementById('additionalFields'));
if Assigned(container) then
container.innerHTML := ''; // Wipe previous colors
if xdwdsOrderquantity_and_colors_qty_colors.Value <> '' then if xdwdsOrderquantity_and_colors_qty_colors.Value <> '' then
begin begin
colorObject := TJSObject(TJSJSON.parse(xdwdsOrderquantity_and_colors_qty_colors.Value)); colorObject := TJSObject(TJSJSON.parse(xdwdsOrderquantity_and_colors_qty_colors.Value));
...@@ -875,6 +883,7 @@ begin ...@@ -875,6 +883,7 @@ begin
btnCancel.Enabled := True; btnCancel.Enabled := True;
btnEdit.Enabled := false; btnEdit.Enabled := false;
btnAdd.Enabled := false; btnAdd.Enabled := false;
btnQB.Enabled := false;
cbPdf.Enabled := True; cbPdf.Enabled := True;
cbInkJet.Enabled := True; cbInkJet.Enabled := True;
...@@ -912,6 +921,7 @@ begin ...@@ -912,6 +921,7 @@ begin
btnCancel.Enabled := false; btnCancel.Enabled := false;
btnEdit.Enabled := true; btnEdit.Enabled := true;
btnAdd.Enabled := true; btnAdd.Enabled := true;
btnQB.Enabled := true;
FViewMain.change := false; FViewMain.change := false;
cbPdf.Enabled := False; cbPdf.Enabled := False;
......
...@@ -14,7 +14,7 @@ uses ...@@ -14,7 +14,7 @@ uses
WEBLib.JSON, Auth.Service, XData.Web.Client, WebLib.Storage, WEBLib.JSON, Auth.Service, XData.Web.Client, WebLib.Storage,
ConnectionModule, App.Types, Vcl.StdCtrls, Vcl.Controls, WEBLib.DBCtrls, ConnectionModule, App.Types, Vcl.StdCtrls, Vcl.Controls, WEBLib.DBCtrls,
XData.Web.JsonDataset, WEBLib.DB, Data.DB, XData.Web.Dataset, XData.Web.DatasetCommon, XData.Web.JsonDataset, WEBLib.DB, Data.DB, XData.Web.Dataset, XData.Web.DatasetCommon,
WEBLib.Grids, VCL.Forms; WEBLib.Grids, VCL.Forms, Math;
type type
TFViewOrders = class(TWebForm) TFViewOrders = class(TWebForm)
...@@ -552,8 +552,15 @@ end; ...@@ -552,8 +552,15 @@ end;
procedure TFViewOrders.wcbPageSizeChange(Sender: TObject); procedure TFViewOrders.wcbPageSizeChange(Sender: TObject);
var
ratio: double;
begin begin
ratio := PageSize/StrToInt(wcbPageSize.Text);
PageSize := StrToInt(wcbPageSize.Text); PageSize := StrToInt(wcbPageSize.Text);
if ratio < 1 then
PageNumber := Ceil(PageNumber * ratio)
else
PageNumber := Ceil(PageNumber * ratio) - Trunc(ratio) + 1;
getOrders(generateSearchOptions()); getOrders(generateSearchOptions());
end; end;
......
...@@ -36,11 +36,17 @@ implementation ...@@ -36,11 +36,17 @@ implementation
{$R *.dfm} {$R *.dfm}
uses View.Main, Utils; uses View.Main, Utils, Auth.Service;
procedure TFQBInfo.btnLinkToQBClick(Sender: TObject); procedure TFQBInfo.btnLinkToQBClick(Sender: TObject);
var
AccessType: String;
begin begin
GetQBLink(); AccessType := JS.toString(AuthService.TokenPayload.Properties['user_access_type']);
if( ( AccessType = 'ADMIN' ) or ( AccessType = 'QBUSR' ) ) then
GetQBLink()
else
ShowToast('Failure:User not authorized to add to QuickBooks', 'failure');
end; end;
procedure TFQBInfo.WebFormCreate(Sender: TObject); procedure TFQBInfo.WebFormCreate(Sender: TObject);
......
...@@ -220,7 +220,7 @@ begin ...@@ -220,7 +220,7 @@ begin
else if wlcbStatus.DisplayText = 'Plate Done' then else if wlcbStatus.DisplayText = 'Plate Done' then
begin begin
dtpPlateDue.Date := plateDue; dtpPlateDue.Date := plateDue;
dtpShipDue.Date := plateDue; dtpShipDue.Date := dtpDate.Date;
end end
else if wlcbStatus.DisplayText = 'Ship Done' then else if wlcbStatus.DisplayText = 'Ship Done' then
begin begin
...@@ -235,10 +235,6 @@ begin ...@@ -235,10 +235,6 @@ begin
begin begin
dtpShipDue.Date := shipDue; dtpShipDue.Date := shipDue;
end end
else if wlcbStatus.DisplayText = 'Art Done' then
begin
dtpShipDue.Date := dtpDate.Date;
end
else if wlcbStatus.DisplayText = 'Ship Done' then else if wlcbStatus.DisplayText = 'Ship Done' then
begin begin
dtpShipDue.Date := shipDue; dtpShipDue.Date := shipDue;
......
...@@ -195,23 +195,9 @@ object FViewEditUser: TFViewEditUser ...@@ -195,23 +195,9 @@ object FViewEditUser: TFViewEditUser
ChildOrder = 19 ChildOrder = 19
ElementID = 'edtrights' ElementID = 'edtrights'
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
MaxLength = 11
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
end end
object cbAccess: TWebComboBox
Left = 346
Top = 90
Width = 145
Height = 23
ElementID = 'cbaccess'
HeightPercent = 100.000000000000000000
TabStop = False
WidthPercent = 100.000000000000000000
ItemIndex = -1
Items.Strings = (
'SALES'
'USER'
'ADMIN')
end
object edtQB: TWebEdit object edtQB: TWebEdit
Left = 346 Left = 346
Top = 62 Top = 62
...@@ -223,6 +209,33 @@ object FViewEditUser: TFViewEditUser ...@@ -223,6 +209,33 @@ object FViewEditUser: TFViewEditUser
HeightPercent = 100.000000000000000000 HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
end end
object cbAccess: TWebLookupComboBox
Left = 346
Top = 93
Width = 145
Height = 22
ElementID = 'cbaccess'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
ItemIndex = -1
LookupValues = <
item
Value = 'ADMIN'
DisplayText = 'Admin'
end
item
Value = 'USER'
DisplayText = 'User'
end
item
Value = 'SALES'
DisplayText = 'Sales User'
end
item
Value = 'QBUSR'
DisplayText = 'QB User'
end>
end
object XDataWebClient1: TXDataWebClient object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection Connection = DMConnection.ApiConnection
Left = 514 Left = 514
......
...@@ -29,9 +29,9 @@ type ...@@ -29,9 +29,9 @@ type
lblRights: TWebLabel; lblRights: TWebLabel;
edtRights: TWebEdit; edtRights: TWebEdit;
lblAccess: TWebLabel; lblAccess: TWebLabel;
cbAccess: TWebComboBox;
lblQB: TWebLabel; lblQB: TWebLabel;
edtQB: TWebEdit; edtQB: TWebEdit;
cbAccess: TWebLookupComboBox;
procedure WebFormCreate(Sender: TObject); procedure WebFormCreate(Sender: TObject);
procedure btnConfirmClick(Sender: TObject); procedure btnConfirmClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject); procedure btnCancelClick(Sender: TObject);
...@@ -90,7 +90,7 @@ begin ...@@ -90,7 +90,7 @@ begin
'&password=' + edtPassword.Text + '&password=' + edtPassword.Text +
'&status=' + BoolToStr(cbStatus.Checked) + '&status=' + BoolToStr(cbStatus.Checked) +
'&email=' + edtEmail.Text + '&email=' + edtEmail.Text +
'&access=' + cbAccess.Text + '&access=' + cbAccess.Value +
'&newuser=' + edtUsername.Text + '&newuser=' + edtUsername.Text +
'&rights=' + edtRights.Text + '&rights=' + edtRights.Text +
'&QB=' + edtQB.Text; '&QB=' + edtQB.Text;
...@@ -123,7 +123,7 @@ begin ...@@ -123,7 +123,7 @@ begin
'&password=' + edtPassword.Text + '&password=' + edtPassword.Text +
'&status=' + BoolToStr(cbStatus.Checked) + '&status=' + BoolToStr(cbStatus.Checked) +
'&email=' + edtEmail.Text + '&email=' + edtEmail.Text +
'&access=' + cbAccess.Text + '&access=' + cbAccess.Value +
'&newuser=' + edtUsername.Text + '&newuser=' + edtUsername.Text +
'&rights=' + edtRights.Text + '&rights=' + edtRights.Text +
'&QB=' + edtQB.Text; '&QB=' + edtQB.Text;
...@@ -176,7 +176,10 @@ begin ...@@ -176,7 +176,10 @@ begin
edtPassword.Text := 'hidden'; edtPassword.Text := 'hidden';
end; end;
edtEmail.Text := Email; edtEmail.Text := Email;
cbAccess.Text := Access; if Access = '' then
cbAccess.Value := 'USER'
else
cbAccess.Value := Access;
edtRights.Text := Rights; edtRights.Text := Rights;
edtQB.Text := QB; edtQB.Text := QB;
if Status = 'ACTIVE' then if Status = 'ACTIVE' then
......
object FViewUserProfile: TFViewUserProfile
Width = 604
Height = 434
CSSLibrary = cssBootstrap
ElementFont = efCSS
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
OnShow = WebFormShow
object WebLabel1: TWebLabel
Left = 24
Top = 24
Width = 55
Height = 13
Caption = 'User Profile'
ElementID = 'view.userprofile.title'
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
HeightPercent = 100.000000000000000000
ParentFont = False
Visible = False
WidthPercent = 100.000000000000000000
end
object WebLabel3: TWebLabel
Left = 41
Top = 60
Width = 38
Height = 14
Caption = 'User ID:'
ElementID = 'view.userprofile.form.lblUserID'
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Style = []
HeightPercent = 100.000000000000000000
ParentFont = False
WidthPercent = 100.000000000000000000
end
object WebLabel2: TWebLabel
Left = 8
Top = 143
Width = 71
Height = 14
Caption = 'Email Address:'
ElementID = 'view.userprofile.form.lblEmail'
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Style = []
HeightPercent = 100.000000000000000000
ParentFont = False
WidthPercent = 100.000000000000000000
end
object WebLabel4: TWebLabel
Left = 27
Top = 84
Width = 52
Height = 14
Caption = 'Username:'
ElementID = 'view.userprofile.form.lblUserName'
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Style = []
HeightPercent = 100.000000000000000000
ParentFont = False
WidthPercent = 100.000000000000000000
end
object WebLabel5: TWebLabel
Left = 30
Top = 117
Width = 49
Height = 14
Caption = 'Full Name:'
ElementID = 'view.userprofile.form.lblFullName'
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Style = []
HeightPercent = 100.000000000000000000
ParentFont = False
WidthPercent = 100.000000000000000000
end
object WebLabel6: TWebLabel
Left = 15
Top = 171
Width = 64
Height = 13
Caption = 'Access Type:'
ElementID = 'view.userprofile.form.lblAccessType'
ElementFont = efCSS
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object WebLabel7: TWebLabel
Left = 47
Top = 196
Width = 32
Height = 13
Caption = 'QB ID:'
ElementID = 'view.userprofile.form.lblQBID'
ElementFont = efCSS
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object WebDBEdit1: TWebDBEdit
Left = 90
Top = 168
Width = 121
Height = 22
ChildOrder = 13
ElementClassName = 'form-control'
ElementID = 'view.userprofile.form.edtAccessType'
ElementFont = efCSS
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
Text = 'WebDBEdit1'
WidthPercent = 100.000000000000000000
DataField = 'AType'
DataSource = wdsUser
end
object WebDBEdit2: TWebDBEdit
Left = 90
Top = 140
Width = 121
Height = 22
ChildOrder = 13
ElementClassName = 'form-control'
ElementID = 'view.userprofile.form.edtEmail'
ElementFont = efCSS
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
Text = 'WebDBEdit1'
WidthPercent = 100.000000000000000000
DataField = 'email_address'
DataSource = wdsUser
end
object WebDBEdit3: TWebDBEdit
Left = 90
Top = 114
Width = 121
Height = 22
ChildOrder = 13
ElementClassName = 'form-control'
ElementID = 'view.userprofile.form.edtFullName'
ElementFont = efCSS
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
Text = 'WebDBEdit1'
WidthPercent = 100.000000000000000000
DataField = 'full_name'
DataSource = wdsUser
end
object WebDBEdit4: TWebDBEdit
Left = 85
Top = 81
Width = 121
Height = 22
ChildOrder = 13
ElementClassName = 'form-control'
ElementID = 'view.userprofile.form.edtUsername'
ElementFont = efCSS
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
Text = 'WebDBEdit1'
WidthPercent = 100.000000000000000000
DataField = 'username'
DataSource = wdsUser
end
object WebDBEdit5: TWebDBEdit
Left = 85
Top = 57
Width = 121
Height = 22
ChildOrder = 13
ElementClassName = 'form-control'
ElementID = 'view.userprofile.form.edtUserID'
ElementFont = efCSS
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
Text = 'WebDBEdit1'
WidthPercent = 100.000000000000000000
DataField = 'userID'
DataSource = wdsUser
end
object WebDBEdit6: TWebDBEdit
Left = 90
Top = 196
Width = 121
Height = 22
ChildOrder = 13
ElementClassName = 'form-control'
ElementID = 'view.userprofile.form.edtQBID'
ElementFont = efCSS
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
Text = 'WebDBEdit1'
WidthPercent = 100.000000000000000000
DataField = 'QBID'
DataSource = wdsUser
end
object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection
Left = 359
Top = 52
end
object xdwdsUser: TXDataWebDataSet
Left = 314
Top = 216
object xdwdsUseruserID: TStringField
FieldName = 'userID'
end
object xdwdsUserusername: TStringField
FieldName = 'username'
end
object xdwdsUseremail_address: TStringField
FieldName = 'email_address'
end
object xdwdsUserQBID: TStringField
FieldName = 'QBID'
end
object xdwdsUserAType: TStringField
FieldName = 'Atype'
end
object xdwdsUserfull_name: TStringField
FieldName = 'full_name'
end
end
object wdsUser: TWebDataSource
AutoEdit = False
DataSet = xdwdsUser
Left = 422
Top = 262
end
end
<div class="container">
<!-- Profile form -->
<div class="row">
<div class="col-lg-8 col-xl-6 mx-auto">
<form id="userprofileform" class="needs-validation" role="form" autocomplete="off" novalidate>
<div class="mb-3">
<label id="view.userprofile.form.lblUserID"
for="view.userprofile.form.edtUserID"
class="form-label">User&nbsp;ID</label>
<input id="view.userprofile.form.edtUserID"
class="form-control"
readonly>
</div>
<div class="mb-3">
<label id="view.userprofile.form.lblUserName"
for="view.userprofile.form.edtUsername"
class="form-label">Username</label>
<input id="view.userprofile.form.edtUsername"
class="form-control">
</div>
<div class="mb-3">
<label id="view.userprofile.form.lblFullName"
for="view.userprofile.form.edtFullName"
class="form-label">Full&nbsp;Name</label>
<input id="view.userprofile.form.edtFullName"
class="form-control">
</div>
<div class="mb-3">
<label id="view.userprofile.form.lblEmail"
for="view.userprofile.form.edtEmail"
class="form-label">Email&nbsp;Address</label>
<input id="view.userprofile.form.edtEmail"
type="email"
class="form-control">
</div>
<div class="mb-3">
<label id="view.userprofile.form.lblAccessType"
for="view.userprofile.form.edtAccessType"
class="form-label">Email&nbsp;Address</label>
<input id="view.userprofile.form.edtAccessType"
type="email"
class="form-control">
</div>
<div class="mb-3">
<label id="view.userprofile.form.lblQBID"
for="view.userprofile.form.edtQBID"
class="form-label">Email&nbsp;Address</label>
<input id="view.userprofile.form.edtQBID"
type="email"
class="form-control">
</div>
</form>
</div>
</div>
</div>
unit View.UserProfile;
interface
uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls,
XData.Web.Client, WEBLib.ExtCtrls, DB, XData.Web.JsonDataset,
XData.Web.Dataset, XData.Web.Connection, Vcl.Forms, ConnectionModule,
WEBLib.Toast, WEBLib.DBCtrls;
type
TFViewUserProfile = class(TWebForm)
WebLabel1: TWebLabel;
WebLabel3: TWebLabel;
WebLabel2: TWebLabel;
WebLabel4: TWebLabel;
WebLabel5: TWebLabel;
XDataWebClient1: TXDataWebClient;
WebDBEdit1: TWebDBEdit;
WebDBEdit2: TWebDBEdit;
WebDBEdit3: TWebDBEdit;
WebDBEdit4: TWebDBEdit;
WebDBEdit5: TWebDBEdit;
WebDBEdit6: TWebDBEdit;
WebLabel6: TWebLabel;
WebLabel7: TWebLabel;
xdwdsUser: TXDataWebDataSet;
wdsUser: TWebDataSource;
xdwdsUseruserID: TStringField;
xdwdsUserusername: TStringField;
xdwdsUseremail_address: TStringField;
xdwdsUserQBID: TStringField;
xdwdsUserAType: TStringField;
xdwdsUserfull_name: TStringField;
procedure WebFormShow(Sender: TObject);
[async] procedure GetUser();
end;
var
FViewUserProfile: TFViewUserProfile;
implementation
uses
Auth.Service,
XData.Model.Classes,
Utils,
View.Main;
{$R *.dfm}
procedure TFViewUserProfile.WebFormShow(Sender: TObject);
begin
GetUser();
end;
procedure TFViewUserProfile.GetUser;
var
xdcResponse: TXDataClientResponse;
userList: TJSObject;
data: TJSArray;
user: TJSObject;
begin
try
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetUsers',
[JS.toString(AuthService.TokenPayload.Properties['user_name'])]));
userList := TJSObject(xdcResponse.Result);
data := TJSArray(userList['data']);
user := TJSObject(data[0]);
xdwdsUser.SetJsonData(user);
xdwdsUser.Open;
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal(E.ErrorResult.ErrorMessage);
end;
end;
end.
[Paths]
HtmlPath=C:\Projects\kgOrders\kgOrders\kgOrdersClient\TMSWeb\Debug
HtmlFile=index.html
DefaultURL=http://127.0.0.1:8000/webKGOrders
SingleInstance=0
Debug=0
DebugManager=C:\RADTools\TMS\Products\tms.webcore\Bin\Win32\TMSDBGManager.exe
URL=http://127.0.0.1:8000/$(ProjectName)
URLParams=
Browser=1
BrowserBin=
BrowserParams=
Electron=0
ElectronBuild=0
JSDebugger=0
...@@ -21,6 +21,11 @@ ...@@ -21,6 +21,11 @@
text-align: center; text-align: center;
} }
#tblPhoneGrid thead th:nth-child(20) {
font-size: 0.9rem !important;
font-weight: bold; /* Optional: keep it bold if shrinking makes it too thin */
}
input[type="text"] { input[type="text"] {
min-width: 50px; min-width: 50px;
max-width: 100%; max-width: 100%;
...@@ -42,11 +47,11 @@ input[type=number] { ...@@ -42,11 +47,11 @@ input[type=number] {
.changed-field { .changed-field {
border: 1px solid #ffc107 !important; border: 1px solid #FFFF00 !important;
} }
.changed-field-label { .changed-field-label {
background-color: #fff3cd; background-color: #FFFF00;
border-radius: 4px; border-radius: 4px;
padding: 2px 6px; padding: 2px 6px;
} }
......
...@@ -8,7 +8,6 @@ uses ...@@ -8,7 +8,6 @@ uses
App.Types in 'App.Types.pas', App.Types in 'App.Types.pas',
ConnectionModule in 'ConnectionModule.pas' {DMConnection: TWebDataModule}, ConnectionModule in 'ConnectionModule.pas' {DMConnection: TWebDataModule},
View.Login in 'View.Login.pas' {FViewLogin: TWebForm} {*.html}, View.Login in 'View.Login.pas' {FViewLogin: TWebForm} {*.html},
View.UserProfile in 'View.UserProfile.pas' {FViewUserProfile: TWebForm} {*.html},
View.ErrorPage in 'View.ErrorPage.pas' {FViewErrorPage: TWebForm} {*.html}, View.ErrorPage in 'View.ErrorPage.pas' {FViewErrorPage: TWebForm} {*.html},
App.Config in 'App.Config.pas', App.Config in 'App.Config.pas',
Paginator.Plugins in 'Paginator.Plugins.pas', Paginator.Plugins in 'Paginator.Plugins.pas',
...@@ -65,7 +64,10 @@ end; ...@@ -65,7 +64,10 @@ end;
procedure UnauthorizedAccessProc(AMessage: string); procedure UnauthorizedAccessProc(AMessage: string);
begin begin
DisplayLoginView(AMessage); if Pos('JWT', AMessage) > 0 then
DisplayLoginView('Login token expired! Please login again')
else
DisplayLoginView(AMessage);
end; end;
...@@ -89,27 +91,31 @@ begin ...@@ -89,27 +91,31 @@ begin
end end
else else
begin begin
asm // asm
var dlg = document.createElement("dialog"); // var dlg = document.createElement("dialog");
dlg.classList.add("shadow", "rounded", "border", "p-4"); // dlg.classList.add("shadow", "rounded", "border", "p-4");
dlg.style.maxWidth = "500px"; // dlg.style.maxWidth = "500px";
dlg.style.width = "90%"; // dlg.style.width = "90%";
dlg.style.fontFamily = "system-ui, sans-serif"; // dlg.style.fontFamily = "system-ui, sans-serif";
//
dlg.innerHTML = // dlg.innerHTML =
"<h5 class='fw-bold mb-3 text-danger'>kgOrders web app</h5>" + // "<h5 class='fw-bold mb-3 text-danger'>kgOrders web app</h5>" +
"<p class='mb-3' style='white-space: pre-wrap;'>" + ErrorMessage + "</p>" + // "<p class='mb-3' style='white-space: pre-wrap;'>" + ErrorMessage + "</p>" +
"<div class='text-end'>" + // "<div class='text-end'>" +
"<button id='refreshBtn' class='btn btn-primary'>Reload</button></div>"; // "<button id='refreshBtn' class='btn btn-primary'>Reload</button></div>";
//
document.body.appendChild(dlg); // document.body.appendChild(dlg);
dlg.showModal(); // dlg.showModal();
//
document.getElementById("refreshBtn").addEventListener("click", function () { // document.getElementById("refreshBtn").addEventListener("click", function () {
var base = location.origin + location.pathname; // var base = location.origin + location.pathname;
location.replace(base + "?ver=" + ClientVer + "&r=" + Date.now() + location.hash); // location.replace(base + "?ver=" + ClientVer + "&r=" + Date.now() + location.hash);
}); // });
end; // end;
if Pos('version', ErrorMessage) > 0 then
ShowMessage( ErrorMessage )
else
ShowMessage( 'Error connecting to kgOrdersServer' + sLineBreak + 'Please contact EM Systems support' );
end; end;
end); end);
end, end,
......
...@@ -99,9 +99,9 @@ ...@@ -99,9 +99,9 @@
<VerInfo_MajorVer>0</VerInfo_MajorVer> <VerInfo_MajorVer>0</VerInfo_MajorVer>
<VerInfo_MinorVer>9</VerInfo_MinorVer> <VerInfo_MinorVer>9</VerInfo_MinorVer>
<VerInfo_Release>8</VerInfo_Release> <VerInfo_Release>8</VerInfo_Release>
<TMSWebBrowser>1</TMSWebBrowser>
<TMSUseJSDebugger>2</TMSUseJSDebugger> <TMSUseJSDebugger>2</TMSUseJSDebugger>
<TMSWebSingleInstance>1</TMSWebSingleInstance> <TMSWebSingleInstance>1</TMSWebSingleInstance>
<TMSWebBrowser>5</TMSWebBrowser>
<TMSWebOutputPath>..\kgOrdersServer\bin\static</TMSWebOutputPath> <TMSWebOutputPath>..\kgOrdersServer\bin\static</TMSWebOutputPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''"> <PropertyGroup Condition="'$(Cfg_2)'!=''">
...@@ -133,10 +133,6 @@ ...@@ -133,10 +133,6 @@
<Form>FViewLogin</Form> <Form>FViewLogin</Form>
<DesignClass>TWebForm</DesignClass> <DesignClass>TWebForm</DesignClass>
</DCCReference> </DCCReference>
<DCCReference Include="View.UserProfile.pas">
<Form>FViewUserProfile</Form>
<DesignClass>TWebForm</DesignClass>
</DCCReference>
<DCCReference Include="View.ErrorPage.pas"> <DCCReference Include="View.ErrorPage.pas">
<Form>FViewErrorPage</Form> <Form>FViewErrorPage</Form>
<DesignClass>TWebForm</DesignClass> <DesignClass>TWebForm</DesignClass>
......
// Where the database is kept. Only used by Lookup.ServiceImpl to retrieve info
// from the data base and send it to the client.
// Author: ???
unit Api.Database; unit Api.Database;
interface interface
...@@ -136,7 +133,7 @@ uses ...@@ -136,7 +133,7 @@ uses
procedure TApiDatabase.DataModuleCreate(Sender: TObject); procedure TApiDatabase.DataModuleCreate(Sender: TObject);
begin begin
Logger.Log( 5, 'TApiDatabase.DataModuleCreate' ); Logger.Log( 5, 'TApiDatabase.DataModuleCreate' );
LoadDatabaseSettings( ucKG, 'kgOrdersServer.ini' ); LoadDatabaseSettings( ucKG );
try try
ucKG.Connect; ucKG.Connect;
except except
......
// Auth Database to verify logins
unit Auth.Database; unit Auth.Database;
interface interface
...@@ -50,24 +48,21 @@ uses ...@@ -50,24 +48,21 @@ uses
procedure TAuthDatabase.DataModuleCreate(Sender: TObject); procedure TAuthDatabase.DataModuleCreate(Sender: TObject);
begin begin
Logger.Log( 5, 'TAuthDatabase.DataModuleCreate' ); Logger.Log( 5, 'TAuthDatabase.DataModuleCreate' );
LoadDatabaseSettings( ucKG, 'kgOrdersServer.ini' );
try try
LoadDatabaseSettings( ucKG );
ucKG.Connect; ucKG.Connect;
except except
on E: Exception do on E: Exception do
begin begin
Logger.Log( 1, '--TAuthDatabase.DataModuleCreate -Error connecting to database: ' + E.Message ); Logger.Log( 1, '--TAuthDatabase.DataModuleCreate -Error connecting to database: ' + E.Message );
raise EXDataHttpException.Create(500, 'Error Connecting to database! Please try again later or contact a system admin!');
end; end;
end; end;
end; end;
procedure TAuthDatabase.DataModuleDestroy(Sender: TObject); procedure TAuthDatabase.DataModuleDestroy(Sender: TObject);
begin begin
ucKG.Connected := false; ucKG.Connected := false;
Logger.Log( 5, 'TAuthDatabase.DataModuleDestroy' ); Logger.Log( 5, 'TAuthDatabase.DataModuleDestroy' );
end; end;
end. end.
...@@ -49,22 +49,33 @@ procedure TAuthService.AfterConstruction; ...@@ -49,22 +49,33 @@ procedure TAuthService.AfterConstruction;
begin begin
inherited; inherited;
try try
Logger.Log(4, 'TAuthService.AfterConstruction');
authDB := TAuthDatabase.Create(nil); authDB := TAuthDatabase.Create(nil);
if not authDB.ucKG.Connected then
begin
Logger.Log(1, 'Unable to connect to the database: A KGOrders Server Error has occured!');
raise EXDataHttpException.Create(500, 'Unable to connect to the database: A KGOrders Server Error has occured!');
end;
except except
on E: Exception do on E: Exception do
begin begin
Logger.Log(1, 'Error when creating the Auth database: ' + E.Message); Logger.Log(1, 'Error creating the Auth database: ' + E.Message);
raise EXDataHttpException.Create(500, 'Unable to create Auth database: A KGOrders Server Error has occured!'); raise; //EXDataHttpException.Create(500, 'Unable to create Auth database: A KGOrders Server Error has occured!');
end; end;
end; end;
end; end;
procedure TAuthService.BeforeDestruction; procedure TAuthService.BeforeDestruction;
begin begin
authDB.Free; authDB.Free;
inherited; inherited;
end; end;
function TAuthService.VerifyVersion(clientVersion: string): TJSONObject; function TAuthService.VerifyVersion(clientVersion: string): TJSONObject;
var var
iniFile: TIniFile; iniFile: TIniFile;
...@@ -85,7 +96,7 @@ begin ...@@ -85,7 +96,7 @@ begin
Result.AddPair('error', Result.AddPair('error',
'webApp version mismatch' + sLineBreak + ' Client version: ' + clientVersion + 'webApp version mismatch' + sLineBreak + ' Client version: ' + clientVersion +
sLineBreak + ' Server version: ' + webClientVersion + sLineBreak + ' Server version: ' + webClientVersion +
sLineBreak + 'Please click button to clear cache and reload.'); sLineBreak + 'Please clear cache and reload.');
end; end;
finally finally
iniFile.Free; iniFile.Free;
...@@ -146,6 +157,7 @@ begin ...@@ -146,6 +157,7 @@ begin
end; end;
end; end;
function TAuthService.CheckUser(const user, password: string): Integer; function TAuthService.CheckUser(const user, password: string): Integer;
var var
SQL: string; SQL: string;
...@@ -175,6 +187,7 @@ begin ...@@ -175,6 +187,7 @@ begin
end; end;
end; end;
function TAuthService.QBAuthorize(code, realmId, state: string): string; function TAuthService.QBAuthorize(code, realmId, state: string): string;
var var
iniFile: TIniFile; iniFile: TIniFile;
...@@ -187,6 +200,7 @@ begin ...@@ -187,6 +200,7 @@ begin
Logger.Log(3, 'TAuthService.QBAuthorize - end - result: ' + result); Logger.Log(3, 'TAuthService.QBAuthorize - end - result: ' + result);
end; end;
function TAuthService.ExchangeQBAuthCode(code: string): string; function TAuthService.ExchangeQBAuthCode(code: string): string;
var var
iniFile: TIniFile; iniFile: TIniFile;
...@@ -280,6 +294,8 @@ begin ...@@ -280,6 +294,8 @@ begin
end; end;
end; end;
initialization initialization
RegisterServiceType(TAuthService); RegisterServiceType(TAuthService);
end. end.
unit Common.Ini;
interface
uses
System.SysUtils, System.IniFiles, Vcl.Forms;
type
TIniEntries = class
private
// [Settings]
FMemoLogLevel: Integer;
FFileLogLevel: Integer;
FLogFileNum: Integer;
// [Database]
FDBServer: string;
FDBPort: Integer;
FDBDatabase: string;
FDBUsername: string;
FDBPassword: string;
public
constructor Create;
// Properties
property memoLogLevel: Integer read FMemoLogLevel;
property fileLogLevel: Integer read FFileLogLevel;
property logFileNum: Integer read FLogFileNum;
property dbServer: string read FDBServer;
property dbPort: Integer read FDBPort;
property dbDatabase: string read FDBDatabase;
property dbUsername: string read FDBUsername;
property dbPassword: string read FDBPassword;
end;
procedure LoadIniEntries;
var
IniEntries: TIniEntries;
implementation
uses
Common.Logging;
procedure LoadIniEntries;
begin
Logger.Log(1, 'IniEntries global variable instantiated');
end;
{ TIniEntries }
constructor TIniEntries.Create;
var
iniFile: TIniFile;
begin
iniFile := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
try
// [Settings]
FMemoLogLevel := iniFile.ReadInteger('Settings', 'MemoLogLevel', 3);
FFileLogLevel := iniFile.ReadInteger('Settings', 'FileLogLevel', 3);
FLogFileNum := iniFile.ReadInteger('Settings', 'LogFileNum', 0);
Inc(FLogFileNum);
iniFile.WriteInteger( 'Settings', 'LogFileNum', FLogFileNum );
// [Database]
FDBServer := iniFile.ReadString('Database', 'Server', '');
FDBPort := iniFile.ReadInteger('Database', 'Port', 0);
FDBDatabase := iniFile.ReadString('Database', 'Database', 'kg_order_entry');
FDBUsername := iniFile.ReadString('Database', 'Username', 'root');
FDBPassword := iniFile.ReadString('Database', 'Password', 'emsys01');
finally
iniFile.Free;
end;
end;
initialization
IniEntries := TIniEntries.Create;
finalization
IniEntries.Free;
end.
...@@ -38,6 +38,7 @@ type ...@@ -38,6 +38,7 @@ type
state: string; state: string;
zip: string; zip: string;
contact: string; contact: string;
first_line: string;
end; end;
TQBCustomerItem = class TQBCustomerItem = class
...@@ -153,13 +154,14 @@ type ...@@ -153,13 +154,14 @@ type
TAddressItem = class TAddressItem = class
Public Public
ship_block: string; ship_id: string;
first_line: string;
shipping_address: string; shipping_address: string;
city: string; city: string;
state: string; state: string;
contact: string;
zip: string; zip: string;
ship_id: string; contact: string;
ship_block: string;
end; end;
TCustomerItem = class TCustomerItem = class
...@@ -182,6 +184,12 @@ type ...@@ -182,6 +184,12 @@ type
SHIPPING_ADDRESS_LIST: TList<TAddressItem>; SHIPPING_ADDRESS_LIST: TList<TAddressItem>;
end; end;
TCustomerResponse = class
Public
customer: TCustomerItem;
status: string;
end;
TCustomerList = class TCustomerList = class
Public Public
count: integer; count: integer;
...@@ -536,7 +544,7 @@ type ...@@ -536,7 +544,7 @@ type
function AddUser(userInfo: string): string; function AddUser(userInfo: string): string;
function AddItem(itemInfo: string): TJSONObject; function AddItem(itemInfo: string): TJSONObject;
function AddShippingAddress(Addressinfo: string): TJSONObject; function AddShippingAddress(Addressinfo: string): TCustomerResponse;
function DelShippingAddress(AddressID, CustomerID: string): TJSONObject; function DelShippingAddress(AddressID, CustomerID: string): TJSONObject;
function DelUser(username: string): string; function DelUser(username: string): string;
function DelOrder(orderID, orderType, UserID: string): TJSONObject; function DelOrder(orderID, orderType, UserID: string): TJSONObject;
......
...@@ -42,6 +42,7 @@ implementation ...@@ -42,6 +42,7 @@ implementation
uses uses
Common.Logging, Common.Logging,
Common.Ini,
Common.Config, Common.Config,
Sparkle.Utils, Sparkle.Utils,
Api.Database, Api.Database,
...@@ -110,50 +111,19 @@ end; ...@@ -110,50 +111,19 @@ end;
procedure TFMain.StartServers; procedure TFMain.StartServers;
// Reads from the ini file to figure out what IP the database is located at and
// whether or not Twilio automatic updates should be enabled
var var
iniFile: TIniFile; iniFile: TIniFile;
iniStr: string; iniStr: string;
bContinue: boolean; bContinue: boolean;
debugMode: boolean; devMode: boolean;
begin begin
// The version is centered when the app is running
Logger.Log( 1, '*******************************************************' );
Logger.Log( 1, '* kgOrdersServer *' );
Logger.Log(1, Format(' Version: %s ', [FMain.ExeInfo1.FileVersion]));
Logger.Log( 1, '* Developed by EM Systems, Inc. *' );
Logger.Log( 1, '*******************************************************' );
Logger.Log( 1, '' );
bContinue := True; bContinue := True;
iniFile := TIniFile.Create( ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini' ); iniFile := TIniFile.Create( ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini' );
try try
Logger.Log( 1, 'iniFile: ' + ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini' ); Logger.Log( 1, 'iniFile: ' + ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini' );
debugMode := iniFile.ReadBool( 'Settings', 'DebugMode', True ); devMode := iniFile.ReadBool( 'Settings', 'devMode', True );
Logger.Log( 1, 'debugMode: ' + BoolToStr(debugMode, True) ); Logger.Log( 1, 'devMode: ' + BoolToStr(devMode, True) );
Logger.Log( 1, 'LogLevels are displayed here. They were set in kgOrdersServer.dpr, it executes first' );
Logger.Log(1, '--- Settings ---');
iniStr := iniFile.ReadString( 'Settings', 'MemoLogLevel', '' );
if iniStr.IsEmpty then
Logger.Log( 1, '--Settings->MemoLogLevel: Entry not found - default: 3' )
else
Logger.Log( 1, '--Settings->MemoLogLevel: ' + iniStr );
iniStr := iniFile.ReadString( 'Settings', 'FileLogLevel', '' );
if iniStr.IsEmpty then
Logger.Log( 1, '--Settings->FileLogLevel: Entry not found - default: 4' )
else
Logger.Log( 1, '--Settings->FileLogLevel: ' + iniStr );
Logger.Log( 1, '' );
iniStr := iniFile.ReadString( 'Settings', 'LogFileNum', '' );
if iniStr.IsEmpty then
Logger.Log( 1, '--Settings->LogFileNum: Entry not found' )
else
Logger.Log( 1, '--Settings->LogFileNum: ' + IntToStr(StrToInt(iniStr) - 1) );
iniStr := iniFile.ReadString( 'Settings', 'webClientVersion', '' ); iniStr := iniFile.ReadString( 'Settings', 'webClientVersion', '' );
if iniStr.IsEmpty then if iniStr.IsEmpty then
...@@ -172,25 +142,25 @@ begin ...@@ -172,25 +142,25 @@ begin
bContinue := False; bContinue := False;
end end
else else
Logger.Log( 1, '----Database->Server: ' + iniStr ); Logger.Log( 1, '----Database->Server: ini entry: ' + iniStr );
iniStr := iniFile.ReadString('Database', 'Database', ''); iniStr := iniFile.ReadString('Database', 'Database', '');
if iniStr.IsEmpty then if iniStr.IsEmpty then
Logger.Log( 1, '----Database->Database: ini entry not found - default: kg_order_entry' ) Logger.Log( 1, '----Database->Database: ini entry not found - default: ' + iniEntries.dbDatabase )
else else
Logger.Log( 1, '----Database->Database: ini entry: ' + iniStr ); Logger.Log( 1, '----Database->Database: ini entry: ' + iniStr );
iniStr := iniFile.ReadString('Database', 'Username', ''); iniStr := iniFile.ReadString('Database', 'Username', '');
if iniStr.IsEmpty then if iniStr.IsEmpty then
Logger.Log( 1, '----Database->Username: Entry not found - default: root' ) Logger.Log( 1, '----Database->Username: Entry not found - default: ' + iniEntries.dbUsername )
else else
Logger.Log( 1, '----Database->Username: ' + iniStr ); Logger.Log( 1, '----Database->Username: ini entry: ' + iniStr );
iniStr := iniFile.ReadString('Database', 'Password', ''); iniStr := iniFile.ReadString('Database', 'Password', '');
if iniStr.IsEmpty then if iniStr.IsEmpty then
Logger.Log( 1, '----Database->Password: Entry not found - default: xxxxxx' ) Logger.Log( 1, '----Database->Password: Entry not found - default: xxxxxxxx' )
else else
Logger.Log( 1, '----Database->Password: xxxxxxxx' ); Logger.Log( 1, '----Database->Password: ini entry: xxxxxxxx' );
Logger.Log(1, '---Quickbooks---'); Logger.Log(1, '---Quickbooks---');
...@@ -198,7 +168,7 @@ begin ...@@ -198,7 +168,7 @@ begin
if iniStr.IsEmpty then if iniStr.IsEmpty then
Logger.Log( 1, '--Quickbooks->CompanyID: Entry not found' ) Logger.Log( 1, '--Quickbooks->CompanyID: Entry not found' )
else else
Logger.Log( 1, '--Quickbooks->CompanyID: Entry found' ); Logger.Log( 1, '--Quickbooks->CompanyID: ini Entry: found' );
iniStr := IniFile.ReadString( 'Quickbooks', 'ClientID', '' ); iniStr := IniFile.ReadString( 'Quickbooks', 'ClientID', '' );
if iniStr.IsEmpty then if iniStr.IsEmpty then
...@@ -251,9 +221,10 @@ begin ...@@ -251,9 +221,10 @@ begin
else else
begin begin
Logger.Log( 1, 'ini configuration error: Existing program!' ); Logger.Log( 1, 'ini configuration error: Existing program!' );
if debugMode then if devMode then
MessageDlg( 'ini configuration error: Existing program!', mtConfirmation, [mbOk], 0 ); MessageDlg( 'ini configuration error!', mtConfirmation, [mbOk], 0 )
Close(); else
Close();
end; end;
end; end;
......
...@@ -138,7 +138,7 @@ uses ...@@ -138,7 +138,7 @@ uses
procedure TrptOrderCorrugated.DataModuleCreate(Sender: TObject); procedure TrptOrderCorrugated.DataModuleCreate(Sender: TObject);
begin begin
Logger.Log( 5, 'TrptOrderCorrugated.DataModuleCreate' ); Logger.Log( 5, 'TrptOrderCorrugated.DataModuleCreate' );
LoadDatabaseSettings( ucKG, 'kgOrdersServer.ini' ); LoadDatabaseSettings( ucKG );
try try
ucKG.Connect; ucKG.Connect;
except except
...@@ -156,15 +156,15 @@ var ...@@ -156,15 +156,15 @@ var
colorArray: TJSONArray; colorArray: TJSONArray;
colorsObject, colorObject: TJSONObject; colorsObject, colorObject: TJSONObject;
colorsString: string; colorsString: string;
i: Integer; i, maxColors: Integer;
begin begin
logger.Log( 5, 'TrptOrderCorrugated.PopulateColorTable' ); logger.Log( 5, 'TrptOrderCorrugated.PopulateColorTable' );
maxColors := 13;
colorsString := uqOrderCorrugated.FieldByName('colors_colors').AsString; colorsString := uqOrderCorrugated.FieldByName('colors_colors').AsString;
colorsObject := TJSONObject.ParseJSONValue(colorsString) as TJSONObject; colorsObject := TJSONObject.ParseJSONValue(colorsString) as TJSONObject;
colorArray := TJSONArray(colorsObject.GetValue<TJSONArray>('items')); colorArray := TJSONArray(colorsObject.GetValue<TJSONArray>('items'));
for i := 0 to colorArray.Count - 1 do for i := 0 to maxColors - 1 do
begin begin
row := frxOrderCorrugated.FindObject('ColorRow' + IntToStr(i + 1)) as TfrxCustomTableRow; row := frxOrderCorrugated.FindObject('ColorRow' + IntToStr(i + 1)) as TfrxCustomTableRow;
colorObject := colorArray.Items[i] as TJSONObject; colorObject := colorArray.Items[i] as TJSONObject;
......
...@@ -50,6 +50,134 @@ object rptOrderCutting: TrptOrderCutting ...@@ -50,6 +50,134 @@ object rptOrderCutting: TrptOrderCutting
DataSetOptions = [] DataSetOptions = []
Left = 444 Left = 444
Top = 206 Top = 206
FieldDefs = <
item
FieldName = 'ORDER_ID'
end
item
FieldName = 'COMPANY_ID'
end
item
FieldName = 'USER_ID'
end
item
FieldName = 'ORDER_DATE'
FieldType = fftDateTime
end
item
FieldName = 'staff_fields_order_date'
FieldType = fftDateTime
end
item
FieldName = 'staff_fields_proof_date'
FieldType = fftDateTime
end
item
FieldName = 'staff_fields_ship_date'
FieldType = fftDateTime
end
item
FieldName = 'staff_fields_ship_via'
FieldType = fftString
Size = 45
end
item
FieldName = 'staff_fields_quantity'
FieldType = fftString
end
item
FieldName = 'staff_fields_price'
FieldType = fftString
end
item
FieldName = 'staff_fields_invoice_to'
FieldType = fftString
Size = 128
end
item
FieldName = 'staff_fields_ship_to'
FieldType = fftString
Size = 128
end
item
FieldName = 'staff_fields_po_number'
FieldType = fftString
Size = 16
end
item
FieldName = 'staff_fields_job_name'
FieldType = fftString
Size = 45
end
item
FieldName = 'staff_fields_quickbooks_item'
FieldType = fftString
Size = 45
end
item
FieldName = 'general_special_instructions'
FieldType = fftString
Size = 2048
end
item
FieldName = 'ORDER_STATUS'
FieldType = fftString
Size = 50
end
item
FieldName = 'ORDER_ID_1'
end
item
FieldName = 'COMPANY_ID_1'
end
item
FieldName = 'ORDER_TYPE'
FieldType = fftString
Size = 45
end
item
FieldName = 'ORDER_DATE_1'
FieldType = fftDateTime
end
item
FieldName = 'PRICE'
end
item
FieldName = 'JOB_NAME'
FieldType = fftString
Size = 128
end
item
FieldName = 'USER_ID_1'
end
item
FieldName = 'LOCATION'
FieldType = fftString
Size = 16
end
item
FieldName = 'IN_QB'
FieldType = fftString
end
item
FieldName = 'QB_ORDER_NUM'
FieldType = fftString
Size = 30
end
item
FieldName = 'QB_ESTIMATE_ID'
FieldType = fftString
Size = 30
end
item
FieldName = 'QB_ORDER_USER'
FieldType = fftString
Size = 60
end
item
FieldName = 'QB_CREATE_DATE'
FieldType = fftDateTime
end>
end end
object frxOrderCutting: TfrxReport object frxOrderCutting: TfrxReport
Version = '2026.1.7' Version = '2026.1.7'
...@@ -62,7 +190,7 @@ object rptOrderCutting: TrptOrderCutting ...@@ -62,7 +190,7 @@ object rptOrderCutting: TrptOrderCutting
PrintOptions.Printer = 'Default' PrintOptions.Printer = 'Default'
PrintOptions.PrintOnSheet = 0 PrintOptions.PrintOnSheet = 0
ReportOptions.CreateDate = 45691.397221759300000000 ReportOptions.CreateDate = 45691.397221759300000000
ReportOptions.LastChange = 45707.397776377300000000 ReportOptions.LastChange = 46143.643605335640000000
ScriptLanguage = 'PascalScript' ScriptLanguage = 'PascalScript'
ScriptText.Strings = ( ScriptText.Strings = (
'begin' 'begin'
...@@ -580,7 +708,7 @@ object rptOrderCutting: TrptOrderCutting ...@@ -580,7 +708,7 @@ object rptOrderCutting: TrptOrderCutting
end end
object SpecialInstructions: TfrxTableObject object SpecialInstructions: TfrxTableObject
AllowVectorExport = True AllowVectorExport = True
Left = 11.918845190000000000 Left = 8.139315190000000000
Top = 238.110390390000000000 Top = 238.110390390000000000
object TableColumn61: TfrxTableColumn object TableColumn61: TfrxTableColumn
Width = 723.779527559055000000 Width = 723.779527559055000000
...@@ -618,7 +746,7 @@ object rptOrderCutting: TrptOrderCutting ...@@ -618,7 +746,7 @@ object rptOrderCutting: TrptOrderCutting
DataSetName = 'frxDBOrderCutting' DataSetName = 'frxDBOrderCutting'
Font.Charset = DEFAULT_CHARSET Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack Font.Color = clBlack
Font.Height = -11 Font.Height = -12
Font.Name = 'Arial' Font.Name = 'Arial'
Font.Style = [] Font.Style = []
Frame.Typ = [ftLeft, ftRight, ftTop, ftBottom] Frame.Typ = [ftLeft, ftRight, ftTop, ftBottom]
......
...@@ -69,7 +69,7 @@ uses ...@@ -69,7 +69,7 @@ uses
procedure TrptOrderCutting.DataModuleCreate(Sender: TObject); procedure TrptOrderCutting.DataModuleCreate(Sender: TObject);
begin begin
Logger.Log( 5, 'TrptOrderCutting.DataModuleCreate' ); Logger.Log( 5, 'TrptOrderCutting.DataModuleCreate' );
LoadDatabaseSettings( ucKG, 'kgOrdersServer.ini' ); LoadDatabaseSettings( ucKG );
try try
ucKG.Connect; ucKG.Connect;
except except
......
...@@ -401,11 +401,10 @@ object rptOrderList: TrptOrderList ...@@ -401,11 +401,10 @@ object rptOrderList: TrptOrderList
Left = 941.480349130000000000 Left = 941.480349130000000000
Top = 7.559060000000000000 Top = 7.559060000000000000
Width = 45.354330710000000000 Width = 45.354330710000000000
Height = 30.236220472440900000 Height = 30.236220470000000000
StretchMode = smActualHeight StretchMode = smActualHeight
ContentScaleOptions.Constraints.MaxIterationValue = 0 ContentScaleOptions.Constraints.MaxIterationValue = 0
ContentScaleOptions.Constraints.MinIterationValue = 0 ContentScaleOptions.Constraints.MinIterationValue = 0
DataField = 'QB_REF_NUM'
DataSet = frxDBOrders DataSet = frxDBOrders
DataSetName = 'frxDBOrders' DataSetName = 'frxDBOrders'
Font.Charset = DEFAULT_CHARSET Font.Charset = DEFAULT_CHARSET
...@@ -415,7 +414,7 @@ object rptOrderList: TrptOrderList ...@@ -415,7 +414,7 @@ object rptOrderList: TrptOrderList
Font.Style = [] Font.Style = []
Frame.Typ = [] Frame.Typ = []
Memo.UTF8W = ( Memo.UTF8W = (
'[frxDBOrders."QB_REF_NUM"]') '[frxDBOrders."QB_ORDER_NUM"]')
ParentFont = False ParentFont = False
end end
object Memo56: TfrxMemoView object Memo56: TfrxMemoView
...@@ -1217,11 +1216,6 @@ object rptOrderList: TrptOrderList ...@@ -1217,11 +1216,6 @@ object rptOrderList: TrptOrderList
FieldName = 'PRICE' FieldName = 'PRICE'
Required = True Required = True
end end
object uqOrdersQB_REF_NUM: TStringField
FieldName = 'QB_REF_NUM'
ReadOnly = True
Size = 24
end
object uqOrdersCOLORS: TStringField object uqOrdersCOLORS: TStringField
FieldKind = fkCalculated FieldKind = fkCalculated
FieldName = 'COLORS' FieldName = 'COLORS'
...@@ -1271,6 +1265,10 @@ object rptOrderList: TrptOrderList ...@@ -1271,6 +1265,10 @@ object rptOrderList: TrptOrderList
object uqOrdersORDER_DATE: TDateField object uqOrdersORDER_DATE: TDateField
FieldName = 'ORDER_DATE' FieldName = 'ORDER_DATE'
end end
object uqOrdersQB_ORDER_NUM: TStringField
FieldName = 'QB_ORDER_NUM'
Size = 50
end
end end
object frxDBOrders: TfrxDBDataset object frxDBOrders: TfrxDBDataset
UserName = 'frxDBOrders' UserName = 'frxDBOrders'
...@@ -1280,6 +1278,126 @@ object rptOrderList: TrptOrderList ...@@ -1280,6 +1278,126 @@ object rptOrderList: TrptOrderList
DataSetOptions = [] DataSetOptions = []
Left = 444 Left = 444
Top = 232 Top = 232
FieldDefs = <
item
FieldName = 'ORDER_ID'
end
item
FieldName = 'Loc'
FieldType = fftString
Size = 16
end
item
FieldName = 'COMPANY_NAME'
FieldType = fftString
Size = 90
end
item
FieldName = 'JOB_NAME'
FieldType = fftString
Size = 128
end
item
FieldName = 'ORDER_TYPE'
FieldType = fftString
Size = 45
end
item
FieldName = 'PROOF_DUE'
FieldType = fftDateTime
end
item
FieldName = 'PROOF_DONE'
FieldType = fftDateTime
end
item
FieldName = 'ART_DUE'
FieldType = fftDateTime
end
item
FieldName = 'ART_DONE'
FieldType = fftDateTime
end
item
FieldName = 'PLATE_DUE'
FieldType = fftDateTime
end
item
FieldName = 'PLATE_DONE'
FieldType = fftDateTime
end
item
FieldName = 'MOUNT_DUE'
FieldType = fftDateTime
end
item
FieldName = 'MOUNT_DONE'
FieldType = fftDateTime
end
item
FieldName = 'SHIP_DUE'
FieldType = fftDateTime
end
item
FieldName = 'SHIP_DONE'
FieldType = fftDateTime
end
item
FieldName = 'PRICE'
end
item
FieldName = 'COLORS'
FieldType = fftString
end
item
FieldName = 'po_number'
FieldType = fftString
Size = 16
end
item
FieldName = 'quickbooks_item'
FieldType = fftString
Size = 45
end
item
FieldName = 'NEW_ORDER_DATE'
FieldType = fftString
Size = 20
end
item
FieldName = 'NEW_PROOF_DONE'
FieldType = fftString
Size = 20
end
item
FieldName = 'NEW_ART_DONE'
FieldType = fftString
Size = 20
end
item
FieldName = 'NEW_PLATE_DONE'
FieldType = fftString
Size = 20
end
item
FieldName = 'NEW_MOUNT_DONE'
FieldType = fftString
Size = 20
end
item
FieldName = 'NEW_SHIP_DONE'
FieldType = fftString
Size = 20
end
item
FieldName = 'ORDER_DATE'
FieldType = fftDateTime
end
item
FieldName = 'QB_ORDER_NUM'
FieldType = fftString
Size = 50
end>
end end
object uqColors: TUniQuery object uqColors: TUniQuery
Connection = ucKG Connection = ucKG
......
...@@ -30,7 +30,6 @@ type ...@@ -30,7 +30,6 @@ type
uqOrdersSHIP_DUE: TDateField; uqOrdersSHIP_DUE: TDateField;
uqOrdersSHIP_DONE: TDateTimeField; uqOrdersSHIP_DONE: TDateTimeField;
uqOrdersPRICE: TFloatField; uqOrdersPRICE: TFloatField;
uqOrdersQB_REF_NUM: TStringField;
uqOrdersCOLORS: TStringField; uqOrdersCOLORS: TStringField;
uqColors: TUniQuery; uqColors: TUniQuery;
uqOrderspo_number: TStringField; uqOrderspo_number: TStringField;
...@@ -42,6 +41,7 @@ type ...@@ -42,6 +41,7 @@ type
uqOrdersNEW_MOUNT_DONE: TStringField; uqOrdersNEW_MOUNT_DONE: TStringField;
uqOrdersNEW_SHIP_DONE: TStringField; uqOrdersNEW_SHIP_DONE: TStringField;
uqOrdersORDER_DATE: TDateField; uqOrdersORDER_DATE: TDateField;
uqOrdersQB_ORDER_NUM: TStringField;
procedure DataModuleCreate(Sender: TObject); procedure DataModuleCreate(Sender: TObject);
procedure uqOrdersCalcFields(DataSet: TDataSet); procedure uqOrdersCalcFields(DataSet: TDataSet);
...@@ -68,7 +68,7 @@ uses ...@@ -68,7 +68,7 @@ uses
procedure TrptOrderList.DataModuleCreate(Sender: TObject); procedure TrptOrderList.DataModuleCreate(Sender: TObject);
begin begin
Logger.Log( 5, 'TrptOrderList.DataModuleCreate' ); Logger.Log( 5, 'TrptOrderList.DataModuleCreate' );
LoadDatabaseSettings( ucKG, 'kgOrdersServer.ini' ); LoadDatabaseSettings( ucKG );
try try
ucKG.Connect; ucKG.Connect;
except except
......
...@@ -137,7 +137,7 @@ uses ...@@ -137,7 +137,7 @@ uses
procedure TrptOrderWeb.DataModuleCreate(Sender: TObject); procedure TrptOrderWeb.DataModuleCreate(Sender: TObject);
begin begin
Logger.Log( 5, 'TrptOrderWeb.DataModuleCreate' ); Logger.Log( 5, 'TrptOrderWeb.DataModuleCreate' );
LoadDatabaseSettings( ucKG, 'kgOrdersServer.ini' ); LoadDatabaseSettings( ucKG );
try try
ucKG.Connect; ucKG.Connect;
except except
...@@ -155,15 +155,16 @@ var ...@@ -155,15 +155,16 @@ var
colorArray: TJSONArray; colorArray: TJSONArray;
colorsObject, colorObject: TJSONObject; colorsObject, colorObject: TJSONObject;
colorsString: string; colorsString: string;
i: Integer; i, maxColors: Integer;
begin begin
maxColors := 10;
logger.Log( 5, 'TrptOrderWeb.PopulateColorTable' ); logger.Log( 5, 'TrptOrderWeb.PopulateColorTable' );
colorsString := uqOrderWeb.FieldByName('quantity_and_colors_qty_colors').AsString; colorsString := uqOrderWeb.FieldByName('quantity_and_colors_qty_colors').AsString;
colorsObject := TJSONObject.ParseJSONValue(colorsString) as TJSONObject; colorsObject := TJSONObject.ParseJSONValue(colorsString) as TJSONObject;
colorArray := TJSONArray(colorsObject.GetValue<TJSONArray>('items')); colorArray := TJSONArray(colorsObject.GetValue<TJSONArray>('items'));
for i := 0 to colorArray.Count - 1 do for i := 0 to maxColors - 1 do
begin begin
row := frxOrderWeb.FindObject('ColorRow' + IntToStr(i + 1)) as TfrxCustomTableRow; row := frxOrderWeb.FindObject('ColorRow' + IntToStr(i + 1)) as TfrxCustomTableRow;
colorObject := colorArray.Items[i] as TJSONObject; colorObject := colorArray.Items[i] as TJSONObject;
......
...@@ -3,32 +3,25 @@ unit uLibrary; ...@@ -3,32 +3,25 @@ unit uLibrary;
interface interface
uses uses
System.Classes, Uni; Common.Ini,
System.Classes,
Uni;
procedure LoadDatabaseSettings( uc: TUniConnection; iniFilename: string ); procedure LoadDatabaseSettings(uc: TUniConnection);
procedure DoQuery( uq: TUniQuery; sql: string ); procedure DoQuery(uq: TUniQuery; sql: string);
implementation implementation
uses uses
System.SysUtils, System.SysUtils,
System.IniFiles,
Vcl.Forms,
Data.DB; Data.DB;
procedure LoadDatabaseSettings( uc: TUniConnection; iniFilename: string ); procedure LoadDatabaseSettings(uc: TUniConnection);
var
iniFile: TIniFile;
begin begin
iniFile := TIniFile.Create( ExtractFilePath(Application.ExeName) + iniFilename ); uc.Server := iniEntries.dbServer;
try uc.Database := iniEntries.dbDatabase;
uc.Server := iniFile.ReadString('Database', 'Server', ''); uc.Username := iniEntries.dbUsername;
uc.Database := iniFile.ReadString('Database', 'Database', 'kg_order_entry'); uc.Password := iniEntries.dbPassword;
uc.Username := iniFile.ReadString('Database', 'Username', 'root');
uc.Password := iniFile.ReadString('Database', 'Password', 'emsys01');
finally
iniFile.Free;
end;
end; end;
procedure DoQuery(uq: TUniQuery; sql: string); procedure DoQuery(uq: TUniQuery; sql: string);
......
...@@ -26,10 +26,11 @@ uses ...@@ -26,10 +26,11 @@ uses
rOrderCorrugated in 'Source\rOrderCorrugated.pas' {rptOrderCorrugated: TDataModule}, rOrderCorrugated in 'Source\rOrderCorrugated.pas' {rptOrderCorrugated: TDataModule},
rOrderWeb in 'Source\rOrderWeb.pas' {rptOrderWeb: TDataModule}, rOrderWeb in 'Source\rOrderWeb.pas' {rptOrderWeb: TDataModule},
rOrderCutting in 'Source\rOrderCutting.pas' {rptOrderCutting: TDataModule}, rOrderCutting in 'Source\rOrderCutting.pas' {rptOrderCutting: TDataModule},
qbAPI in 'Source\qbAPI.pas' {fQB}; qbAPI in 'Source\qbAPI.pas' {fQB},
Common.Ini in 'Source\Common.Ini.pas';
type type
TMemoLogAppender = class( TInterfacedObject, ILogAppender ) TMemoLogAppender = class(TInterfacedObject, ILogAppender)
private private
FLogLevel: Integer; FLogLevel: Integer;
FLogMemo: TMemo; FLogMemo: TMemo;
...@@ -40,18 +41,19 @@ type ...@@ -40,18 +41,19 @@ type
procedure Send(logLevel: Integer; Log: ILog); procedure Send(logLevel: Integer; Log: ILog);
end; end;
TFileLogAppender = class( TInterfacedObject, ILogAppender ) TFileLogAppender = class(TInterfacedObject, ILogAppender)
private private
FLogLevel: Integer; FLogLevel: Integer;
FLogFile: string; FLogFile: string;
FCriticalSection: TCriticalSection; FCriticalSection: TCriticalSection;
public public
constructor Create(ALogLevel: Integer; AFilename: string); constructor Create(ALogLevel: Integer; AFilename: string; AFileNum: Integer);
destructor Destroy; override; destructor Destroy; override;
procedure Send(logLevel: Integer; Log: ILog); procedure Send(logLevel: Integer; Log: ILog);
end; end;
{ TMemoLogAppender } { TMemoLogAppender }
constructor TMemoLogAppender.Create(ALogLevel: Integer; ALogMemo: TMemo); constructor TMemoLogAppender.Create(ALogLevel: Integer; ALogMemo: TMemo);
begin begin
FLogLevel := ALogLevel; FLogLevel := ALogLevel;
...@@ -67,34 +69,33 @@ end; ...@@ -67,34 +69,33 @@ end;
procedure TMemoLogAppender.Send(logLevel: Integer; Log: ILog); procedure TMemoLogAppender.Send(logLevel: Integer; Log: ILog);
var var
FormattedMessage: string; logMsg: string;
LogTime: TDateTime; logTime: TDateTime;
LogMsg: string; formattedMessage: string;
begin begin
FCriticalSection.Acquire; FCriticalSection.Acquire;
try try
LogTime := Now; logTime := Now;
FormattedMessage := FormatDateTime('[yyyy-mm-dd HH:nn:ss.zzz]', LogTime); formattedMessage := FormatDateTime('[yyyy-mm-dd HH:nn:ss.zzz]', logTime);
LogMsg := Log.GetMessage; logMsg := Log.GetMessage;
if LogMsg.IsEmpty then if logMsg.IsEmpty then
FormattedMessage := '' formattedMessage := ''
else else
FormattedMessage := FormattedMessage + '[' + IntToStr(logLevel) +'] ' + LogMsg; formattedMessage := formattedMessage + '[' + IntToStr(logLevel) + '] ' + logMsg;
if logLevel <= FLogLevel then if logLevel <= FLogLevel then
FLogMemo.Lines.Add( FormattedMessage ); FLogMemo.Lines.Add(formattedMessage);
finally finally
FCriticalSection.Release; FCriticalSection.Release;
end; end;
end; end;
{ TFileLogAppender } { TFileLogAppender }
constructor TFileLogAppender.Create(ALogLevel: integer; AFilename: string);
constructor TFileLogAppender.Create(ALogLevel: integer; AFilename: string; AFileNum: integer);
var var
iniFile: TIniFile; iniFile: TIniFile;
fileNum: integer;
logsDir: string; logsDir: string;
begin begin
FLogLevel := ALogLevel; FLogLevel := ALogLevel;
...@@ -103,14 +104,7 @@ begin ...@@ -103,14 +104,7 @@ begin
if not DirectoryExists(logsDir) then if not DirectoryExists(logsDir) then
CreateDir(logsDir); CreateDir(logsDir);
iniFile := TIniFile.Create( ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini' ); FLogFile := logsDir + AFilename + Format( '%.4d', [AFileNum] ) + '.log';
try
fileNum := iniFile.ReadInteger( 'Settings', 'LogFileNum', 0 );
FLogFile := logsDir + AFilename + Format( '%.4d', [fileNum] ) + '.log';
iniFile.WriteInteger( 'Settings', 'LogFileNum', fileNum + 1 );
finally
iniFile.Free;
end;
end; end;
destructor TFileLogAppender.Destroy; destructor TFileLogAppender.Destroy;
...@@ -119,14 +113,16 @@ begin ...@@ -119,14 +113,16 @@ begin
inherited; inherited;
end; end;
procedure TFileLogAppender.Send(logLevel: integer; Log: ILog); procedure TFileLogAppender.Send(logLevel: Integer; Log: ILog);
var var
formattedMessage: string; logFile: TextFile;
logTime: TDateTime;
logMsg: string; logMsg: string;
txtFile: TextFile; logTime: TDateTime;
formattedMessage: string;
begin begin
if logLevel > FLogLevel then
Exit;
FCriticalSection.Acquire; FCriticalSection.Acquire;
try try
logTime := Now; logTime := Now;
...@@ -136,18 +132,18 @@ begin ...@@ -136,18 +132,18 @@ begin
if logMsg.IsEmpty then if logMsg.IsEmpty then
formattedMessage := '' formattedMessage := ''
else else
formattedMessage := formattedMessage + '[' + IntToStr(logLevel) +'] ' + logMsg; formattedMessage := formattedMessage + '[' + IntToStr(logLevel) + '] ' + logMsg;
AssignFile( logFile, FLogFile );
if FileExists(FLogFile) then
Append(logFile)
else
Rewrite(logFile);
try try
AssignFile( txtFile, FLogFile ); Writeln(logFile, formattedMessage);
if FileExists(FLogFile) then
Append( txtFile )
else
ReWrite( txtFile );
if logLevel <= FLogLevel then
WriteLn( txtFile, formattedMessage );
finally finally
CloseFile(txtFile); CloseFile(logFile);
end; end;
finally finally
FCriticalSection.Release; FCriticalSection.Release;
...@@ -157,23 +153,55 @@ end; ...@@ -157,23 +153,55 @@ end;
{$R *.res} {$R *.res}
var var
iniFilename: string;
iniFile: TIniFile; iniFile: TIniFile;
MemoLogLevel: Integer; iniStr: string;
FileLogLevel: Integer;
begin begin
ReportMemoryLeaksOnShutdown := True; ReportMemoryLeaksOnShutdown := True;
Application.Initialize; Application.Initialize;
Application.MainFormOnTaskbar := True; Application.MainFormOnTaskbar := True;
Application.CreateForm(TFMain, FMain); Application.CreateForm(TFMain, FMain);
iniFile := TIniFile.Create( ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini' ); iniFilename := ChangeFileExt( Application.ExeName, '.ini' );
iniFile := TIniFile.Create( iniFilename );
try try
MemoLogLevel := iniFile.ReadInteger( 'Settings', 'MemoLogLevel', 3 ); Logger.AddAppender( TMemoLogAppender.Create(iniEntries.memoLogLevel, FMain.memoinfo) );
FileLogLevel := iniFile.ReadInteger( 'Settings', 'FileLogLevel', 4 ); Logger.AddAppender( TFileLogAppender.Create(iniEntries.fileLogLevel, 'emT3XDataServer', iniEntries.logFileNum) );
Logger.Log( 1, '*******************************************************' );
Logger.Log( 1, '* kgOrdersServer *' );
Logger.Log( 1, Format(' Version: %s ', [FMain.ExeInfo1.FileVersion]));
Logger.Log( 1, '* Developed by EM Systems, Inc. *' );
Logger.Log( 1, '*******************************************************' );
Logger.Log( 1, '' );
//iniEntries is automatically instantiated when the file Common.Ini is used
//we added LoadIniEntries call to put an entry in the Log file
LoadIniEntries;
Logger.Log( 1, 'iniFile: ' + iniFilename );
iniStr := iniFile.ReadString( 'Settings', 'MemoLogLevel', '' );
if iniStr.IsEmpty then
Logger.Log( 1, '--Settings->MemoLogLevel: ini entry not found - default: ' + IntToStr(iniEntries.memoLogLevel) )
else
Logger.Log( 1, '--Settings->MemoLogLevel: ini entry: ' + iniStr );
iniStr := iniFile.ReadString( 'Settings', 'FileLogLevel', '' );
if iniStr.IsEmpty then
Logger.Log( 1, '--Settings->FileLogLevel: ini entry not found - default: ' + IntToStr(iniEntries.fileLogLevel) )
else
Logger.Log( 1, '--Settings->FileLogLevel: ini entry: ' + iniStr );
Logger.Log( 1, '' );
iniStr := iniFile.ReadString( 'Settings', 'LogFileNum', '' );
if iniStr = '1' then
Logger.Log( 1, '--Settings->LogFileNum: ini entry not found - LogFileNum 1 added to iniFile' )
else
Logger.Log( 1, '--Settings->LogFileNum: ini entry: ' + iniStr );
finally finally
iniFile.Free; iniFile.Free;
end; end;
Logger.AddAppender(TMemoLogAppender.Create( MemoLogLevel, FMain.memoinfo ));
Logger.AddAppender(TFileLogAppender.Create( FileLogLevel, 'kgOrdersServer' ));
Application.Run; Application.Run;
end. end.
...@@ -114,11 +114,11 @@ ...@@ -114,11 +114,11 @@
<VerInfo_Locale>1033</VerInfo_Locale> <VerInfo_Locale>1033</VerInfo_Locale>
<DCC_ExeOutput>.\bin</DCC_ExeOutput> <DCC_ExeOutput>.\bin</DCC_ExeOutput>
<DCC_UnitSearchPath>C:\RADTOOLS\FastMM4;$(DCC_UnitSearchPath)</DCC_UnitSearchPath> <DCC_UnitSearchPath>C:\RADTOOLS\FastMM4;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<VerInfo_Keys>CompanyName=EM Systems;FileDescription=$(MSBuildProjectName);FileVersion=0.9.15.1;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=0.9.11;Comments=</VerInfo_Keys> <VerInfo_Keys>CompanyName=EM Systems;FileDescription=$(MSBuildProjectName);FileVersion=0.9.15.4;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=0.9.11;Comments=</VerInfo_Keys>
<VerInfo_MajorVer>0</VerInfo_MajorVer> <VerInfo_MajorVer>0</VerInfo_MajorVer>
<VerInfo_MinorVer>9</VerInfo_MinorVer> <VerInfo_MinorVer>9</VerInfo_MinorVer>
<VerInfo_Release>15</VerInfo_Release> <VerInfo_Release>15</VerInfo_Release>
<VerInfo_Build>1</VerInfo_Build> <VerInfo_Build>4</VerInfo_Build>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1_Win64)'!=''"> <PropertyGroup Condition="'$(Cfg_1_Win64)'!=''">
<AppDPIAwarenessMode>PerMonitorV2</AppDPIAwarenessMode> <AppDPIAwarenessMode>PerMonitorV2</AppDPIAwarenessMode>
...@@ -209,6 +209,7 @@ ...@@ -209,6 +209,7 @@
<Form>fQB</Form> <Form>fQB</Form>
<FormType>dfm</FormType> <FormType>dfm</FormType>
</DCCReference> </DCCReference>
<DCCReference Include="Source\Common.Ini.pas"/>
<BuildConfiguration Include="Base"> <BuildConfiguration Include="Base">
<Key>Base</Key> <Key>Base</Key>
</BuildConfiguration> </BuildConfiguration>
......
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