-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployeeForm.pas
337 lines (297 loc) · 10.5 KB
/
EmployeeForm.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
331
332
333
334
335
336
337
unit EmployeeForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Vcl.Grids, Vcl.DBGrids,
Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Buttons, Vcl.ComCtrls;
type
TfrmKupacLista = class(TForm)
Panel1: TPanel;
DBGrid1: TDBGrid;
btnCreate: TBitBtn;
btnChange: TBitBtn;
btnExi: TBitBtn;
Label1: TLabel;
edtSearch: TEdit;
btnSearch: TBitBtn;
Panel3: TPanel;
btnNoviUgovorZaKupca: TBitBtn;
btnPlacanjeRate: TBitBtn;
btnIzaberiratu: TBitBtn;
btnIzvestaj: TBitBtn;
aaa: TPanel;
BitBtn1: TBitBtn;
DataSource1: TDataSource;
edtBojDanaKasnjenja: TEdit;
edtBrojPlacenihRata: TEdit;
Label2: TLabel;
Label3: TLabel;
procedure FormShow(Sender: TObject);
procedure btnCreateClick(Sender: TObject);
procedure btnSearchClick(Sender: TObject);
procedure btnChangeClick(Sender: TObject);
procedure btnNoviUgovorZaKupcaClick(Sender: TObject);
procedure btnPlacanjeRateClick(Sender: TObject);
procedure btnIzaberiratuClick(Sender: TObject);
procedure btnIzvestajClick(Sender: TObject);
procedure btnExiClick(Sender: TObject);
procedure IsRowSelected();
procedure BitBtn1Click(Sender: TObject);
procedure showListOfRateForBuyer;
procedure proveraKupcaIkreiranjeListeRata;
procedure reopenForm;
procedure hideDtaAbouBuyer;
// procedure BitBtn2Click(Sender: TObject);//(id: Integer);
private
{ Private declarations }
public
{ Public declarations }
forKupacDetalji: String;
idForUpdateKupac: String;
end;
var
frmKupacLista: TfrmKupacLista;
query: String;
implementation
{$R *.dfm}
uses DataModule, KupacDetalji, UplataRate, Izvestaj;
procedure TfrmKupacLista.hideDtaAbouBuyer;
begin
Label2.Visible := False;
Label3.Visible := False;
edtBojDanaKasnjenja.Visible := false;
edtBrojPlacenihRata.Visible := False;
end;
procedure TfrmKupacLista.reopenForm;
begin
self.Caption := 'Lista kupaca';
btnCreate.Visible := True;
btnChange.Visible := True;
btnNoviUgovorZaKupca.Visible := True;
btnPlacanjeRate.Visible := True;
btnIzvestaj.Visible := True;
btnIzaberiratu.Visible := False;
Label1.Visible := True;
edtSearch.Visible := True;
btnSearch.Visible := True;
query := 'SELECT * FROM kupac ';
DM.RefreshGrid(query);
BitBtn1.Visible := False;
end;
procedure TfrmKupacLista.BitBtn1Click(Sender: TObject);
begin
Self.hideDtaAbouBuyer;
self.Caption := 'Lista kupaca';
btnCreate.Visible := True;
btnChange.Visible := True;
btnNoviUgovorZaKupca.Visible := True;
btnPlacanjeRate.Visible := True;
btnIzvestaj.Visible := True;
btnIzaberiratu.Visible := False;
Label1.Visible := True;
edtSearch.Visible := True;
btnSearch.Visible := True;
query := 'SELECT * FROM kupac ';
DM.RefreshGrid(query);
BitBtn1.Visible := False;
end;
procedure TfrmKupacLista.btnChangeClick(Sender: TObject);
begin
frmNoviKupac.Caption := 'Izmena podataka o kupcu';
self.idForUpdateKupac := DBGrid1.Fields[0].Text;
self.forKupacDetalji := 'Izmena podataka o kupcu';
frmNoviKupac.Show;
end;
procedure TfrmKupacLista.btnCreateClick(Sender: TObject);
begin
frmNoviKupac.Caption := 'Novi kupac';
self.forKupacDetalji := 'Novi kupac';
frmNoviKupac.ShowModal;
end;
procedure TfrmKupacLista.btnExiClick(Sender: TObject);
begin
Application.Terminate;
end;
procedure TfrmKupacLista.btnIzaberiratuClick(Sender: TObject);
begin
frmUplataRate.ShowModal;
end;
procedure TfrmKupacLista.btnIzvestajClick(Sender: TObject);
begin
DM.fdqSelect.Active := False;
frmKupacLista.CloseModal;
frmIzvestaj.ShowModal;
end;
procedure TfrmKupacLista.IsRowSelected();
begin
while True do
begin
if DBGrid1.SelectedRows.Count = 0 then
begin
ShowMessage('Morate izabrati kupca');
Exit
end
else
begin
Break
end;
end;
end;
procedure TfrmKupacLista.proveraKupcaIkreiranjeListeRata;
begin
btnCreate.Visible := False;
btnChange.Visible := False;
Label2.Visible := True;
Label3.Visible := True;
edtBojDanaKasnjenja.Visible := True;
edtBrojPlacenihRata.Visible := True;
btnNoviUgovorZaKupca.Visible := False;
btnPlacanjeRate.Visible := False;
btnIzvestaj.Visible := False;
btnIzaberiratu.Visible := True;
Label1.Visible := False;
edtSearch.Visible := False;
btnSearch.Visible := False;
BitBtn1.Visible := true;
self.idForUpdateKupac := DBGrid1.Fields[0].Text;
DM.fdqSelect.SQL.Clear;
DM.fdqSelect.Active := False;
DM.fdqSelect.SQL.Text :=
'SELECT kupac.prezime as PREZIME, kupac.ime as IME, ugovor.id_ugovor as BROJ_UGOVORA,'
+ ' ugovor.datum_ugovora as DATUM_UGOVORA, rate.broj_rate as RATA_BROJ, rate.datum_rate as DATUM_DOSPECA,'
+ 'rate.iznos_rate as IZNOS , rate.id_rate as ID FROM kupac INNER JOIN ugovor ON kupac.id_kupac = ugovor.id_kupac '
+ 'INNER JOIN rate ON ugovor.id_ugovor = rate.id_ugovor WHERE ( kupac.id_kupac = :id_kupac AND (rate.iznos_uplate IS null)) '
+ 'ORDER BY DATUM_DOSPECA';
DM.fdqSelect.ParamByName('id_kupac').AsInteger :=
StrToInt(self.idForUpdateKupac);
DM.fdqSelect.Active := True;
DM.FDQuery1.SQL.Clear;
DM.FDQuery1.SQL.Text := 'SELECT avg(DATEDIFF(r.datum_uplate, r.datum_rate)) as bonitet,' +
'count(iznos_rate) as broj_rata from rate r ' +
'join ugovor u USING(id_ugovor)' +
'join kupac k Using(id_kupac) ' +
'where k.id_kupac = :id_kupac and r.iznos_uplate is not null' ;
DM.FDQuery1.ParamByName('id_kupac').AsInteger :=
StrToInt(self.idForUpdateKupac);
DM.FDQuery1.Active := true;
if (DM.FDQuery1.FieldByName('bonitet').Text = '') then
begin
edtBojDanaKasnjenja.Text := '0';
end
else
begin
edtBojDanaKasnjenja.Text := Format('%6.2f', [StrToFloat (DM.FDQuery1.FieldByName('bonitet').Text)]);
end;
// edtBojDanaKasnjenja.Text := Format('%6.2f', [StrToFloat (DM.FDQuery1.FieldByName('bonitet').Text)]);
edtBrojPlacenihRata.Text := DM.FDQuery1.FieldByName('broj_rata').Text;
end;
procedure TfrmKupacLista.btnNoviUgovorZaKupcaClick(Sender: TObject);
var i :Integer;
begin
if self.Caption = 'Lista kupaca' then
begin
DBGrid1.SelectedRows.CurrentRowSelected := True;
frmKupacLista.Caption := 'Novi ugovor za kupca';
self.idForUpdateKupac := DBGrid1.Fields[0].Text;
self.forKupacDetalji := 'Novi ugovor za kupca';
proveraKupcaIkreiranjeListeRata;
btnNoviUgovorZaKupca.Visible := true;
btnIzaberiratu.Visible := False;
end
else
begin
frmNoviKupac.Caption := 'Novi ugovor za kupca';
self.hideDtaAbouBuyer;
frmNoviKupac.ShowModal;
end;
end;
procedure TfrmKupacLista.btnPlacanjeRateClick(Sender: TObject);
begin
self.Caption := 'Placanje rate';
btnCreate.Visible := False;
btnChange.Visible := False;
Label2.Visible := True;
Label3.Visible := True;
edtBojDanaKasnjenja.Visible := True;
edtBrojPlacenihRata.Visible := True;
btnNoviUgovorZaKupca.Visible := False;
btnPlacanjeRate.Visible := False;
btnIzvestaj.Visible := False;
btnIzaberiratu.Visible := True;
Label1.Visible := False;
edtSearch.Visible := False;
btnSearch.Visible := False;
BitBtn1.Visible := true;
self.idForUpdateKupac := DBGrid1.Fields[0].Text;
DM.fdqSelect.SQL.Clear;
DM.fdqSelect.Active := False;
DM.fdqSelect.SQL.Text :=
'SELECT kupac.prezime as PREZIME, kupac.ime as IME, ugovor.id_ugovor as BROJ_UGOVORA,'
+ ' ugovor.datum_ugovora as DATUM_UGOVORA, rate.broj_rate as RATA_BROJ, rate.datum_rate as DATUM_DOSPECA,'
+ 'rate.iznos_rate as IZNOS , rate.id_rate as ID FROM kupac INNER JOIN ugovor ON kupac.id_kupac = ugovor.id_kupac '
+ 'INNER JOIN rate ON ugovor.id_ugovor = rate.id_ugovor WHERE ( kupac.id_kupac = :id_kupac AND (rate.iznos_uplate IS null)) '
+ 'ORDER BY DATUM_DOSPECA';
DM.fdqSelect.ParamByName('id_kupac').AsInteger :=
StrToInt(self.idForUpdateKupac);
DM.fdqSelect.Active := True;
DM.FDQuery1.SQL.Clear;
DM.FDQuery1.SQL.Text := 'SELECT avg(DATEDIFF(r.datum_uplate, r.datum_rate)) as bonitet,' +
'count(iznos_rate) as broj_rata from rate r ' +
'join ugovor u USING(id_ugovor)' +
'join kupac k Using(id_kupac) ' +
'where k.id_kupac = :id_kupac and r.iznos_uplate is not null' ;
DM.FDQuery1.ParamByName('id_kupac').AsInteger :=
StrToInt(self.idForUpdateKupac);
DM.FDQuery1.Active := true;
if (DM.FDQuery1.FieldByName('bonitet').Text = '') then
begin
edtBojDanaKasnjenja.Text := '0';
end
else
begin
edtBojDanaKasnjenja.Text := Format('%6.2f', [StrToFloat (DM.FDQuery1.FieldByName('bonitet').Text)]);
end;
// edtBojDanaKasnjenja.Text := Format('%6.2f', [StrToFloat (DM.FDQuery1.FieldByName('bonitet').Text)]);
edtBrojPlacenihRata.Text := DM.FDQuery1.FieldByName('broj_rata').Text;
end;
procedure TfrmKupacLista.btnSearchClick(Sender: TObject);
begin
query := 'SELECT * FROM kupac WHERE prezime LIKE ' +
QuotedStr(edtSearch.Text + '%');
DM.RefreshGrid(query);
end;
procedure TfrmKupacLista.FormShow(Sender: TObject);
begin
query := 'SELECT * FROM kupac ';
DM.RefreshGrid(query);
end;
procedure TfrmKupacLista.showListOfRateForBuyer;//(id: Integer);
begin
self.Caption := 'Placanje rate';
btnCreate.Visible := False;
btnChange.Visible := False;
btnNoviUgovorZaKupca.Visible := False;
btnPlacanjeRate.Visible := False;
btnIzvestaj.Visible := False;
btnIzaberiratu.Visible := True;
Label1.Visible := False;
edtSearch.Visible := False;
btnSearch.Visible := False;
BitBtn1.Visible := true;
//self.idForUpdateKupac := DBGrid1.Fields[0].Text;
DM.fdqSelect.SQL.Clear;
DM.fdqSelect.Active := False;
DM.fdqSelect.SQL.Text :=
'SELECT kupac.prezime as PREZIME, kupac.ime as IME, ugovor.id_ugovor as BROJ_UGOVORA,'
+ ' ugovor.datum_ugovora as DATUM_UGOVORA, rate.broj_rate as RATA_BROJ, rate.datum_rate as DATUM_DOSPECA,'
+ 'rate.iznos_rate as IZNOS , rate.id_rate as ID FROM kupac INNER JOIN ugovor ON kupac.id_kupac = ugovor.id_kupac '
+ 'INNER JOIN rate ON ugovor.id_ugovor = rate.id_ugovor WHERE ( kupac.id_kupac = :id_kupac AND (rate.iznos_uplate IS null)) '
+ 'ORDER BY DATUM_DOSPECA';
DM.fdqSelect.ParamByName('id_kupac').AsInteger :=
StrToInt(self.idForUpdateKupac);
DM.fdqSelect.Active := True;
end;
// ALTER TABLE `ugovori_aplikacija`.`kupac`
//CHANGE COLUMN `grad` `grad` VARCHAR(5) NULL DEFAULT NULL ;
end.