forked from layerfsd/Roomer-PMS-1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathufrmPaymentReqRoomtypeGroup.pas
256 lines (224 loc) · 7.42 KB
/
ufrmPaymentReqRoomtypeGroup.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
unit ufrmPaymentReqRoomtypeGroup;
interface
uses
VCL.Forms,
sSpeedButton, sLabel, Vcl.ExtCtrls, sPanel, cxCheckBox, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
cxStyles, dxSkinsCore, dxSkinCaramel, dxSkinCoffee, dxSkinDarkSide, dxSkinTheAsphaltWorld, dxSkinsDefaultPainters,
dxSkinscxPCPainter, cxCustomData, cxFilter, cxData, cxDataStorage, cxEdit, cxNavigator, Data.DB, cxDBData, dxPSGlbl,
dxPSUtl, dxPSEngn, dxPrnPg, dxBkgnd, dxWrap, dxPrnDev, dxPSCompsProvider, dxPSFillPatterns, dxPSEdgePatterns,
dxPSPDFExportCore, dxPSPDFExport, cxDrawTextUtils, dxPSPrVwStd, dxPSPrVwAdv, dxPSPrVwRibbon,
dxPScxPageControlProducer, dxPScxGridLnk, dxPScxGridLayoutViewLnk, dxPScxEditorProducers, dxPScxExtEditorProducers,
dxSkinsdxBarPainter, dxSkinsdxRibbonPainter, cxCalc, Vcl.Menus, cxGridCustomTableView, cxGridTableView,
cxGridDBTableView, cxPropertiesStore, dxmdaset, dxPSCore, dxPScxCommon, cxGridLevel, cxClasses, cxGridCustomView,
cxGrid, Vcl.StdCtrls, sButton, Vcl.ComCtrls, sStatusBar, sEdit, Vcl.Buttons, Vcl.Controls, System.Classes, dxPScxPivotGridLnk;
type
TfrmPaymentReqRoomtypeGroup = class(TForm)
pnlHolder: TsPanel;
sPanel1: TsPanel;
cLabFilter: TsLabel;
btnClear: TsSpeedButton;
edFilter: TsEdit;
sbMain: TsStatusBar;
panBtn: TsPanel;
btnCancel: TsButton;
BtnOk: TsButton;
grData: TcxGrid;
tvData: TcxGridDBTableView;
lvData: TcxGridLevel;
DS: TDataSource;
grPrinter: TdxComponentPrinter;
prLink_grData: TdxGridReportLink;
m_: TdxMemData;
FormStore: TcxPropertiesStore;
m_ChannelmanagerID: TStringField;
m_Name: TStringField;
m_PaymentRequired: TBooleanField;
m_PrepaidPercentage: TFloatField;
tvDataRecId: TcxGridDBColumn;
tvDataChannelmanagerID: TcxGridDBColumn;
tvDataName: TcxGridDBColumn;
tvDataPaymentRequired: TcxGridDBColumn;
tvDataPrepaidPercentage: TcxGridDBColumn;
m_Active: TBooleanField;
mnuOther: TPopupMenu;
mnuiPrint: TMenuItem;
mnuiAllowGridEdit: TMenuItem;
N2: TMenuItem;
Export1: TMenuItem;
mnuiGridToExcel: TMenuItem;
mnuiGridToHtml: TMenuItem;
mnuiGridToText: TMenuItem;
mnuiGridToXml: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure edFilterChange(Sender: TObject);
procedure btnClearClick(Sender: TObject);
procedure tvDataPrepaidPercentagePropertiesValidate(Sender: TObject; var DisplayValue: Variant;
var ErrorText: TCaption; var Error: Boolean);
procedure BtnOkClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ Private declarations }
FRoomtypeGroup: string;
procedure fillGridFromDataset(const iGoto: String);
procedure applyFilter;
procedure UpdatePaymentRequirements;
public
{ Public declarations }
constructor CreateForGroup(const aRoomTypeGroup: string); overload;
end;
function EditPaymentRequirements(const aRoomTypeGroup: string): boolean;
implementation
{$R *.dfm}
uses
Windows
, Variants
, SysUtils
, uSqlDefinitions
, uAppGlobal
, uG
, cmpRoomerDataset
, uD
, uUtils
, _Glob
, hData
, uSQLUtils
, uRoomerLanguage
, uVCLUtils;
function EditPaymentRequirements(const aRoomTypeGroup: string): boolean;
var
frm: TfrmPaymentReqRoomtypeGroup;
begin
frm := TfrmPaymentReqRoomtypeGroup.CreateForGroup(aRoomTypeGroup);
try
Result := frm.ShowModal = mrOk;
finally
frm.Free;
end;
end;
procedure TfrmPaymentReqRoomtypeGroup.btnClearClick(Sender: TObject);
begin
edFilter.Text := '';
end;
procedure TfrmPaymentReqRoomtypeGroup.BtnOkClick(Sender: TObject);
begin
UpdatePaymentRequirements;
ModalResult := mrOk;
end;
constructor TfrmPaymentReqRoomtypeGroup.CreateForGroup(const aRoomTypeGroup: string);
begin
inherited Create(nil);
FRoomtypeGroup := aRoomTypeGroup;
Caption := Caption + ' '+ FRoomTypeGroup;
end;
procedure TfrmPaymentReqRoomtypeGroup.FormCreate(Sender: TObject);
begin
RoomerLanguage.TranslateThisForm(self);
glb.PerformAuthenticationAssertion(self);
PlaceFormOnVisibleMonitor(self);
end;
procedure TfrmPaymentReqRoomtypeGroup.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key = VK_ESCAPE then
btnCancel.Click;
end;
procedure TfrmPaymentReqRoomtypeGroup.FormShow(Sender: TObject);
begin
fillGridFromDataset('');
end;
procedure TfrmPaymentReqRoomtypeGroup.tvDataPrepaidPercentagePropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
Error := not VarInRange(DisplayValue, 0, 100);
end;
procedure TfrmPaymentReqRoomtypeGroup.UpdatePaymentRequirements;
var
sql: string;
lExec: TRoomerExecutionPlan;
begin
if m_.State in [dsEdit, dsInsert] then
m_.Post;
lExec := d.roomerMainDataset.CreateExecutionPlan;
try
sql := Format(delete_PaymentRequirementsForRoomTypeGroup, [_db(FRoomtypeGroup)]);
lExec.AddExec(sql);
m_.First;
while not m_.Eof do
begin
if m_PaymentRequired.AsBoolean and (m_PrepaidPercentage.AsFloat > 0) then
begin
sql := Format(Insert_PaymentRequirementsForRoomtypeGroup, [_db(d.roomerMainDataSet.hotelId),
_db(m_ChannelmanagerID.AsString),
_db(FRoomtypeGroup),
_db(m_PrepaidPercentage.AsFloat)]);
lExec.AddExec(sql);
end;
m_.Next;
end;
if not lExec.Execute(ptExec, True, True) then
raise Exception.Create(lExec.ExecException);
finally
lExec.Free;
end;
end;
procedure TfrmPaymentReqRoomtypeGroup.edFilterChange(Sender: TObject);
begin
if edFilter.Text = '' then
begin
tvData.DataController.Filter.Root.Clear;
tvData.DataController.Filter.Active := false;
end
else
applyFilter;
end;
procedure TfrmPaymentReqRoomtypeGroup.applyFilter;
begin
tvData.DataController.Filter.Options := [fcoCaseInsensitive];
tvData.DataController.Filter.Root.BoolOperatorKind := fboOr;
tvData.DataController.Filter.Root.Clear;
tvData.DataController.Filter.Root.AddItem(tvDataName,foLike,'%'+edFilter.Text+'%','%'+edFilter.Text+'%');
tvData.DataController.Filter.Root.AddItem(tvDataChannelmanagerID,foLike,'%'+edFilter.Text+'%','%'+edFilter.Text+'%');
tvData.DataController.Filter.Active := True;
end;
procedure TfrmPaymentReqRoomtypeGroup.fillGridFromDataset(const iGoto : String);
var
s : string;
rSet : TRoomerDataSet;
begin
rSet := CreateNewDataSet;
try
s := format(select_PaymentRequirementForRoomTypeGroup, [_db(FRoomTypeGroup)]);
CopyToClipboard(s);
if rSet_bySQL(rSet,s, false) then
begin
m_.Close;
m_.Open;
rSet.first;
while not rSet.Eof do
begin
m_.Append;
try
m_ChannelmanagerID.AsString := rset.FieldByName('ChannelmanagerId').ASstring;
m_Name.AsString := rset.FieldByName('Name').ASstring;
m_PaymentRequired.AsBoolean := rset.FieldByName('Payment_Required').Asboolean;
m_PrepaidPercentage.AsFloat := rset.FieldByName('Prepaid_Percentage').AsFloat;
m_.Post;
except
m_.Cancel;
raise;
end;
rSet.Next;
end;
if iGoto = '' then
m_.First
else
try
m_.Locate('ChannelmanagerId',iGoto,[]);
except
end;
end;
finally
rSet.Free;
end;
end;
end.