-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmTellerHomeScreen_u.pas
330 lines (301 loc) · 11 KB
/
frmTellerHomeScreen_u.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
// ##################################
// ###### IT PAT 2018 #######
// ###### GrowCery #######
// ###### Tiaan van der Riel #######
// ##################################
unit frmTellerHomeScreen_u;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, pngimage, ExtCtrls, StdCtrls, ComCtrls, jpeg, clsDisplayUserInfo_u,
clsAnalyticsCalculator_u, DateUtils;
type
TfrmTellerHomeScreen = class(TForm)
btnStartShift: TButton;
btnLogOut: TButton;
imgBacground: TImage;
imgWelcomeHeading: TImage;
lblLoggedOnUser: TLabel;
lblTellerInfo: TLabel;
imgDarkLogo: TImage;
btHelp: TButton;
lblTotalNumberYesterday: TLabel;
lblTotalValueYesterday: TLabel;
lblTotalNumberToday: TLabel;
lblTotalValueToday: TLabel;
lblYesterday: TLabel;
lblToday: TLabel;
pnlTotalNumberYesterday: TPanel;
pnlTotalNumberToday: TPanel;
pnlTotalValueYesterday: TPanel;
pnlTotalValueToday: TPanel;
lblTodaysDate: TLabel;
lblYesterdaysDate: TLabel;
lblNoDataYesterday: TLabel;
lblDifferenceInNumberSold: TLabel;
lblDifferenceValue: TLabel;
procedure FormActivate(Sender: TObject);
procedure btnLogOutClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btnStartShiftClick(Sender: TObject);
procedure btHelpClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
objDisplayUserInfo: TDisplayUserInfo;
objAnalyticsCalculator: TAnalyticsCalculator;
procedure DetermindeYesterdaysDate;
procedure CalculateDifferences;
procedure GetUserFullName;
public
{ Public declarations }
sLoggedOnUser: string;
sLoggedOnUserName: string;
sTodaysDate: string;
sYesterdaysDate: string;
rTodayTotalValue: real;
rYesterdayTotalValue: real;
iTodayTotalNumSold: integer;
iYesterdayTotalNumSold: integer;
end;
var
frmTellerHomeScreen: TfrmTellerHomeScreen;
implementation
uses
frmLogIn_u, frmPointOfSale_u, dmDatabase_u;
{$R *.dfm}
/// ========================= Start Shift Button ==============================
procedure TfrmTellerHomeScreen.btnStartShiftClick(Sender: TObject);
begin
frmTellerHomeScreen.Hide;
frmPointOfSale.ShowModal;
end;
/// ======================== Form Activate ====================================
procedure TfrmTellerHomeScreen.FormActivate(Sender: TObject);
var
sSelectedAccountID: string;
sStartDate: string;
sEndDate: string;
begin
// Obtains the logged in user`s name from frmLogIn
sLoggedOnUser := frmLogIn.sLoggedOnUser;
GetUserFullName;
lblLoggedOnUser.Caption := sLoggedOnUserName;
// Object to display user information
{ The function of this piece of code is to create the object objDisplayUserInfo,
this object will make use of the class clsDisplayUserInfo, as the variable
sLoggedOnUser, to find and return all of the relevant information regarding the
currently logged in user, and display that information in the top left
* also used by frmAdminHomeScreeen }
objDisplayUserInfo := TDisplayUserInfo.Create(sLoggedOnUser);
lblTellerInfo.Caption := objDisplayUserInfo.ToString;
objDisplayUserInfo.Free;
// Get the analytics for TODAY
with dmDatabase do
Begin
dsrTransactions.DataSet := qryTransactions;
End;
{ The function of this code is to send over the paramaters to clsAnalyticsCalsulator
so that the totals for the CURRENT DATE can be calculated
- see class clsAnalyticsCalculator on more information as to how this is done.}
sSelectedAccountID := sLoggedOnUser;
sStartDate := sTodaysDate;
sEndDate := sTodaysDate;
objAnalyticsCalculator := TAnalyticsCalculator.Create
(sSelectedAccountID, sStartDate, sEndDate);
iTodayTotalNumSold := objAnalyticsCalculator.CalcTotalItemsSold;
pnlTotalNumberToday.Caption := IntToStr(iTodayTotalNumSold);
rTodayTotalValue := objAnalyticsCalculator.CalcTotalSales;
pnlTotalValueToday.Caption := FloatToStrF(rTodayTotalValue, ffCurrency, 8, 2);
objAnalyticsCalculator.Free;
lblTodaysDate.Caption := sTodaysDate;
// Get the analytics for YESTERDAY
DetermindeYesterdaysDate;
lblYesterdaysDate.Caption := sYesterdaysDate;
sSelectedAccountID := sLoggedOnUser;
sStartDate := sYesterdaysDate;
sEndDate := sYesterdaysDate;
objAnalyticsCalculator := TAnalyticsCalculator.Create
(sSelectedAccountID, sStartDate, sEndDate);
iYesterdayTotalNumSold := objAnalyticsCalculator.CalcTotalItemsSold;
pnlTotalNumberYesterday.Caption := IntToStr(iYesterdayTotalNumSold);
rYesterdayTotalValue := objAnalyticsCalculator.CalcTotalSales;
pnlTotalValueYesterday.Caption := FloatToStrF
(rYesterdayTotalValue, ffCurrency, 8, 2);
objAnalyticsCalculator.Free;
//
iYesterdayTotalNumSold := StrToInt(pnlTotalNumberYesterday.Caption);
{ If no items where sold yesterday, that means that teller either didn`t work
the previous day, OR IT IS THE BEGGING OF A NEW WORK CYCLE/WEEK - data gets "archived"
every 6 days }
if iYesterdayTotalNumSold = 0 then
Begin
lblNoDataYesterday.Visible := True;
lblTotalNumberYesterday.Visible := False;
lblTotalValueYesterday.Visible := False;
lblDifferenceInNumberSold.Visible := False;
lblDifferenceValue.Visible := False;
pnlTotalValueYesterday.Visible := False;
pnlTotalNumberYesterday.Visible := False;
End
Else
Begin
CalculateDifferences;
End;
//
pnlTotalNumberYesterday.Color := rgb(139, 198, 99);
pnlTotalValueYesterday.Color := rgb(139, 198, 99);
pnlTotalNumberToday.Color := rgb(139, 198, 99);
pnlTotalValueToday.Color := rgb(139, 198, 99);
end;
/// ========================= Determine Yesterday`s date ======================
procedure TfrmTellerHomeScreen.DetermindeYesterdaysDate;
{ This procedure calculats the previous date, this will work no matter if the
previous date is in another month, or even a previous year}
var
GivenDate: TdateTime;
iYear: word;
iMonth: word;
iDay: word;
PreviousDate: TdateTime;
begin
iYear := StrToInt(Copy(sTodaysDate, 1, 4));
iMonth := StrToInt(Copy(sTodaysDate, 6, 2));
iDay := StrToInt(Copy(sTodaysDate, 9, 2));
GivenDate := EncodeDate(iYear, iMonth, iDay);
/////////////////// NB /////////////////////
{ Increases the given date (today`s date) by -1, effectively calculating the
previuos day, yesterday }
/////////////////// NB /////////////////////
PreviousDate := IncDay(GivenDate, -1);
sYesterdaysDate := DateToStr(PreviousDate);
// ShowMessage(sYesterdaysDate);
sYesterdaysDate := Copy(sYesterdaysDate, 1, 4) + '-' + Copy
(sYesterdaysDate, 6, 2) + '-' + Copy(sYesterdaysDate, 9, 2);
// ShowMessage(sYesterdaysDate);
lblYesterdaysDate.Caption := sYesterdaysDate;
end;
// ================ Calculates the difference in the number of items sold and
// value of the current day and previous day =================================
procedure TfrmTellerHomeScreen.CalculateDifferences;
var
iDifferenceInNumSold: integer;
rDifferenceInValue: real;
begin
iDifferenceInNumSold := iTodayTotalNumSold - iYesterdayTotalNumSold;
rDifferenceInValue := rTodayTotalValue - rYesterdayTotalValue;
if iDifferenceInNumSold = 0 then
Begin
lblDifferenceInNumberSold.Font.Color := clBlack;
lblDifferenceInNumberSold.Caption := 'No Difference ' + IntToStr
(iDifferenceInNumSold);
End;
if iDifferenceInNumSold > 0 then
Begin
lblDifferenceInNumberSold.Font.Color := clGreen;
lblDifferenceInNumberSold.Caption := '↑ Up by ' + IntToStr
(iDifferenceInNumSold);
End;
if iDifferenceInNumSold < 0 then
Begin
lblDifferenceInNumberSold.Font.Color := clRed;
lblDifferenceInNumberSold.Caption := '↓ Down by ' + IntToStr
(iDifferenceInNumSold);
end;
if rDifferenceInValue = 0 then
Begin
lblDifferenceValue.Font.Color := clBlack;
lblDifferenceValue.Caption := 'No Difference ' + FloatToStrF
(rDifferenceInValue, ffCurrency, 8, 2)
End;
if rDifferenceInValue > 0 then
Begin
lblDifferenceValue.Font.Color := clGreen;
lblDifferenceValue.Caption := '↑ Up by ' + FloatToStrF
(rDifferenceInValue, ffCurrency, 8, 2);
End;
if rDifferenceInValue < 0 then
Begin
lblDifferenceValue.Font.Color := clRed;
lblDifferenceValue.Caption := '↓ Down by ' + FloatToStrF
(rDifferenceInValue, ffCurrency, 8, 2);
End;
end;
/// ========================= Form Close ======================================
procedure TfrmTellerHomeScreen.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
ShowMessage('You have been logged out of your account.');
// Date gets reset
sTodaysDate := '';
end;
/// ======================== Log Out Button ===================================
procedure TfrmTellerHomeScreen.btnLogOutClick(Sender: TObject);
begin
if MessageDlg(' Are you sure you want to log out of your account ?',
mtConfirmation, [mbYes, mbCancel], 0) = mrYes then
begin
frmTellerHomeScreen.Close;
end
else
Exit
end;
/// ======================= Form Gets Shown ===================================
procedure TfrmTellerHomeScreen.FormShow(Sender: TObject);
begin
if sTodaysDate = '' then
Begin
sTodaysDate := InputBox('Today`s Date',
'Please enter today`s date' + #9 + '(yyyy-mm-dd)', '2018-01-02');
End;
end;
/// ================== Get The Sull Name Of the User ==========================
procedure TfrmTellerHomeScreen.GetUserFullName;
var
bAccountIDFound: boolean;
sCompare: string;
begin
bAccountIDFound := False;
dmDatabase.tblAccounts.First;
while (NOT dmDatabase.tblAccounts.EOF) AND (bAccountIDFound = False) do
Begin
sCompare := dmDatabase.tblAccounts['AccountID'];
if sLoggedOnUser = sCompare then
Begin
bAccountIDFound := True;
sLoggedOnUserName := dmDatabase.tblAccounts['Name']
+ ' ' + dmDatabase.tblAccounts['Surname'];
// ShowMessage('Account ID Found');
End
else
Begin
dmDatabase.tblAccounts.Next;
End;
End; // End of searching for username (EOF)
End;
/// ============================= Help Button =================================
procedure TfrmTellerHomeScreen.btHelpClick(Sender: TObject);
var
tHelp: TextFile;
sLine: string;
sMessage: string;
begin
sMessage := '========================================';
AssignFile(tHelp, 'Help_AdminHomeScreen.txt');
try { Code that checks to see if the file about the sponsors can be opened
- displays error if not }
reset(tHelp);
Except
ShowMessage('ERROR: The help file could not be opened.');
Exit;
end;
while NOT EOF(tHelp) do
begin
Readln(tHelp, sLine);
sMessage := sMessage + #13 + sLine;
end;
sMessage := sMessage + #13 + '========================================';
CloseFile(tHelp);
ShowMessage(sMessage);
end;
end.