-
Notifications
You must be signed in to change notification settings - Fork 1
/
ufrmCadCompra.pas
233 lines (211 loc) · 7.1 KB
/
ufrmCadCompra.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
unit ufrmCadCompra;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ufrmCadSubAbas, cxGraphics, cxControls,
cxLookAndFeels, cxLookAndFeelPainters, dxRibbonCustomizationForm,
dxRibbonSkins, dxBarBuiltInMenu, cxStyles, cxCustomData, cxFilter, cxData,
cxDataStorage, cxEdit, cxNavigator, dxDateRanges, Data.DB, cxDBData,
cxButtonEdit, cxDropDownEdit, cxTextEdit, FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt,
FireDAC.Comp.DataSet, FireDAC.Comp.Client, System.ImageList, Vcl.ImgList,
cxImageList, dxSkinsForm, dxBar, cxBarEditItem, cxClasses, cxGridLevel,
cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
cxGrid, cxPC, dxRibbon, cxContainer, cxCalendar, cxDBEdit, cxMaskEdit,
cxSpinEdit, Vcl.StdCtrls, cxMemo, cxRichEdit, cxDBRichEdit, cxLookupEdit,
cxDBLookupEdit, cxDBLookupComboBox, cxGroupBox, dxSkinsCore, dxSkinProject1,
cxLabel, cxCurrencyEdit, Vcl.Menus, cxButtons, cxCheckBox;
type
TfrmCadCompra = class(TfrmCadSubAbas)
FDQueryID: TIntegerField;
FDQueryDESCRICAO: TStringField;
FDQueryIDFORNECEDOR: TIntegerField;
FDQueryDATA: TDateField;
FDQueryOBS: TStringField;
FDQueryFLPAGA: TSmallintField;
FDQueryVRPAGO: TCurrencyField;
FDQueryDTEXCLUIU: TDateField;
FDQueryID_1: TIntegerField;
FDQueryNOME: TStringField;
FDQueryTELEFONE: TStringField;
FDQueryOBS_1: TStringField;
cxGridDBTableView1ID: TcxGridDBColumn;
cxGridDBTableView1DATA: TcxGridDBColumn;
cxGridDBTableView1VRPAGO: TcxGridDBColumn;
cxGridDBTableView1NOME: TcxGridDBColumn;
cxGridDBTableView1TELEFONE: TcxGridDBColumn;
Label1: TLabel;
cxDBSpinEdit1: TcxDBSpinEdit;
Label3: TLabel;
cxDBDateEdit1: TcxDBDateEdit;
Label4: TLabel;
cxDBLookupComboBox1: TcxDBLookupComboBox;
cxDBRichEdit1: TcxDBRichEdit;
Label5: TLabel;
FDQFornecedor: TFDQuery;
dtsFornecedor: TDataSource;
FDQFornecedorID: TFDAutoIncField;
FDQFornecedorNOME: TStringField;
cxGrid1DBTableView1: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
cxLabel1: TcxLabel;
cxLabel2: TcxLabel;
edtValor: TcxCurrencyEdit;
edtQuantidade: TcxTextEdit;
cxLabel3: TcxLabel;
cxButton1: TcxButton;
FDQProdutos: TFDQuery;
dsitem: TDataSource;
FDQProdutosID: TFDAutoIncField;
FDQProdutosNOME: TStringField;
FDQProdutosIDUNIDADEDEMEDIDA: TIntegerField;
FDQProdutosVALORDOPRODUTO: TCurrencyField;
FDQProdutosQUANTIDADE: TFMTBCDField;
FDQProdutosSTATUS: TSmallintField;
cbProduto: TcxLookupComboBox;
FDQProdutosCOmpra: TFDQuery;
DataSource1: TDataSource;
FDQProdutosCOmpraID: TFDAutoIncField;
FDQProdutosCOmpraNOME: TStringField;
FDQProdutosCOmpraVRUNIDADE: TCurrencyField;
FDQProdutosCOmpraQUANTIDADE: TStringField;
FDQProdutosCOmpraIDITEMCOMPRA: TIntegerField;
cxGrid1DBTableView1ID: TcxGridDBColumn;
cxGrid1DBTableView1NOME: TcxGridDBColumn;
cxGrid1DBTableView1VRUNIDADE: TcxGridDBColumn;
cxGrid1DBTableView1QUANTIDADE: TcxGridDBColumn;
FDQProdutosCOmpraVALORTOTAL: TBCDField;
Label6: TLabel;
cxGrid1DBTableView1VALORTOTAL: TcxGridDBColumn;
FDPInsereItem: TFDStoredProc;
cxGrid1DBTableView1Column1: TcxGridDBColumn;
Label7: TLabel;
cxDBCurrencyEdit1: TcxDBCurrencyEdit;
FDPRemoveItem: TFDStoredProc;
dxBarCombo1: TdxBarCombo;
cxGroupBox2: TcxGroupBox;
lblTotal: TcxLabel;
FDQTotal: TFDQuery;
FDQTotalIDCOMPRA: TIntegerField;
FDQTotalVALOR: TBCDField;
cxGroupBox3: TcxGroupBox;
gbProdutos: TcxGroupBox;
cxGroupBox4: TcxGroupBox;
cxLabel4: TcxLabel;
cxLabel5: TcxLabel;
cxGridDBTableView1FLPAGA: TcxGridDBColumn;
FDQueryIDCOMPRA: TIntegerField;
FDQueryVALORDACOMPRA: TBCDField;
cxGridDBTableView1VALORDACOMPRA: TcxGridDBColumn;
QryAux: TFDQuery;
procedure btnAdcClick(Sender: TObject);
procedure cxTabSheet2Show(Sender: TObject);
procedure cxButton1Click(Sender: TObject);
procedure cxGrid1DBTableView1Column1PropertiesButtonClick(Sender: TObject;
AButtonIndex: Integer);
procedure dtsStateChange(Sender: TObject);
procedure cbProdutoPropertiesChange(Sender: TObject);
private
{ Private declarations }
public
procedure MontaQry; override;
procedure AtualizaItens;
procedure CalculaValorTotal;
end;
var
frmCadCompra: TfrmCadCompra;
implementation
{$R *.dfm}
uses uDM;
{ TfrmCadBase2 }
procedure TfrmCadCompra.AtualizaItens;
begin
FDQProdutosCompra.Close;
FDQProdutosCompra.Params.ClearValues;
FDQProdutosCompra.Params.Items[0].Value := FDQueryID.Value;
FDQProdutosCompra.Open;
end;
procedure TfrmCadCompra.btnAdcClick(Sender: TObject);
begin
inherited;
cxDBDateEdit1.Date := Date();
cxDBLookupComboBox1.SetFocus;
end;
procedure TfrmCadCompra.CalculaValorTotal;
begin
FDQTotal.Close;
FDQTotal.Params.ClearValues;
FDQTotal.Params.Items[0].Value := FDQueryID.Value;
FDQTotal.Open;
lblTotal.Caption:= 'Total: '+ CurrToStr(FDQTotal.FieldByName('VALOR').AsCurrency);
end;
procedure TfrmCadCompra.cbProdutoPropertiesChange(Sender: TObject);
begin
inherited;
QryAux.Close;
with QryAux.SQL do
begin
clear;
add('select * from item where id = '+String(cbProduto.EditValue));
end;
QryAux.Open;
edtValor.Value := QryAux.FieldByName('VALORDOPRODUTO').AsCurrency;
end;
procedure TfrmCadCompra.cxButton1Click(Sender: TObject);
begin
inherited;
FDPInsereItem.Params.ParamByName('IDITEM').Value := cbProduto.EditValue;//cbProduto.ItemObject.;
FDPInsereItem.Params.ParamByName('IDCOMPRA').Value := FDQueryID.Value;
FDPInsereItem.Params.ParamByName('VRUNIDADE').Value := edtValor.Value;
FDPInsereItem.Params.ParamByName('QTUNIDADE').Value := edtQuantidade.Text;
FDPInsereItem.Execute;
CalculaValorTotal;
AtualizaItens;
end;
procedure TfrmCadCompra.cxGrid1DBTableView1Column1PropertiesButtonClick(
Sender: TObject; AButtonIndex: Integer);
begin
inherited;
FDPRemoveItem.Params.ParamByName('IDITEMCOMPRA').Value := FDQProdutosCOmpraidItemCompra.Value;
FDPRemoveItem.Execute;
CalculaValorTotal;
AtualizaItens;
end;
procedure TfrmCadCompra.cxTabSheet2Show(Sender: TObject);
begin
inherited;
AtualizaItens;
CalculaValorTotal;
end;
procedure TfrmCadCompra.dtsStateChange(Sender: TObject);
begin
inherited;
if FDQuery.State in [dsInsert] then
gbProdutos.Visible:=false
else
gbProdutos.Visible:=true;
end;
procedure TfrmCadCompra.MontaQry;
begin
inherited;
FDQuery.close;
with FDQuery.SQL do
begin
clear;
add('select * ');
add('from compra c ');
add('left join valorcompra v on v.idcompra=c.id ');
add('left join pessoa p on c.idfornecedor=p.id ');
add('where dtexcluiu is null ');
add('order by c.id desc ');
end;
FDQuery.Open;
FDQFornecedor.Close;
FDQFornecedor.Open;
FDQProdutos.Close;
FDQProdutos.open;
cbProduto.ItemIndex:=0;
end;
end.