This repository has been archived by the owner on Aug 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfuncoes.pas
268 lines (241 loc) · 6.93 KB
/
funcoes.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
unit funcoes;
{$mode objfpc}{$H+}
interface
uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ComCtrls;
//function getNotas100:Integer;
function caixaStatus():Integer;
function somaSaldo():Integer;
function getNotas100():Integer;
function getNotas50():Integer;
function getNotas20():Integer;
function getNotas10():Integer;
function getNotas5():Integer;
function getNotas2():integer;
//function validaValor(valor : Integer): Integer;
function updateNotas100(upNota100 :Integer):integer;
function updateNotas50(upNota50 :Integer):integer;
function updateNotas20(upNota20 : Integer):integer;
function updateNotas10(upNota10 : Integer):integer;
function updateNotas5(upNota5 : Integer):integer;
function updateNotas2(upNota2 : Integer):integer;
function statusSaque():integer;
function falhaBanco():integer;
implementation
uses conexaoDB, telaInicial;
//var resultSaldo : Double;
function getNotas100:integer;
begin
try
DB.SQLQuery1.SQL.Text:='SELECT quantidade FROM nota WHERE valor= 100.00 AND idcaixa = 1';
DB.SQLQuery1.Open;
getNotas100:= StrToInt(DB.SQLQuery1['quantidade']);
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function getNotas50:integer;
begin
try
DB.SQLQuery1.SQL.Text:='SELECT quantidade FROM nota WHERE valor= 50.00 AND idcaixa = 1';
DB.SQLQuery1.Open;
getNotas50 := StrToInt(DB.SQLQuery1['quantidade']);
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function getNotas20:integer;
begin
try
DB.SQLQuery1.SQL.Text:='SELECT quantidade FROM nota WHERE valor= 20.00 AND idcaixa = 1';
DB.SQLQuery1.Open;
getNotas20 := StrToInt(DB.SQLQuery1['quantidade']);
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function getNotas10:integer;
begin
try
DB.SQLQuery1.SQL.Text:='SELECT quantidade FROM nota WHERE valor= 10.00 AND idcaixa = 1';
DB.SQLQuery1.Open;
getNotas10 := StrToInt(DB.SQLQuery1['quantidade']);
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function getNotas5:integer;
begin
try
DB.SQLQuery1.SQL.Text:='SELECT quantidade FROM nota WHERE valor= 5.00 AND idcaixa = 1';
DB.SQLQuery1.Open;
Result := DB.SQLQuery1['quantidade'];
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function getNotas2:integer;
begin
try
DB.SQLQuery1.SQL.Text:='SELECT quantidade FROM nota WHERE valor= 2.00 AND idcaixa = 1';
DB.SQLQuery1.Open;
Result := DB.SQLQuery1['quantidade'];
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function somaSaldo:integer;
begin
//DB.SQLQuery1.Close;
somaSaldo:= (getNotas2 *2) + (getNotas5 * 5) + (getNotas10 * 10) + (getNotas20 * 20) + (getNotas50 * 50) + (getNotas100 * 100);
end;
{function validaValor(valor: Integer): Integer;
var
resto100, resto50, resto20, resto10, resto5, resto2 :double;
begin
resto100 := valor mod 100;
resto50 := valor mod 50;
resto20 := valor mod 20;
resto10 := valor mod 10;
resto5 := valor mod 5;
resto2 :=valor mod 2;
if(resto100 = 0) OR (resto50 = 0) OR (resto20 = 0) OR (resto10 = 0) OR (resto5 = 0) OR (resto2 = 0)then
validaValor := 1
else
validaValor := 0;
end;}
function caixaStatus:Integer;
begin
try
DB.SQLQuery1.SQL.Text:='SELECT status FROM caixa WHERE idcaixa =1';
DB.SQLQuery1.Open;
if DB.SQLQuery1['status'] = 1 then
Result := 1
else
Result := 2;
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function updateNotas2(upNota2 : Integer):integer;
begin
try
DB.SQLQuery1.SQL.Text:='UPDATE nota SET quantidade='''+IntToStr(upNota2)+''' WHERE idcaixa =1 AND idnota =6';
DB.SQLTransaction1.Active:=false;
DB.SQLTransaction1.StartTransaction;
DB.SQLQuery1.ExecSQL;
DB.SQLTransaction1.Commit;
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function updateNotas5(upNota5 : Integer):integer;
begin
try
DB.SQLQuery1.SQL.Text:='UPDATE nota SET quantidade='''+IntToStr(upNota5)+''' WHERE idcaixa =1 AND idnota =5';
DB.SQLTransaction1.Active:=false;
DB.SQLTransaction1.StartTransaction;
DB.SQLQuery1.ExecSQL;
DB.SQLTransaction1.Commit;
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function updateNotas10(upNota10 : Integer):integer;
begin
try
DB.SQLQuery1.SQL.Text:='UPDATE nota SET quantidade='''+IntToStr(upNota10)+''' WHERE idcaixa =1 AND idnota =4';
DB.SQLTransaction1.Active:=false;
DB.SQLTransaction1.StartTransaction;
DB.SQLQuery1.ExecSQL;
DB.SQLTransaction1.Commit;
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function updateNotas20(upNota20 : Integer):integer;
begin
try
DB.SQLQuery1.SQL.Text:='UPDATE nota SET quantidade='''+IntToStr(upNota20)+''' WHERE idcaixa =1 AND idnota =3';
DB.SQLTransaction1.Active:=false;
DB.SQLTransaction1.StartTransaction;
DB.SQLQuery1.ExecSQL;
DB.SQLTransaction1.Commit;
DB.SQLQuery1.Close;
finally
// falhaBanco();
end;
end;
function updateNotas50(upNota50 :Integer):integer;
begin
try
DB.SQLQuery1.SQL.Text:='UPDATE nota SET quantidade='''+IntToStr(upNota50)+''' WHERE idcaixa =1 AND idnota =2';
DB.SQLTransaction1.Active:=false;
DB.SQLTransaction1.StartTransaction;
DB.SQLQuery1.ExecSQL;
DB.SQLTransaction1.Commit;
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function updateNotas100(upNota100 :Integer):integer;
begin
try
DB.SQLQuery1.SQL.Text:='UPDATE nota SET quantidade='''+IntToStr(upNota100)+''' WHERE idcaixa =1 AND idnota =1';
DB.SQLTransaction1.Active:=false;
DB.SQLTransaction1.StartTransaction;
DB.SQLQuery1.ExecSQL;
DB.SQLTransaction1.Commit;
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function statusSaque():integer;
begin
if(getNotas100 < 1) AND (getNotas50 < 1) AND (getNotas20 <1) AND (getNotas10 <1) AND (getNotas5 <1) AND (getNotas2 < 1) then
statusSaque := 1;
end;
function falhaBanco():integer;
begin
//ShowMessage('Erro aqui');
Form1.Show;
Form1.btDeposito.Hide;
Form1.SaqueSem.Hide;
Form1.lbError.Caption:='Ocorreu uma falha, por favor utilize outro terminal.';
Form1.status.Visible:=True;
Form1.status.Color:=clRed;
Form1.status.Caption:='Caixa Inativo';
Form1.lbNotasDisponiveis.Hide;
Form1.lbNota100.Hide;
Form1.lbNota50.Hide;
Form1.lbNota20.Hide;
Form1.lbNota10.Hide;
Form1.lbNota5.Hide;
Form1.lbNota2.Hide;
Form1.lbInsiraCartao.Hide;
end;
end.