-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathuAppGlobal.pas
1632 lines (1418 loc) · 50.5 KB
/
uAppGlobal.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
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit uAppGlobal;
interface
uses
Windows
, Winapi.ShlObj
, System.IOUtils
, Grids
, Forms
, Inifiles
, SysUtils
, Classes
, ADODB
, Data.DB
,_glob
, cmpRoomerDataSet
, cmpRoomerConnection
, Vcl.Menus
, Generics.Collections
, objDayFreeRooms
, uMessageList
, uRoomerLanguage
, uActivityLogs
, stdCtrls
, comCtrls
, extCtrls
, uStringUtils
, sButton
, sCheckBox
, sPageControl
, sTabControl
, sGroupBox
, sLabel
, sPanel
, sComboBox
, sSpeedButton
, cxButtons
, dxBar
, cxDropdownEdit
, cxGridDBTableView
, cxGridBandedTableView
, cxGridDBBandedTableView
, cxDBPivotGrid
, dxRibbon
, dxMdaSet
, cxGrid
, ppCtrls
, AdvEdBtn
, Variants
, Vcl.Buttons
, uRoomerThreadedRequest
, uPMSSettings
, uTableEntityList
;
Type
RecRRInfo = record
RoomReservation: integer;
Reservation: integer;
Channel: integer;
Date: Tdate;
Room: string;
RoomType: string;
resFlag: string;
isNoRoom: boolean;
AscIndex: integer;
DescIndex: integer;
CustomerName: string;
PaymentInvoice: integer;
GroupAccount: boolean;
Percentage: boolean;
PriceType: String;
Currency: String;
Arrival: Tdate;
Departure: Tdate;
active: boolean;
ItemsOnInvoice: boolean;
numGuests: integer;
GuestName, Tel1, Tel2, Fax: String;
Payments, Price, Discount: Double;
Information, PMInfo: String;
RoomClass: string;
BookingId : String;
OutOfOrderBlocking: boolean;
BlockMove: boolean;
BlockMoveReason: String;
OngoingSale : Double;
OngoingTaxes : Double;
OngoingRent : Double;
Invoices,
Guarantee : String;
InvoiceIndex : Integer;
end;
TNumberBase = (INB_USER_EDIT,
INB_ROOM_NIGHT,
INB_GUEST_NIGHT,
INB_GUEST,
INB_ROOM,
INB_BOOKING);
TRoomTypesHolder = class( TObject )
private
FRoomType : string;
FCount : integer;
FNumGuests : integer;
public
end;
TSet_Of_Integer = class
private
list : TList<Integer>;
function GetCount: integer;
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure Add(value : Integer);
function ValueInList(value : Integer) : Boolean;
property Count : integer read GetCount;
end;
{$M+}
TGlobalSettings = class( TObject )
private
FRoomTypes : TList;
FNumAvailType : TStringList;
FRoomFloors : TList<Integer>;
tablesList : TTableDictionary;
FPreviousGuestsSet: TRoomerDataSet;
FPreviousGuestsReload : TGetThreadedData;
FPmsSettings: TPmsSettings;
procedure AddRoomType( sType : string; iNumber, NumGuests : integer );
procedure Clear;
procedure ClearRoomFloors;
// procedure ClearSingleTable(Table: TRoomerDataSet);
function GetChannelsSet: TRoomerDataSet;
function GetControlSet: TRoomerDataSet;
function GetCountries: TRoomerDataSet;
function GetCountryGroups: TRoomerDataSet;
function GetCurrenciesSet: TRoomerDataSet;
function GetItems: TRoomerDataSet;
function GetItemTypes: TRoomerDataSet;
function GetLocations: TRoomerDataSet;
function GetRoomsSet: TRoomerDataSet;
function GetRoomTypeGroups: TRoomerDataSet;
function GetChannelPlanCodes: TRoomerDataSet;
function GetRoomTypeRulesSet: TRoomerDataSet;
function GetRoomTypesSet: TRoomerDataSet;
function GetVAT: TRoomerDataSet;
function GetCustomertypes: TRoomerDataSet;
function GetPaygroups: TRoomerDataSet;
function GetPaytypes: TRoomerDataSet;
function GetTblconvertgroups: TRoomerDataSet;
function GetTblconverts: TRoomerDataSet;
function GetTblpricecodes: TRoomerDataSet;
function GetTblseasons: TRoomerDataSet;
function GetCustomersSet: TRoomerDataSet;
procedure AssertComponent(Comp: TComponent);
function ValidateHelpContext(ctx: Integer): Boolean;
// Function ValidateHelpContext2(ctx : Integer) : Boolean;
function GetPackages: TRoomerDataSet;
function GetPackageItems: TRoomerDataSet;
function GetPersonProfiles: TRoomerDataSet;
function GetBookKeepingCodes: TRoomerDataSet;
function GetChannelManagersSet: TRoomerDataSet;
procedure PreviousGuestsReloadFetchHandler(Sender: TObject);
function GetPmsSettingsSet: TRoomerDataSet;
function GetMaintenanceCodes: TRoomerDataSet;
function GetMaintenanceRoomNotes: TRoomerDataSet;
function GetStaffMembers: TRoomerDataset;
public
constructor Create;
destructor Destroy; override;
procedure LogChanges(DataSet: TDataSet; tableName : String; action: TTableAction; descriptor: String);
function locateId(rSet : TDataset; id : Integer) : Boolean;
procedure FillRoomAndTypeGrid(agrRooms : TStringGrid;
Location : TSet_Of_Integer;
Floor : TSet_Of_Integer;
FreeRoomsFiltered : Boolean = false;
oFreeRooms : TFreeRooms = nil;
zOneDay_dtDate : TDateTime = 0;
numDays : integer = 0);
procedure ReloadPreviousGuests;
procedure ForceTableRefresh;
procedure RefreshTableByName(const aTable: string);
function KeyAlreadyExistsInAnotherRecord(table, field, value: String; ID: Integer): Boolean;
function LocateSpecificRecord(table, field, value: String): Boolean; overload;
function LocateSpecificRecord(dataSet : TRoomerDataSet; field : String; value : Variant) : Boolean; overload; inline;
function LocateSpecificRecord(table, field: String; value: Integer): Boolean; overload;
function LocateSpecificRecord(table, field: String; value: Boolean): Boolean; overload;
function LocateSpecificRecordAndGetValue(table, field, value: String; fieldToGet : String; var resultingValue : String): Boolean; overload;
function LocateSpecificRecordAndGetValue(table, field : String; value : Integer; fieldToGet: String; var resultingValue: String): Boolean; overload;
function LocateSpecificRecordAndGetValue(table, field, value: String; fieldToGet : String; var resultingValue : Integer): Boolean; overload;
function LocateSpecificRecordAndGetValue(table, field, value: String; fieldToGet : String; var resultingValue : Boolean): Boolean; overload;
function LocateSpecificRecordAndGetValue(table, field, value: String; fieldToGet : String; var resultingValue : Double): Boolean; overload;
function LocateSpecificRecordAndGetValue(table, field : String; value : Integer; fieldToGet: String; var resultingValue: Double): Boolean; overload;
function IsValidInList(list: TSet_Of_Integer; intValue : Integer): Boolean;
procedure LoadStaticTables(startingUp : Boolean = False);
procedure RefreshTablesWhenNeeded;
procedure FillRoomAndTypeGridNew(agrRooms : TStringGrid );
procedure FillLocationsMenu(mnu : TPopupMenu; event : TNotifyEvent);
function GetRoomLocation(Room: String): String;
function LocateRoom(Room : String) : Boolean;
function LocateCountryGroup(CountryGroup: String): Boolean;
function LocateLocation(Location: String): Boolean;
function GetRoomStatistics(Room : String) : Boolean;
function GetRoomFloor(Room: String): Integer;
function GetRoomTypeFromRoom(Room: String): String;
function GetLocationId(Location: String): integer;
function GetNumberOfItems( aType : string ) : integer;
function GetRoomTypeNumberGuests( aType : string ) : integer;
function GetRoomTypeNumberGuestsTotal( aType : string ) : integer;
function GetRoomType( iIndex : integer ) : string;
function GetNumberBaseOfItem( item : string ) : TNumberBase;
function GetCountryName(Country : String) : String;
function RoomTypeCount : integer;
function LocateCountry(Country : String) : Boolean;
function LocateItemType(ItemType : String) : Boolean;
function LocateRoomType(RoomType : String) : Boolean;
function LocateCurrency(Currency: String): Boolean;
function LocateChannelById(id : Integer): Boolean;
function LocateChannelColorById(id : Integer): Integer;
function LocateRoomTypeColor(RoomType: String): Integer;
function LocateRoomTypeGroup(RoomTypeGroup : String) : Boolean;
function LocateRoomTypeGroupById(RoomTypeGroupId: Integer): Boolean;
function GetRoomTypeGroupDescription(Code: String): String;
function GetRoomTypeDescription(RoomType : String) : String;
function GET_RoomTypeNumberGuests_byRoom(Room : String) : integer;
function GET_RoomTypeNumberGuests_byRoomType(RoomType: String): integer;
function GetDataCacheLocation : String;
function GetOfflineReportLocation: string;
function GetLanguageLocation: String;
property RoomTypes[ aType : string ] : integer read GetNumberOfItems;
property RoomTypesNumGuests[ aType : string ] : integer read GetRoomTypeNumberGuests;
property RoomTypesNumGuestsTotal[ aType : string ] : integer read GetRoomTypeNumberGuestsTotal;
procedure InitAvailability;
procedure PerformAuthenticationAssertion(Form : TForm);
function AccessAllowed(value : Integer) : boolean;
procedure EnableOrDisableTableRefresh(tablename : String; enable: Boolean);
function LocationSQLInString(locationlist : TSet_Of_Integer) : string;
function getPackageNameByPackageCode(packageCode : String) : String;
procedure fillListWithMonthsLong(List : TStrings; fromIndex : Integer);
procedure fillListWithMonthsShort(List: TStrings; fromIndex : Integer);
procedure fillListWithYears(List : TStrings; FromIndex : Integer; ForwardOnly : Boolean);
procedure LoadCurrentRecordFromDataSet(ToSet, DataSet: TDataSet; _AppendRecord: Boolean);
function GetRateInclusive(channelId: Integer; Item : String; Rate: Double): Double;
function GetRateExclusive(Item : String; Rate : Double) : Double;
function isCustomerCityTaxIncluded(Customer : String) : Boolean;
function GetIntegerValueOfFieldFromId(tableName : String; fieldName : String; id: Integer): Integer;
function GetBooleanValueOfFieldFromId(tableName : String; fieldName : String; id: Integer): boolean;
property PMSSettings: TPmsSettings read FPmsSettings;
published
property PreviousGuestsSet : TRoomerDataSet read FPreviousGuestsSet;
property RoomsSet : TRoomerDataSet read GetRoomsSet;
property RoomTypeRulesSet: TRoomerDataSet read GetRoomTypeRulesSet;
property RoomTypesSet : TRoomerDataSet read GetRoomTypesSet;
property ChannelsSet : TRoomerDataSet read GetChannelsSet;
property ChannelManagersSet : TRoomerDataSet read GetChannelManagersSet;
property CurrenciesSet : TRoomerDataSet read GetCurrenciesSet;
property ControlSet : TRoomerDataSet read GetControlSet;
property CustomersSet : TRoomerDataSet read GetCustomersSet;
property RoomTypeGroups : TRoomerDataSet read GetRoomTypeGroups;
property ChannelPlanCodes: TRoomerDataSet read GetChannelPlanCodes;
property Items : TRoomerDataSet read GetItems;
property ItemTypes : TRoomerDataSet read GetItemTypes;
property CountryGroups : TRoomerDataSet read GetCountryGroups;
property Locations : TRoomerDataSet read GetLocations;
property Countries : TRoomerDataSet read GetCountries;
property VAT : TRoomerDataSet read GetVAT;
property Packages : TRoomerDataSet read GetPackages;
property PackageItems : TRoomerDataSet read GetPackageItems;
property PersonProfiles : TRoomerDataSet read GetPersonProfiles;
property BookKeepingCodes : TRoomerDataSet read GetBookKeepingCodes;
property TblconvertsSet : TRoomerDataSet read GetTblconverts;
property TblconvertgroupsSet : TRoomerDataSet read GetTblconvertgroups;
property PaygroupsSet : TRoomerDataSet read GetPaygroups;
property PaytypesSet : TRoomerDataSet read GetPaytypes;
property TblseasonsSet : TRoomerDataSet read GetTblseasons;
property TblpricecodesSet : TRoomerDataSet read GetTblpricecodes;
property CustomertypesSet : TRoomerDataSet read GetCustomertypes;
property MaintenanceCodes : TRoomerDataSet read GetMaintenanceCodes;
property Maintenanceroomnotes : TRoomerDataSet read GetMaintenanceRoomNotes;
property Staffmembers : TRoomerDataset read GetStaffMembers;
property NumAvailType : TStringList read FNumAvailType write FNumAvailType;
end;
var
glb : TGlobalSettings = nil;
AppInifile : string;
RoomerLanguage : TRoomerLanguage;
const
FMHandle : THandle = 0;
RIGHTS_REPORTS_FINANCE = 94;
RIGHTS_REPORTS_GUESTS = 80;
RIGHTS_INVOICE = 88;
RIGHTS_BASE_TABLES = 90;
RIGHTS_PRICES = 90;
RIGHTS_BOOKINGS = 90;
cOfflinefoldername = 'offlinereports';
cDatacachefoldername = 'datacache';
procedure OpenAppSettings;
procedure CloseAppSettings;
procedure FilterRoom( RoomNumber : string );
implementation
uses dbTables
, Registry
, dialogs
, uSqlDefinitions
, hData
, ud
, ug
, uUtils
, PrjConst
, uFileSystemUtils;
procedure FilterRoom( RoomNumber : string );
begin
with glb.RoomsSet do
begin
Filter := 'Room=''' + RoomNumber + '''';
Filtered := true;
end;
end;
{
{ TGlobalSettings }
constructor TGlobalSettings.Create;
begin
tablesList := TTableDictionary.Create([doOwnsValues]);
tablesList.InitializeTables;
FRoomFloors := TList<Integer>.Create;
FRoomTypes := TList.Create;
FNumAvailType := TStringlist.create;
FPMSSettings := TPmsSettings.Create(GetPmsSettingsSet);
FPreviousGuestsReload := TGetThreadedData.Create;
FPreviousGuestsSet := nil;
ReloadPreviousGuests;
LoadStaticTables(true);
end;
destructor TGlobalSettings.Destroy;
begin
clear;
FNumAvailType.free;
ClearRoomFloors;
FRoomtypes.Free;
FRoomFloors.free;
FPreviousGuestsReload.Free;
tablesList.Clear;
FreeAndNil(tablesList);
FPmsSettings.Free;
end;
procedure TGlobalSettings.LogChanges(DataSet: TDataSet; tableName : String; action : TTableAction; descriptor : String);
var i : Integer;
Field : TField;
Value, OldValue : String;
begin
if action = CHANGE_FIELD then
begin
for i := 0 to DataSet.FieldCount - 1 do
begin
Field := DataSet.Fields[i];
if Field.DataType IN [ftUnknown, ftString, ftSmallint, ftInteger, ftWord,
ftBoolean, ftFloat, ftCurrency, ftDate, ftTime, ftDateTime,
ftAutoInc, ftMemo, ftFmtMemo, ftFixedChar, ftWideString,
ftLargeint, ftTimeStamp, ftWideMemo, ftLongWord, ftShortint,
ftByte, ftExtended, ftSingle] then
begin
Value := VarToStr(Field.Value);
OldValue := VarToStr(Field.OldValue);
if Value <> OldValue then
AddTableChangeActivityLog(d.roomerMainDataSet.username,
action,
tableName + '.' + field.FieldName,
DataSet['id'],
OldValue,
Value,
'');
end;
end;
end else
if action = DELETE_RECORD then
begin
AddTableChangeActivityLog(d.roomerMainDataSet.username,
action,
tableName,
DataSet['id'],
descriptor,
'',
format('User %s deleted record with id %d, description: %s',
[d.roomerMainDataSet.username,
DataSet['id'],
descriptor]));
end else
if action = ADD_RECORD then
begin
AddTableChangeActivityLog(d.roomerMainDataSet.username,
action,
tableName,
-1,
descriptor,
'',
format('User %s added record with description: %s',
[d.roomerMainDataSet.username,
descriptor]));
end;
end;
var PreviousGuestsReload : TGetThreadedData = nil;
procedure TGlobalSettings.ReloadPreviousGuests;
const PREV_GUESTS_SQL = 'SELECT DISTINCT * FROM ' +
'( ' +
'SELECT CONCAT(''PE'',pe.ID) AS ID, pe.title, pe.PersonalIdentificationId AS PassPortNumber, ' +
' pe.Name, pe.Surname AS CustomerName, pe.Address1, pe.Address2, pe.Address3, pe.Address4, pe.Country, pe.Tel1, pe.Tel2, pe.Email, pe.SocialSecurityNumber, pe.CompVATNumber, pe.CompFax ' +
'FROM persons pe JOIN reservations r ON r.Reservation=pe.Reservation AND r.Departure > DATE_ADD(CURRENT_DATE, INTERVAL 365*-3 DAY) ' +
'WHERE pe.MainName=1 ' +
'AND pe.Surname <> '''' ' +
'AND pe.Address1 <> '''' ' +
'AND pe.Country <> '''' ' +
'AND (pe.Tel1 <> '''' OR pe.Tel2 <> '''' OR pe.Email <> '''') ' +
'UNION ALL ' +
'SELECT CONCAT(''RV'',ID) AS ID, '''' AS title, '''' AS PassPortNumber, Contactname AS Name, Name AS CustomerName, ContactAddress1, ContactAddress2, ContactAddress3, ContactAddress4, ContactCountry, ContactPhone, ContactPhone2, ContactEmail, '''', '''', ContactFax ' +
'FROM reservations ' +
'WHERE Contactname <> '''' ' +
'AND ContactAddress1 <> '''' ' +
'AND ContactCountry <> '''' ' +
'AND (ContactPhone <> '''' OR ContactPhone2 <> '''' OR ContactEmail <> '''') ' +
'AND Departure > DATE_ADD(CURRENT_DATE, INTERVAL 365*-3 DAY) ' +
'UNION ALL ' +
'SELECT CONCAT(''CU'',ID) AS ID, title, '''' AS PassPortNumber, Surname AS Name, Surname AS CustomerName, Address1, Address2, Address3, Address4, Country, Tel1, Tel2, EmailAddress, '''', '''', Fax ' +
'FROM customers ' +
'WHERE Surname <> '''' ' +
'AND Address1 <> '''' ' +
'AND Country <> '''' ' +
'AND (CONCAT(Tel1,Tel2,EmailAddress) <> '''') ' +
'ANd active=1 ' +
') xxx ';
begin
FPreviousGuestsReload.execute(PREV_GUESTS_SQL, PreviousGuestsReloadFetchHandler);
end;
procedure TGlobalSettings.PreviousGuestsReloadFetchHandler(Sender : TObject);
begin
FPreviousGuestsSet := FPreviousGuestsReload.RoomerDataSet;
FPreviousGuestsSet.First;
end;
function TGlobalSettings.locateId(rSet : TDataset; id : Integer) : Boolean;
begin
result := False;
rSet.First;
while NOT rSet.Eof do
begin
if rSet['ID'] = id then
begin
result := True;
Break;
end;
rSet.Next;
end;
end;
function TGlobalSettings.GetRateInclusive(channelId : Integer; Item : String; Rate : Double) : Double;
begin
result := Rate;
if (channelId = -1) AND LocateSpecificRecord('channels', 'default', true) OR
(channelId <> -1) AND LocateSpecificRecord('channels', 'id', channelId) then
if GetChannelsSet['ratesExcludingTaxes'] then
if LocateSpecificRecord('items', 'Item', Item) then
if LocateSpecificRecord('itemtypes', 'ItemType', GetItems.FieldByName('ItemType').AsString) then
if LocateSpecificRecord('vatcodes', 'VATCode', GetItemTypes.FieldByName('VATCode').AsString) then
result := Rate * (1 + (GetVAT.GetFloatValue(getVat.FieldByName('VATPercentage'))/100));
end;
function TGlobalSettings.GetRateExclusive(Item : String; Rate : Double) : Double;
begin
result := Rate;
if LocateSpecificRecord('items', 'Item', Item) then
if LocateSpecificRecord('itemtypes', 'ItemType', GetItems.FieldByName('ItemType').AsString) then
if LocateSpecificRecord('vatcodes', 'VATCode', GetItemTypes.FieldByName('VATCode').AsString) then
result := Rate / (1 + (GetVAT.GetFloatValue(getVat.FieldByName('VATPercentage'))/100));
end;
function TGlobalSettings.GetIntegerValueOfFieldFromId(tableName : String; fieldName : String; id : Integer) : Integer;
var dataSet : TRoomerDataSet;
begin
dataset := tablesList.Dataset[tableName];
if locateId(dataset, id) then
begin
result := dataset[fieldName];
end else
result := -1;
end;
function TGlobalSettings.GetBooleanValueOfFieldFromId(tableName : String; fieldName : String; id : Integer) : boolean;
var dataSet : TRoomerDataSet;
begin
dataset := tablesList.Dataset[tableName];
if locateId(dataset, id) then
begin
result := dataset[fieldName];
end else
result := false;
end;
function TGlobalSettings.LocationSQLInString(locationlist : TSet_Of_Integer) : string;
var
locationID : integer;
s : string;
begin
result := '';
if (locationList.Count = 0) or (locationList.Count = glb.Locations.recordCount) then exit;
s := '';
glb.Locations.first;
while not glb.locations.eof do
begin
locationID := glb.Locations.FieldByName('ID').asinteger;
if LocationList.ValueInList(locationID) then
begin
s := s+_db(glb.Locations.FieldByName('location').AsString)+',';
end;
glb.Locations.next;
end;
if length(s) > 0 then delete(s,length(s),1);
result := s;
end;
procedure TGlobalSettings.EnableOrDisableTableRefresh(tablename : String; enable: Boolean);
var tableEntity : TTableEntity;
begin
tableEntity := tablesList[tableName];
if assigned(tableEntity) then
begin
tableEntity.RefreshEnabled := enable;
if enable then
tableEntity.RefreshFromServer;
end;
end;
procedure TGlobalSettings.fillListWithMonthsLong(List: TStrings; fromIndex : Integer);
var i : Integer;
begin
for i := 1 to 12 do
begin
list.Delete(i-1 + fromIndex);
list.insert(i-1 + fromIndex, GetTranslatedText('shSystem_Months_Long_' + inttostr(i)));
end;
end;
procedure TGlobalSettings.fillListWithMonthsShort(List: TStrings; fromIndex : Integer);
var i : Integer;
begin
for i := 1 to 12 do
begin
list.Delete(i-1 + fromIndex);
list.insert(i-1 + fromIndex, GetTranslatedText('shSystem_Months_Short_' + inttostr(i)));
end;
end;
procedure TGlobalSettings.fillListWithYears(List: TStrings; FromIndex : Integer; ForwardOnly: Boolean);
var i : Integer;
iStart : Integer;
begin
iStart := 2010;
if ForwardOnly then
iStart := Year(now);
for i := iStart to Year(Now) + 15 do
begin
list.Delete(i-iStart + fromIndex);
list.Insert(i-iStart + fromIndex, inttostr(i));
end;
end;
procedure TGlobalSettings.ClearRoomFloors;
begin
while (FRoomFloors.Count > 0) do
begin
FRoomFloors.Delete(0);
end;
end;
procedure TGlobalSettings.Clear;
var
i : integer;
begin
for i := FRoomTypes.count - 1 downto 0 do
begin
TRoomTypesHolder(FRoomTypes[i]).free;
FRoomTypes.delete(i);
end;
end;
procedure TGlobalSettings.FillLocationsMenu(mnu: TPopupMenu; event : TNotifyEvent);
var item : TMenuItem;
i : integer;
begin
mnu.Items.Clear;
locations.First;
while NOT locations.Eof do
begin
item := TMenuItem.Create(nil);
item.Caption := format('%s [%s]', [locations['Description'], locations['Location']]);
item.Tag := locations['Id'] + 1000;
item.OnClick := event;
mnu.Items.Add(item);
locations.Next;
end;
item := TMenuItem.Create(nil);
item.Caption := '-';
mnu.Items.Add(item);
for i := 0 to FRoomFloors.Count - 1 do
begin
item := TMenuItem.Create(nil);
item.Caption := format('%s %d', [GetTranslatedText('shTx_Floor'), FRoomFloors[i]]);
item.Tag := FRoomFloors[i];
item.OnClick := event;
mnu.Items.Add(item);
end;
end;
procedure TGlobalSettings.FillRoomAndTypeGrid(agrRooms : TStringGrid;
Location : TSet_Of_Integer;
Floor : TSet_Of_Integer;
FreeRoomsFiltered : Boolean = false;
oFreeRooms : TFreeRooms = nil;
zOneDay_dtDate : TDateTime = 0;
numDays : integer = 0);
var l : integer;
sTemp : String;
dtdate : TDateTime;
iNextOcc : integer;
resultFilter : Boolean;
FloorFilterActive,
LocationFilterActive,
FloorFilterPassed,
LocationFilterPassed,
FilterPassed : Boolean;
begin
// --
if agrRooms.ColCount < 2 then
agrRooms.ColCount := 2;
with roomsSet do
begin
first;
l := 1;
while not eof do
begin
if not RoomsSet['Hidden'] then
begin
FloorFilterActive := Floor.Count > 0;
LocationFilterActive := Location.Count > 0;
FloorFilterPassed := IsValidInList(Floor, RoomsSet['Floor']);
LocationFilterPassed := IsValidInList(Location, GetLocationId(RoomsSet['Location']));
FilterPassed := (NOT FloorFilterActive) OR (FloorFilterPassed AND FloorFilterActive);
FilterPassed := FilterPassed AND
((NOT LocationFilterActive) OR (LocationFilterPassed AND LocationFilterActive));
resultFilter := FilterPassed
AND (NOT FreeRoomsFiltered);
if resultFilter then
begin
sTemp := oFreeRooms.FindRoomNextOcc(FieldByName( 'Room' ).AsString);
if sTemp = '' then
begin
dtdate := zOneDay_dtDate + 1000;
end else dtDate := _DBDateToDate(sTemp);
iNextOcc := trunc(dtDate)-trunc(zOneDay_dtDate);
resultFilter := iNextOcc >= numDays;
end;
if resultFilter then
begin
inc(l);
agrRooms.RowCount :=l;
agrRooms.Cells[ 0, l - 1 ] := FieldByName( 'Room' ).AsString;
agrRooms.Cells[ 1, l - 1 ] := FieldByName( 'RoomType' ).AsString;
end;
end;
next;
end;
end;
agrRooms.RowCount := agrRooms.RowCount + 1;
end;
function TGlobalSettings.IsValidInList(list : TSet_Of_Integer; intValue : Integer) : Boolean;
begin
result := (list.Count = 0) OR (list.ValueInList(intValue));
end;
procedure TGlobalSettings.FillRoomAndTypeGridNew(agrRooms : TStringGrid );
var l : integer;
begin
// --
if agrRooms.ColCount < 3 then agrRooms.ColCount := 3;
with RoomsSet do
begin
first;
l := 1;
while not eof do
begin
if (RoomsSet['Hidden'] = false) and (RoomsSet['bookable'] = true) then
begin
inc( l );
agrRooms.RowCount := l;
agrRooms.Cells[ 0, l - 1 ] := FieldByName( 'Room' ).AsString;
agrRooms.Cells[ 1, l - 1 ] := FieldByName( 'Description' ).AsString+' ('+FieldByName( 'location' ).AsString+') ';;
agrRooms.Cells[ 2, l - 1 ] := FieldByName( 'RoomType' ).AsString;
end;
next;
end;
end;
end;
procedure TGlobalSettings.RefreshTablesWhenNeeded;
begin
tablesList.RefreshAllIfNeeded;
end;
procedure TGlobalSettings.ForceTableRefresh;
begin
RoomerMessages.RefreshTabelStateList;
tablesList.RefreshAllIfNeeded;
end;
procedure TGlobalSettings.RefreshTableByName(const aTable: string);
begin
tablesList.TableEntity[aTable].RefreshFromServer;
end;
procedure TGlobalSettings.LoadStaticTables(startingUp : Boolean = False);
var
rSet: TRoomerDataSet;
s : string;
bTemp : Boolean;
begin
tableslist.RefreshAllLocally(startingUp);
if NOT d.roomerMainDataSet.OfflineMode then
begin
FRoomFloors.Clear;
RoomsSet.First;
while not RoomsSet.eof do
begin
if not FRoomFloors.Contains(RoomsSet['Floor']) then
FRoomFloors.Add(RoomsSet['Floor']);
RoomsSet.next;
end;
FRoomFloors.Sort;
rSet := CreateNewDataSet;
try
rSet.CommandType := cmdText;
s := format(select_GlobalSettings_LoadStaticTables, []);
hData.rSet_bySQL(rSet,s);
rSet.First;
while not rSet.eof do
begin
AddRoomType( rSet.FieldByName( 'RoomType' ).AsString, 1, rSet.FieldByName( 'NumberGuests' ).AsInteger);
rSet.next;
end;
finally
freeandnil(rSet);
end;
RoomTypesSet.First;
while not RoomTypesSet.eof do
begin
if LocateSpecificRecordAndGetValue('rooms', 'RoomType', RoomTypesSet.FieldByName( 'RoomType' ).AsString, 'Bookable', bTemp) AND bTemp then
AddRoomType( RoomTypesSet.FieldByName( 'RoomType' ).AsString,
1,
RoomTypesSet.FieldByName( 'NumberGuests' ).AsInteger);
RoomTypesSet.next;
end;
end;
end;
function TGlobalSettings.GetDataCacheLocation: String;
var AppDataPath : String;
DataCache: String;
begin
AppDataPath := TPath.Combine(LocalAppDataPath, 'Roomer');
DataCache := format('%s\' + cDatacachefoldername, [d.roomerMainDataSet.hotelId]);
result := TPath.Combine(AppDataPath, DataCache);
forceDirectories(result);
end;
function TGlobalSettings.GetOfflineReportLocation: string;
var AppDataPath : String;
begin
AppDataPath := TPath.Combine(LocalAppDataPath, 'Roomer');
result := format('%s\' + cofflinefoldername,[d.roomerMainDataSet.hotelId]);
result := TPath.Combine(AppDataPath, Result);
forceDirectories(result);
end;
function TGlobalSettings.GetLanguageLocation: String;
begin
result := TPath.Combine(LocalAppDataPath, 'Roomer');
result := TPath.Combine(result, 'Languages');
forceDirectories(result);
end;
function TGlobalSettings.GetPmsSettingsSet: TRoomerDataSet;
begin
result := tableslist.Dataset['pms_settings'];
end;
function TGlobalSettings.GetChannelsSet: TRoomerDataSet;
begin
result := tableslist.Dataset['channels'];
end;
function TGlobalSettings.GetControlSet: TRoomerDataSet;
begin
result := tableslist.Dataset['control'];
end;
function TGlobalSettings.GetCountries: TRoomerDataSet;
begin
result := tableslist.Dataset['countries'];
end;
function TGlobalSettings.GetCountryGroups: TRoomerDataSet;
begin
result := tableslist.Dataset['countrygroups'];
end;
function TGlobalSettings.GetCountryName(Country: String): String;
begin
result := '';
if LocateCountry(Country) then
result := Countries['CountryName'];
end;
function TGlobalSettings.GetCurrenciesSet: TRoomerDataSet;
begin
result := tableslist.Dataset['currencies'];
end;
function TGlobalSettings.GetCustomersSet: TRoomerDataSet;
begin
result := tableslist.Dataset['customers'];
end;
function TGlobalSettings.GetCustomertypes: TRoomerDataSet;
begin
result := tableslist.Dataset['customertypes'];
end;
function TGlobalSettings.GetItems: TRoomerDataSet;
begin
result := tableslist.Dataset['items'];
end;
function TGlobalSettings.GetItemTypes: TRoomerDataSet;
begin
result := tableslist.Dataset['itemtypes'];
end;
function TGlobalSettings.GetLocationId(Location : String) : integer;
begin
result := 0;
Locations.First;
while not Locations.eof do
begin
if LowerCase(Locations['Location']) = LowerCase(Location) then
begin
result := Locations['Id'];
Break;
end;
Locations.next;
end;
end;
function TGlobalSettings.GetLocations: TRoomerDataSet;
begin
result := tableslist.Dataset['locations'];
end;
function TGlobalSettings.GetMaintenanceCodes: TRoomerDataSet;
begin
Result := tablesList.Dataset['maintenancecodes'];
end;
function TGlobalSettings.GetMaintenanceRoomNotes: TRoomerDataSet;
begin
Result := TablesList.Dataset['maintenanceroomnotes'];
end;
function TGlobalSettings.LocateSpecificRecord(table, field, value : String) : Boolean;
var dataSet : TRoomerDataSet;
begin
Result := false;
dataset := tableslist.Dataset[table];
if assigned(Dataset) then
result := LocateSpecificRecord(dataset, field, value);
end;
function TGlobalSettings.KeyAlreadyExistsInAnotherRecord(table, field, value : String; ID : Integer) : Boolean;
var dataSet : TRoomerDataSet;
begin
result := false;
dataset := tableslist.Dataset[table];
dataSet.First;
while not dataSet.eof do
begin
if (LowerCase(dataSet[field]) = LowerCase(value)) AND (dataSet['ID'] <> ID) then
begin
result := true;
Break;
end;
dataSet.next;
end;
end;
function TGlobalSettings.LocateSpecificRecord(dataSet : TRoomerDataSet; field : String; value : Variant) : Boolean;
var
lFld: TField;
begin
try
result := dataset.Locate(field, value, [loCaseInsensitive]);
except
result := false;
end;
end;
function TGlobalSettings.LocateSpecificRecord(table, field : String; value : Integer) : Boolean;
var dataSet : TRoomerDataSet;
begin