forked from layerfsd/Roomer-PMS-1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
objRoomRates.pas
522 lines (433 loc) · 13.9 KB
/
objRoomRates.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
unit objRoomRates;
interface
uses
Windows
, Messages
, SysUtils
, Variants
, Classes
, Contnrs
, Dialogs
, NativeXML
, ADODB
, uUtils
, cmpRoomerDataSet
, cmpRoomerConnection
, System.Generics.Collections
;
TYPE
TRateItem = class
FReservation : integer ;
FRoomReservation : integer ;
FRoomNumber : string ;
FRateDate : TDateTime ;
FPriceCode : string ;
FRate : double ;
FDiscount : Double ;
FisPercentage : boolean ;
FShowDiscount : boolean ;
FisPaid : boolean ;
function getRate : Double ;
function getRateDate : TdateTime ;
function getDiscount : Double ;
function GetIsPercentage : boolean ;
function GetShowDiscount : boolean ;
function GetIsPaid : boolean ;
function GetPriceCode : string ;
function GetRoomNumber : string ;
function GetReservation : integer ;
function GetRoomReservation : integer ;
procedure SetRate(Value : double);
procedure SetRateDate(Value : TDateTime);
procedure SetDiscount(Value : double);
procedure SetShowDiscount(Value : boolean);
procedure SetIsPercentage(Value : boolean);
procedure SetISPaid(Value : boolean);
procedure SetPriceCode(Value : string);
procedure SetRoomNumber(Value : string);
procedure SetReservation(Value : integer);
procedure SetRoomReservation(Value : integer);
public
constructor Create(aRate : double;
aRateDate : TDateTime;
aDiscount :double;
aShowDiscount
,aIsPercentage
,aIsPaid : boolean;
aPriceCode
,aRoomNumber : string;
aReservation
,aRoomReservation : integer
);
destructor Destroy; override;
property Rate : double read getRate write setRate ;
property RateDate : TDateTime read getRateDate write setRateDate ;
property Discount : Double read getDiscount write setDiscount ;
property ShowDiscount : boolean read getShowDiscount write setShowDiscount ;
property isPercentage : boolean read getisPercentage write setIsPercentage ;
property isPaid : boolean read getisPaid write setIsPaid ;
property priceCode : string read getPriceCode write setPriceCode ;
property RoomNumber : string read getRoomNumber write setRoomNumber ;
property Reservation : integer read getReservation write setReservation ;
property RoomReservation : integer read getRoomReservation write setRoomReservation;
end;
//////////////////////////////////////////////////////////////////////////////
// TSelectedRoomItem
//////////////////////////////////////////////////////////////////////////////
TRateItemsList = TObjectList<TRateItem>;
//////////////////////////////////////////////////////////////////////////////////////
/// TRates
/////////////////////////////////////////////////////////////////////////////////////
TRates = class
private
FHotelcode : string;
FXmlFileName : string;
FRateCount : integer;
FRateList : TRateItemsList;
FCurrency : String;
function getRateCount : integer;
public
constructor Create(aHotelCode : string);
destructor Destroy; override;
function getCurrency : string;
procedure SetCurrency(Value : string);
function getPriceID : integer;
procedure SetPriceID(Value : integer);
function GetDayRate(RoomType: string;
RoomNumber : string;
aDate : TDateTime;
GuestCount : integer;
ChildCount : integer;
infantCount : integer;
Currency : string;
PriceID : integer;
Discount : double;
showDiscount : boolean;
isPercentage : boolean;
isPaid : boolean;
doAdd : boolean
): double;
property Hotelcode : string read FHotelcode write FHotelcode;
property XmlFileName : string read FXmlFileName write FXmlFileName;
function FindRateByDate(aDate : TDateTime; StartAt : integer) : integer;
function FindRoomAndDate(RoomNumber: string;aDate: TdateTime; StartAt: integer): integer;
property RateItemsList : TRateItemsList read FRateList write FRateList;
property RateCount : integer read getRateCount;
property Currency : string read getCurrency write setCurrency;
end;
implementation
uses
_Glob
,uSqlDefinitions
,hData
, uSQLUtils;
//////////////////////////////////////////////////////////////////////////////
// TRateItem
//////////////////////////////////////////////////////////////////////////////
constructor TRateItem.Create(aRate : double;
aRateDate : TDateTime;
aDiscount :double;
aShowDiscount
,aIsPercentage
,aIsPaid : boolean;
aPriceCode
,aRoomNumber : string;
aReservation
,aRoomReservation : integer
);
begin
setRate(aRate);
setRateDate(aRateDate);
setDiscount(aDiscount);
setIsPercentage(aIsPercentage);
setIsPaid(aIsPaid);
setPriceCode(aPriceCode);
setShowDiscount(aShowDiscount);
setRoomNumber(aRoomNumber);
setReservation(aReservation);
setRoomReservation(aRoomReservation);
end;
destructor TRateItem.Destroy;
begin
inherited;
end;
function TRateItem.getDiscount: Double;
begin
result := FDiscount;
end;
function TRateItem.GetIsPaid: boolean;
begin
result := FIsPaid;
end;
function TRateItem.GetIsPercentage: boolean;
begin
result := FIsPercentage
end;
function TRateItem.GetPriceCode: string;
begin
result := FPriceCode;
end;
function TRateItem.getRate: double;
begin
result := FRate
end;
function TRateItem.getRateDate : TDateTime;
begin
result := FRateDate
end;
function TRateItem.GetReservation: integer;
begin
result := FReservation;
end;
function TRateItem.GetRoomNumber: string;
begin
result := FRoomNumber;
end;
function TRateItem.GetRoomReservation: integer;
begin
result := FRoomReservation;
end;
function TRateItem.GetShowDiscount: boolean;
begin
result := FShowDiscount;
end;
procedure TRateItem.SetDiscount(Value: double);
begin
FDiscount := value;
end;
procedure TRateItem.SetISPaid(Value: boolean);
begin
FIsPaid := Value;
end;
procedure TRateItem.SetIsPercentage(Value: boolean);
begin
FIsPercentage := Value;
end;
procedure TRateItem.SetPriceCode(Value: string);
begin
FPriceCode := Value;
end;
procedure TRateItem.SetRate(Value : double);
begin
FRate := value;
end;
procedure TRateItem.SetRateDate(Value : TDateTime);
begin
FRateDate := value;
end;
procedure TRateItem.SetReservation(Value: integer);
begin
FReservation := value;
end;
procedure TRateItem.SetRoomNumber(Value: string);
begin
FRoomNumber := value;
end;
procedure TRateItem.SetRoomReservation(Value: integer);
begin
FRoomreservation := value;
end;
procedure TRateItem.SetShowDiscount(Value: boolean);
begin
FShowDiscount := value;
end;
//////////////////////////////////////////////////////////////////////
{TRates}
//////////////////////////////////////////////////////////////////////
constructor TRates.Create(aHotelCode : string);
begin
inherited Create;
try
FRateList := TRateItemsList.Create(True);
Except
//TODO Loga
end;
FRateCount := 0;
end;
destructor TRates.Destroy;
begin
freeandnil(FRateList);
inherited;
end;
function TRates.FindRoomAndDate(RoomNumber: string;aDate: TdateTime; StartAt: integer): integer;
var
i : integer;
tmpRoom : string;
tmpDate : Tdate;
begin
aDate := trunc(date);
result := -1;
if StartAt > FRateList.Count-1 then exit;
RoomNumber := ansiLowercase(RoomNumber);
for i := startAt to FRateList.Count -1 do
begin
tmpRoom := FRateList[i].FRoomNumber;
tmpDate := trunc(FRateList[i].FRateDate);
if (RoomNumber = tmproom) and (tmpDate = aDate) then
begin
result := i;
Break;
end;
end;
end;
function TRates.FindRateByDate(aDate : TDateTime; StartAt : integer) : integer;
var
i : integer;
tmpDate : TdateTime;
begin
result := -1;
if StartAt > FRateList.Count-1 then exit;
for i := startAt to FRateList.Count -1 do
begin
tmpDate := FRateList[i].FRateDate;
if tmpDate = aDate then
begin
result := i;
Break;
end;
end;
end;
function TRates.getCurrency: string;
begin
result := FCurrency;
end;
function TRates.getPriceID: integer;
begin
result := 0;
end;
procedure TRates.SetCurrency(Value: string);
begin
FCurrency := Value;
end;
procedure TRates.SetPriceID(Value: integer);
begin
//**
end;
function TRates.getRateCount: integer;
begin
result := FRateList.Count;
end;
function TRates.GetDayRate(RoomType : string;
RoomNumber : string;
aDate : TDateTime;
GuestCount : integer;
ChildCount : integer;
infantCount : integer;
Currency : string;
PriceID : integer;
Discount : double;
showDiscount : boolean;
isPercentage : boolean;
isPaid : boolean;
doAdd : boolean
): double;
var
rSet : TRoomerDataSet;
s: string;
ExtraPrice: double;
p1, p2, p3, p4, p5, p6 : double;
// Price: double;
extraPersons: double;
oRateItem : TRateItem;
priceCode : string;
// iDateCount : integer;
Description : string;
RateExtraChildren : double;
RateExtraInfant : double;
begin
result := 0;
extraPersons := GuestCount - 5;
// Price := 0.00;
if GuestCount < 1 then
begin
exit;
end;
s := s+' SELECT '#10;
s := s+' `wroomrates`.`ID`, '#10;
s := s+' `wroomrates`.`PriceCodeID`, '#10;
s := s+' `wroomrates`.`pcCode`, '#10;
s := s+' `wroomrates`.`pcRack`, '#10;
s := s+' `wroomrates`.`CurrencyID`, '#10;
s := s+' `wroomrates`.`Currency`, '#10;
s := s+' `wroomrates`.`SeasonID`, '#10;
s := s+' `wroomrates`.`seStartDate`, '#10;
s := s+' `wroomrates`.`seEndDate`, '#10;
s := s+' `wroomrates`.`seDescription`, '#10;
s := s+' `wroomrates`.`RoomTypeID`, '#10;
s := s+' `wroomrates`.`RoomType`, '#10;
s := s+' `wroomrates`.`NumberGuests`, '#10;
s := s+' `wroomrates`.`RateID`, '#10;
s := s+' `wroomrates`.`RateCurrency`, '#10;
s := s+' `wroomrates`.`Rate1Person`, '#10;
s := s+' `wroomrates`.`Rate2Persons`, '#10;
s := s+' `wroomrates`.`Rate3Persons`, '#10;
s := s+' `wroomrates`.`Rate4Persons`, '#10;
s := s+' `wroomrates`.`Rate5Persons`, '#10;
s := s+' `wroomrates`.`Rate6Persons`, '#10;
s := s+' `wroomrates`.`RateExtraPerson`, '#10;
s := s+' `wroomrates`.`RateExtraChildren`, '#10;
s := s+' `wroomrates`.`RateExtraInfant`, '#10;
s := s+' `wroomrates`.`rateDescription`, '#10;
s := s+' `wroomrates`.`Active`, '#10;
s := s+' `wroomrates`.`DateFrom`, '#10;
s := s+' `wroomrates`.`DateTo`, '#10;
s := s+' `wroomrates`.`Description`, '#10;
s := s+' `wroomrates`.`DateCreated`, '#10;
s := s+' `wroomrates`.`LastModified`, '#10;
s := s+' DATEDIFF(DateTo,DateFrom) AS DateCount '#10;
s := s+'FROM '#10;
s := s+' `wroomrates` '#10;
s := s+'WHERE '#10;
s := s+' `PriceCodeID` = %d AND '#10;
s := s+' `Currency` = %s AND '#10;
s := s+' `RoomType` = %s AND '#10;
s := s+' `DateFrom` <= %s AND '#10;
s := s+' `DateTo` >= %s '#10;
s := s+'ORDER BY DateCount '#10;
s := s+'LIMIT 0,1 '#10;
rSet := TRoomerDataSet.Create(nil);
try
s := format(s , [priceID,_db(currency),_db(RoomType),_db(aDate),_db(aDate)]);
hData.rSet_bySQL(rSet,s);
// CopyToClipboard(s);
// DebugMessage('select_objRoomRates_GetDayRate'#10+' '+s);
if not rSet.eof then
begin
// iDateCount := Rset.fieldbyname('DateCount').asInteger;
description := rSet.fieldbyname('description').AsString;
RateExtraChildren := Rset.fieldbyname('RateExtraChildren').AsFloat;
RateExtraInfant := Rset.fieldbyname('RateExtraInfant').AsFloat;
ExtraPrice := Rset.fieldbyname('RateExtraPerson').AsFloat;
p1 := Rset.fieldbyname('Rate1Person').AsFloat;
p2 := Rset.fieldbyname('Rate2Persons').AsFloat;
p3 := Rset.fieldbyname('Rate3Persons').AsFloat;
p4 := Rset.fieldbyname('Rate4Persons').AsFloat;
p5 := Rset.fieldbyname('Rate5Persons').AsFloat;
p6 := Rset.fieldbyname('Rate6Persons').AsFloat;
if p1 = 0 then p1 := ExtraPrice;
if p2 = 0 then p2 := p1 + ExtraPrice;
if p3 = 0 then p3 := p2 + ExtraPrice;
if p4 = 0 then p4 := p3 + ExtraPrice;
if p5 = 0 then p5 := p4 + ExtraPrice;
if p6 = 0 then p6 := p5 + ExtraPrice;
if GuestCount = 1 then result := p1;
if GuestCount = 2 then result := p2;
if GuestCount = 3 then result := p3;
if GuestCount = 4 then result := p4;
if GuestCount = 5 then result := p5;
if GuestCount = 6 then result := p6;
if GuestCount > 6 then result := p6 + (extraPersons * ExtraPrice);
result := result+(RateExtraChildren * ChildCount);
result := result+(RateExtraInfant * infantCount);
end;
finally
freeandNil(rSet);
end;
priceCode := hdata.PriceCode_Code(priceID);
if doAdd then
begin
oRateItem := TRateItem.Create(result,aDate,discount,showDiscount,isPercentage,isPaid,priceCode,RoomNumber,-1,-1);
self.FRateList.Add(oRateItem);
end;
end;
end.