-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathuChannelAvailabilityManager.pas
5241 lines (4691 loc) · 177 KB
/
uChannelAvailabilityManager.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 uChannelAvailabilityManager;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Data.Win.ADODB,
cmpRoomerDataSet, Vcl.Grids, AdvObj, BaseGrid, AdvGrid, Vcl.ExtCtrls,
Vcl.StdCtrls, sLabel,
Vcl.Mask, sMaskEdit, sCustomComboEdit, sTooledit, sButton, sPanel,
System.Generics.Collections, acPNG, Vcl.ImgList, cxPropertiesStore,
Vcl.ComCtrls,
sPageControl, Vcl.OleCtrls, SHDocVw, mshtml, RoomerCloudEntities,
AdvTimePickerDropDown, sEdit, sCheckBox, sComboBox,
uUtils, Vcl.Menus, uD, sGroupBox, sBevel, UbuntuProgress, ActiveX, HTMLabel,
cxClasses, acImage, clisted, uRoomerThreadedRequest, cxGraphics, cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore, dxSkinCaramel, dxSkinCoffee,
dxSkinDarkSide, dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, cxButtons, AdvEdit, AdvEdBtn, PlannerDatePicker,
dxSkinBlack, dxSkinBlue, dxSkinDevExpressDarkStyle, dxSkinFoggy, dxSkinLiquidSky, dxSkinMcSkin, dxSkinOffice2013White, dxSkinWhiteprint, CheckComboBox,
AdvUtil;
type
TChannelManagerValue = class
FId: integer;
FDescription: String;
FAdminUser: String;
FAdminPassword: String;
FNumDays: integer;
public
constructor Create(Id: integer; const description, username, password: String; _numDays: integer);
end;
TPlanCodeValue = class
FId: integer;
FCode: String;
FDescription: String;
public
constructor Create(Id: integer; const Code, description: String);
end;
TCellData = class
private
FId: integer;
FDate: TDateTime;
FPlanCodeId: integer;
FOriginalValue: Variant;
FOriginalMaxValue: Variant;
FMaxValue: Variant;
FCurrentValue: Variant;
FRoomClassId: integer;
FChannelManagerId: integer;
FIsEditable: Boolean;
FForceRefresh: Boolean;
FLinkElement: String;
FRoomClassCode: String;
function GetChanged: Boolean;
function GetEdited: Boolean;
public
constructor Create(Id: integer; date: TDateTime; IsEditable: Boolean; const LinkElement: String; PlanCodeId, RoomClassId, ChannelManagerId: integer;
const RoomClassCode: String; originalValue: Variant; maxAvailability: Variant);
destructor Destroy; override;
property date: TDateTime read FDate;
property Id: integer read FId;
property PlanCodeId: integer read FPlanCodeId;
property RoomClassId: integer read FRoomClassId;
property ChannelManagerId: integer read FChannelManagerId;
property originalValue: Variant read FOriginalValue write FOriginalValue;
property MaxValue: Variant read FMaxValue write FMaxValue;
property CurrentValue: Variant read FCurrentValue write FCurrentValue;
property IsEditable: Boolean read FIsEditable write FIsEditable;
property LinkElement: String read FLinkElement write FLinkElement;
property RoomClassCode: String read FRoomClassCode write FRoomClassCode;
property ForceRefresh: Boolean read FForceRefresh write FForceRefresh;
property Changed: Boolean read GetChanged;
property Edited: Boolean read GetEdited;
end;
TfrmChannelAvailabilityManager = class;
TPriceData = class
private
FDate: TDateTime;
FChannelManager: integer;
FId: integer;
FOldValue: Double;
FPrice: Double;
FChannelId: integer;
FRateRoundingType: integer;
FRoomTypeGroupId: integer;
FRoomTypeGroupCode, FRoomTypeTopClass: String;
FStopSell: Boolean;
FMinStay: integer;
ForcingUpdate: Boolean;
FAvailability: integer;
FMaxStay: integer;
FCOA: Boolean;
FCOD: Boolean;
FLOSArrivalDateBased: Boolean;
FSingleUsePrice: Double;
FPriceDirty, FAvailabilityDirty, FStopSellDirty, FMaxStayDirty, FMinStayDirty, FCOADirty, FCODDirty, FLOSArrivalDateBasedDirty,
FSingleUsePriceDirty: Boolean;
FconnectSingleUseRateToMasterRate: Boolean;
FconnectRateToMasterRate: Boolean;
FsingleUseRateDeviationType: String;
FmasterRateSingleUseRateDeviation: Double;
FRateDeviationType: String;
FmasterRateRateDeviation: Double;
FconnectMaxStayToMasterRate: Boolean;
FconnectCOAToMasterRate: Boolean;
FconnectCODToMasterRate: Boolean;
FconnectMinStayToMasterRate: Boolean;
FconnectAvailabilityToMasterRate: Boolean;
FconnectLOSToMasterRate: Boolean;
FconnectStopSellToMasterRate: Boolean;
procedure SetPrice(const value: Double);
procedure SetAvailability(const value: integer);
procedure SetCOA(const value: Boolean);
procedure SetCOD(const value: Boolean);
procedure SetLOSArrivalDateBased(const value: Boolean);
procedure SetMaxStay(const value: integer);
procedure SetSingleUsePrice(const value: Double);
procedure setMinStay(const value: integer);
function isEdited: Boolean;
procedure setStopSell(const value: Boolean);
public
constructor Create(_Id: integer; const roomtypeGroupCode, _roomTypeTopClass: String; date: TDateTime;
rateRoundingType, channelId, roomTypeGroupId, channelManager: integer; price: Double; stopSell: Boolean; minStay: integer; _Availability: integer;
_MaxStay: integer; _COA: Boolean; _COD: Boolean; _LOSArrivalDateBased: Boolean; _SingleUsePrice: Double
;
_connectRateToMasterRate : Boolean;
_masterRateRateDeviation : Double;
const _RateDeviationType : String;
_connectSingleUseRateToMasterRate : Boolean;
_masterRateSingleUseRateDeviation : Double;
const _singleUseRateDeviationType : String;
_connectStopSellToMasterRate : Boolean;
_connectAvailabilityToMasterRate : Boolean;
_connectMinStayToMasterRate : Boolean;
_connectMaxStayToMasterRate : Boolean;
_connectCOAToMasterRate : Boolean;
_connectCODToMasterRate : Boolean;
_connectLOSToMasterRate : Boolean
);
destructor Destroy; override;
procedure ClearEdited;
property Id: integer read FId;
property stopSell: Boolean read FStopSell Write setStopSell;
property minStay: integer read FMinStay Write setMinStay;
property channelId: integer read FChannelId;
property rateRoundingType: integer read FRateRoundingType;
property roomTypeGroupId: integer read FRoomTypeGroupId;
property roomtypeGroupCode: String read FRoomTypeGroupCode;
property RoomTypeTopClass: String read FRoomTypeTopClass;
property price: Double read FPrice write SetPrice;
property Availability: integer read FAvailability write SetAvailability;
property MaxStay: integer read FMaxStay write SetMaxStay;
property COA: Boolean read FCOA write SetCOA;
property COD: Boolean read FCOD write SetCOD;
property LOSArrivalDateBased: Boolean read FLOSArrivalDateBased write SetLOSArrivalDateBased;
property SingleUsePrice: Double read FSingleUsePrice write SetSingleUsePrice;
property date: TDateTime read FDate;
property channelManager: integer read FChannelManager;
property connectRateToMasterRate : Boolean read FconnectRateToMasterRate write FconnectRateToMasterRate;
property masterRateRateDeviation : Double read FmasterRateRateDeviation write FmasterRateRateDeviation;
property RateDeviationType : String read FRateDeviationType write FRateDeviationType;
property connectSingleUseRateToMasterRate : Boolean read FconnectSingleUseRateToMasterRate write FconnectSingleUseRateToMasterRate;
property masterRateSingleUseRateDeviation : Double read FmasterRateSingleUseRateDeviation write FmasterRateSingleUseRateDeviation;
property singleUseRateDeviationType : String read FsingleUseRateDeviationType write FsingleUseRateDeviationType;
property connectStopSellToMasterRate : Boolean read FconnectStopSellToMasterRate write FconnectStopSellToMasterRate;
property connectAvailabilityToMasterRate : Boolean read FconnectAvailabilityToMasterRate write FconnectAvailabilityToMasterRate;
property connectMinStayToMasterRate : Boolean read FconnectMinStayToMasterRate write FconnectMinStayToMasterRate;
property connectMaxStayToMasterRate : Boolean read FconnectMaxStayToMasterRate write FconnectMaxStayToMasterRate;
property connectCOAToMasterRate : Boolean read FconnectCOAToMasterRate write FconnectCOAToMasterRate;
property connectCODToMasterRate : Boolean read FconnectCODToMasterRate write FconnectCODToMasterRate;
property connectLOSToMasterRate : Boolean read FconnectLOSToMasterRate write FconnectLOSToMasterRate;
end;
TDictionaryItem = class
private
FCode: String;
FDate: String;
fvalue: integer;
public
constructor Create(const Code, ADate: String; value: integer);
end;
TColumns = Array Of TCellData;
TRowsOfColumns = Array Of TColumns;
TDictItemObjectDictionary = TObjectDictionary<String, TDictionaryItem>;
TfrmChannelAvailabilityManager = class(TForm)
timStart: TTimer;
ImageList1: TImageList;
FormStore: TcxPropertiesStore;
pgcPages: TsPageControl;
sTabSheet1: TsTabSheet;
sTabSheet2: TsTabSheet;
Panel2: TsPanel;
sPanel1: TsPanel;
btnSave: TsButton;
sPanel2: TsPanel;
grid: TAdvStringGrid;
pnlBulkChanges: TsPanel;
lblBulkUpdate: TsLabel;
lblAmountType: TsLabel;
Label3: TsLabel;
Label4: TsLabel;
edtAvail: TsEdit;
cbxRoomTypes: TCheckComboBox;
dtBulkFrom: TsDateEdit;
dtBulkTo: TsDateEdit;
cbTue: TsCheckBox;
cbWen: TsCheckBox;
cbFri: TsCheckBox;
cbThu: TsCheckBox;
cbSat: TsCheckBox;
cbSun: TsCheckBox;
btnApplyBulk: TsButton;
sButton2: TsButton;
cbMon: TsCheckBox;
rateGrid: TAdvStringGrid;
sPanel10: TsPanel;
sPanel11: TsPanel;
btnPublish: TsButton;
Panel1: TsPanel;
lblEditing: TsLabel;
sPanel9: TsPanel;
cbxChannelManagers: TsComboBox;
cbxChannel: TCheckComboBox;
lblChannel: TsLabel;
mnuRates: TPopupMenu;
C1: TMenuItem;
P1: TMenuItem;
N1: TMenuItem;
C2: TMenuItem;
R1: TMenuItem;
sButton1: TsButton;
sButton3: TsButton;
timRecalc: TTimer;
sPanel6: TsPanel;
cbxStopMinOptions: TsCheckBox;
cbxPlanCodes: TsComboBox;
sButton4: TsButton;
sButton5: TsButton;
pnlProgress: TsPanel;
prgSaving: TUbuntuProgress;
lblReadSave: TsLabel;
sPanel3: TsPanel;
cbxShowLinkedCells: TsCheckBox;
cbxAvailType: TsComboBox;
pnlHolder: TsPanel;
btnClose: TsButton;
cbxExtraRestrictions: TsCheckBox;
lblDCAvailability: TsLabel;
edtDCAvailbility: TsEdit;
cbDCAvailabilityType: TsComboBox;
__cbxRate: TsCheckBox;
__cbxAvailability: TsCheckBox;
pnlHideEdits: TsPanel;
sPanel4: TsPanel;
Image1: TImage;
sPanel5: TsPanel;
pnlRestrictions: TsPanel;
__cbxMinimumStayActive: TsCheckBox;
lblMinStay: TsLabel;
edtMinStay: TsEdit;
edtMaximumStay: TsEdit;
lblMaximumStay: TsLabel;
N2: TMenuItem;
C3: TMenuItem;
imgHelp: TsImage;
edtSingleUsePrice: TsEdit;
__cbxSingleUsePriceActive: TsCheckBox;
lblSingleUsePrice: TsLabel;
ccChannels: TCheckComboBox;
sLabel1: TsLabel;
cbxShowSubrates: TsCheckBox;
btnRecalcDescendantRates: TsButton;
btnClearRoomClasses: TsButton;
btnClearChannelSelection: TsButton;
btnClearChannelSelectionGrid: TsButton;
btnCheckAllChannel: TsButton;
btnCheckAllBulkRoomClasses: TsButton;
btnCheckAllBulkChannel: TsButton;
pnlGridsWithLoadingCaption: TsPanel;
sPanel7: TsPanel;
wwDBDateTimePicker1: TPlannerDatePicker;
btnRefreshOneDay: TcxButton;
btnForward: TcxButton;
btnBack: TcxButton;
dateEdit: TsDateEdit;
lblVisibleDays: TsLabel;
__cbxVisibleDays: TsComboBox;
btnBegin: TcxButton;
btnEnd: TcxButton;
pmnuForce: TPopupMenu;
F1: TMenuItem;
F2: TMenuItem;
btnStopSell_Off: TsButton;
btnStopSell_On: TsButton;
btnStopSell_Clear: TsButton;
cbxStopSell: TsLabel;
btnCloseOnArrival_Off: TsButton;
btnCloseOnArrival_Clear: TsButton;
btnCloseOnArrival_On: TsButton;
cbxClosedOnArrival: TsLabel;
btnCloseOnDeparture_Off: TsButton;
btnCloseOnDeparture_On: TsButton;
btnCloseOnDeparture_Clear: TsButton;
cbxClosedOnDeparture: TsLabel;
cbxStayThrough: TsCheckBox;
cbxBasedOnArrival: TsCheckBox;
lblStayThrough: TsLabel;
lblBasedOnArrival: TsLabel;
btnPrepareExcel: TsButton;
lblReadTime: TsLabel;
lblDrawTime: TsLabel;
timBlink: TTimer;
timBringToFront: TTimer;
procedure FormCreate(Sender: TObject);
procedure timStartTimer(Sender: TObject);
procedure gridDrawCell(Sender: TObject; ACol, ARow: integer; Rect: TRect; State: TGridDrawState);
procedure gridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure dateEditAcceptDate(Sender: TObject; var ADate: TDateTime; var CanAccept: Boolean);
procedure btnSaveClick(Sender: TObject);
procedure gridCanEditCell(Sender: TObject; ARow, ACol: integer; var CanEdit: Boolean);
procedure dtBulkToChange(Sender: TObject);
procedure btnApplyBulkClick(Sender: TObject);
procedure sPanel4Click(Sender: TObject);
procedure sButton2Click(Sender: TObject);
procedure gridGetEditorType(Sender: TObject; ACol, ARow: integer; var AEditor: TEditorType);
procedure gridCellValidate(Sender: TObject; ACol, ARow: integer; var value: string; var Valid: Boolean);
procedure Image1Click(Sender: TObject);
procedure pgcPagesChange(Sender: TObject);
procedure btnPublishClick(Sender: TObject);
procedure rateGridCanEditCell(Sender: TObject; ARow, ACol: integer; var CanEdit: Boolean);
procedure rateGridDrawCell(Sender: TObject; ACol, ARow: integer; Rect: TRect; State: TGridDrawState);
procedure rateGridGetCellBorder(Sender: TObject; ARow, ACol: integer; APen: TPen; var Borders: TCellBorders);
procedure rateGridGetAlignment(Sender: TObject; ARow, ACol: integer; var HAlign: TAlignment; var VAlign: AdvObj.TVAlignment);
procedure rateGridGetCellColor(Sender: TObject; ARow, ACol: integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
procedure cbxChannelManagersChange(Sender: TObject);
procedure rateGridGetEditorType(Sender: TObject; ACol, ARow: integer; var AEditor: TEditorType);
procedure rateGridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure rateGridCellValidate(Sender: TObject; ACol, ARow: integer; var value: string; var Valid: Boolean);
procedure rateGridEditCellDone(Sender: TObject; ACol, ARow: integer);
procedure rateGridKeyPress(Sender: TObject; var Key: Char);
procedure rateGridClipboardAfterPasteCell(Sender: TObject; ACol, ARow: integer; value: string);
procedure rateGridClipboardBeforePasteCell(Sender: TObject; ACol, ARow: integer; var value: string; var Allow: Boolean);
procedure R1Click(Sender: TObject);
procedure C1Click(Sender: TObject);
procedure P1Click(Sender: TObject);
procedure C2Click(Sender: TObject);
procedure sButton1Click(Sender: TObject);
procedure sButton3Click(Sender: TObject);
procedure rateGridGridHint(Sender: TObject; ARow, ACol: integer; var hintstr: string);
procedure gridGridHint(Sender: TObject; ARow, ACol: integer; var hintstr: string);
procedure timRecalcTimer(Sender: TObject);
procedure rateGridCheckBoxChange(Sender: TObject; ACol, ARow: integer; State: Boolean);
procedure cbxStopMinOptionsClick(Sender: TObject);
procedure sButton4Click(Sender: TObject);
procedure sButton5Click(Sender: TObject);
procedure gridEditCellDone(Sender: TObject; ACol, ARow: integer);
procedure gridClipboardAfterPasteCell(Sender: TObject; ACol, ARow: integer; value: string);
procedure cbxShowLinkedCellsClick(Sender: TObject);
procedure cbxAvailTypeChange(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure cbDCAvailabilityTypeChange(Sender: TObject);
procedure __cbxRateClick(Sender: TObject);
procedure __cbxAvailabilityClick(Sender: TObject);
procedure __cbxMinimumStayActiveClick(Sender: TObject);
procedure __cbxSingleUsePriceActiveClick(Sender: TObject);
procedure pnlBulkChangesResize(Sender: TObject);
procedure rateGridCellChanging(Sender: TObject; OldRow, OldCol, NewRow, NewCol: integer; var Allow: Boolean);
procedure C3Click(Sender: TObject);
procedure cbxChannelCloseUp(Sender: TObject);
procedure ccChannelsClickCheck(Sender: TObject);
procedure btnRecalcDescendantRatesClick(Sender: TObject);
procedure cbxChannelClickCheck(Sender: TObject);
procedure btnClearRoomClassesClick(Sender: TObject);
procedure btnClearChannelSelectionClick(Sender: TObject);
procedure btnClearChannelSelectionGridClick(Sender: TObject);
procedure btnCheckAllBulkChannelClick(Sender: TObject);
procedure btnCheckAllBulkRoomClassesClick(Sender: TObject);
procedure btnCheckAllChannelClick(Sender: TObject);
procedure BackgroundAvailabilityFetchHandler(Sender: TObject);
procedure btnForwardClick(Sender: TObject);
procedure btnBackClick(Sender: TObject);
procedure btnBeginClick(Sender: TObject);
procedure btnEndClick(Sender: TObject);
procedure F1Click(Sender: TObject);
procedure F2Click(Sender: TObject);
procedure btnStopSell_OffClick(Sender: TObject);
procedure btnStopSell_OnClick(Sender: TObject);
procedure btnStopSell_ClearClick(Sender: TObject);
procedure btnRefreshOneDayClick(Sender: TObject);
procedure btnPrepareExcelClick(Sender: TObject);
procedure timBlinkTimer(Sender: TObject);
procedure timBringToFrontTimer(Sender: TObject);
procedure __cbxVisibleDaysCloseUp(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ Private declarations }
RoomerDataSet: TRoomerDataSet;
Halting: Boolean;
FCurrentNumDays: integer;
AvailDict: TDictItemObjectDictionary;
CurrentChannelMan: TChannelManagerValue;
ARoomTypeSet: TRoomerDataSet;
NumLinesPerRateEntity: integer;
anyDirectConnection : Boolean;
onlyDirectConnection : Boolean;
startDate : TDateTime;
ThreadedDataGetter : TGetThreadedData;
procedure ShowAvailabilityForSelectedChannelManager;
function GetDateLabel(date: TDateTime): String;
function EditableCell(_grid: TAdvStringGrid; ARow, ACol: integer): Boolean;
function LoadRoomTypeGroups: Boolean;
function DayOfWeekIsIncludes(date: TDateTime): Boolean;
procedure EmptyBulkOperation;
function IsWeekend(ACol: integer): Boolean;
procedure ShowRatesForSelectedChannelManager;
procedure FreeGridObject(aGrid: TadvStringGrid);
function LoadChannelManagers: Boolean;
procedure RemoveData;
procedure EmptyGrid(grid: TAdvStringGrid);
procedure SetAvailabilityValue(iRow: integer; var value: string; _grid: TAdvStringGrid; iCol: integer);
procedure SetRateValue(iCol, iRow: integer; value: string; _grid: TAdvStringGrid; InPlaceEditing: Boolean = false; IsSinglePrice: Boolean = false);
procedure InitializeBulkOperation;
procedure getPriceOfSpecificCell;
procedure DeleteContentOfCurrentCell;
function CurrentActiveGrid: TAdvStringGrid;
function getRateValueForCell(value: String; ACol, ARow: integer; ForSingleUsePrice : Boolean): Double;
function getPriceForOnCell(ACol, ARow: integer): Double;
procedure GetStatusOfRoomClasses;
function locateAvailabilityFromRoomTypeCodeAndDate(const Code: String; date: TDateTime): integer;
function RoundValue(RoundType: integer; value: Double): Double;
function NumDecimals(RoundType: integer): integer;
function LoadPlanCodes: Boolean;
function SeekRecordValue(ASet: TRoomerDataSet; const fieldNameToSeek: String; fieldValue: integer): Boolean;
procedure GridPostPasteAction(_grid: TAdvStringGrid);
function FindRoomClassRow(const Code: String): integer;
function AvailabilityCell(iCol, iRow: integer): TCellData;
procedure PostList(list: TList<String>);
procedure BeginProject(numItems: integer);
procedure EndProject;
procedure ForwardProject;
procedure StallingProject(stalled: Boolean);
procedure RefreshScreen;
procedure CorrectLinks(ACol, ARow: integer);
procedure HideShowLinkedClasses;
procedure HideShowExtraCells;
procedure PrepareAvailDictionary(AvailabilitySet: TRoomerDataSet);
function RealNumberOfRateObjects: integer;
function RealNumberOfAvailabilityObjects: integer;
function isAvailabilityRow(iRow: integer): Boolean;
function isClosedOnDepartureRow(iRow: integer): Boolean;
function isCloseOnArrivalRow(iRow: integer): Boolean;
function isLOSArrivalDateBasedRow(iRow: integer): Boolean;
function isMaxStayRow(iRow: integer): Boolean;
function isMinStayRow(iRow: integer): Boolean;
function isSingleUsePriceRow(iRow: integer): Boolean;
function isStopSellRow(iRow: integer): Boolean;
function isAnySpecRow(iRow: integer): Boolean;
function isAnyCheckBoxRow(iRow: integer): Boolean;
function isAnyEditBoxRow(iRow: integer): Boolean;
function isPriceRow(iRow: integer): Boolean;
function isAnyEditableRow(iRow: integer): Boolean;
function findPriceRowFrom(iRow: integer): integer;
function getPriceDataOfRow(iCol, iRow: integer): TPriceData;
function isCurrentlySelectedValueEdited(iCol, iRow: integer): Boolean;
function buildSetStatement(dirty: Boolean; var oldResultValue: String; const dirtyName, valueName, value: String): String;
function isPriceCell(iCol, iRow: integer): Boolean;
function findRowTypeIndex(startAt, pointerType: integer): integer;
function GetChannelManagerId: integer;
function GetPlanCodeId: integer;
procedure AssignChanges(destChannelId : Integer);
procedure SetRateCellValue(iCol, iRow: integer; PriceData: TPriceData; value: Double);
procedure SetAvailabilityCellValue(iCol, iRow: integer; PriceData: TPriceData; value: integer);
procedure SetCheckBoxCellValue(iCol, iRow: integer; value: Boolean);
procedure SetMinStayCellValue(iCol, iRow: integer; PriceData: TPriceData; value: integer);
procedure SetMaxStayCellValue(iCol, iRow: integer; PriceData: TPriceData; value: integer);
procedure FindFirstAndLastDateInList(var firstDate, lastDate: TDateTime);
procedure SetSingleUsePriceCellValue(iCol, iRow: integer; PriceData: TPriceData; value: Double);
procedure SetCheckBoxStateForCheckBoxCells(iCol, iRow: integer; value: Boolean);
procedure CorrectMasterRateLinkedCells(PriceData : TPriceData; ACol, ARow: integer);
function SameTypeRows(iRow1, iRow2: integer): Boolean;
function findIdInCheckListCombo(cbx : TCheckComboBox; id: Integer): Integer;
function IsIdCheckedInCheckListCombo(cbx: TCheckComboBox; id: Integer): Boolean;
function isHiddenUnusedRow(iRow: integer): Boolean;
function LoadRoomTypeGroupsForBulk: Boolean;
procedure CheckOrUnCheckAllInCheckList(cl: TCheckComboBox; checked : Boolean; skipMinValues : Boolean = False);
function AddCheckEditItem(comp : TCheckComboBox; line : String; obj : TObject) : Integer;
procedure RefreshGridsData;
procedure ForceAvailabilityForCurrentPeriod;
procedure ForceFullAvailability;
procedure ForceRateUpdateForCurrentPeriod;
procedure ForceFullRates;
function ButtonOff(const pre: String): TsButton;
function ButtonOn(const pre: String): TsButton;
function PreOfButton(btn: TsButton): String;
procedure SetButtonOnOff(btn: TSButton; SetOn: Boolean);
procedure PostRatesList(const tableName : String; list: TList<String>);
procedure PublishSheet(OnlyCreateExcel: Boolean; AllowEditAndSendEmail : Boolean);
procedure ShowHideExtraOptions;
procedure BlinkCombo;
function buildSetStatementMinMax(var oldResultValue: String; minDirty, maxDirty: Boolean; minValue, maxValue: Integer): String;
procedure CleanUpRedundantRoomClassesInAvailbilities;
function PerformForcedRatesUpdate: Boolean;
function PerformForcedAvailabilityUpdate: Boolean;
procedure ReloadSelectedPeriod;
function AnyRateOrRestrictionsChanges: Boolean;
protected
procedure CreateParams(var Params: TCreateParams); override;
public
{ Public declarations }
embedded: Boolean;
EmbedWindowCloseEvent: TNotifyEvent;
procedure PrepareUserInterface;
procedure BringWindowToFront;
end;
var
frmChannelAvailabilityManager: TfrmChannelAvailabilityManager;
frmChannelAvailabilityManagerX: TfrmChannelAvailabilityManager;
CHANNELMANAGER_IS_OPEN : Boolean = False;
procedure ShowChannelAvailabilityManager(embedPanel: TsPanel = nil; WindowCloseEvent: TNotifyEvent = nil);
implementation
{$R *.dfm}
uses ioUtils, uMain, uDateUtils, uStringUtils, _glob, uAppGlobal, PrjConst,
uFrmChannelCopyFrom, uRoomerMessageDialog, uDImages, uExcelProcessors, uG, uEmailExcelSheet, hData,
uActivityLogs,
UITypes
, uFloatUtils, uFileSystemUtils;
const
BODY_START = '<body bgcolor="#0000FF"><font bgcolor="#0000FF" color="#FFFFFF">';
BOLD_START = '<b>';
BOLD_END = '</b>';
BODY_END = '</font></body>';
ACTIVE_FLAG_RESTRICTION = '<b>%s</b> active.<br>';
ACTIVE_SETTING_RESTRICTION = '<b>%s</b> = %d.<br>';
MAX_UPDATES_PER_CALL = 600;
NUMBER_OF_DAYS_DISPLAYED : Integer = 14;
procedure ShowChannelAvailabilityManager(embedPanel: TsPanel = nil; WindowCloseEvent: TNotifyEvent = nil);
begin
if CHANNELMANAGER_IS_OPEN then
begin
if frmChannelAvailabilityManager.WindowState = wsMinimized then
frmChannelAvailabilityManager.WindowState := wsNormal;
frmChannelAvailabilityManager.BringToFront;
end else
begin
Application.CreateForm(TfrmChannelAvailabilityManager, frmChannelAvailabilityManager);
frmChannelAvailabilityManager.embedded := (embedPanel <> nil);
frmChannelAvailabilityManager.EmbedWindowCloseEvent := WindowCloseEvent;
if frmChannelAvailabilityManager.embedded then
begin
frmChannelAvailabilityManager.pnlHolder.parent := embedPanel;
embedPanel.Update;
frmChannelAvailabilityManagerX := frmChannelAvailabilityManager;
end
else
begin
frmChannelAvailabilityManager.PrepareUserInterface;
CHANNELMANAGER_IS_OPEN := True;
frmChannelAvailabilityManager.Show;
end;
end;
end;
procedure TfrmChannelAvailabilityManager.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent := Application.Handle;
end;
procedure TfrmChannelAvailabilityManager.btnApplyBulkClick(Sender: TObject);
var
iRowCounter, iColCounter: integer;
value: String;
_grid: TAdvStringGrid;
Msg, MsgType : String;
begin
case pgcPages.ActivePageIndex of
0: begin
_grid := grid;
Msg := GetTranslatedText('shUI_ChannelManager_AvailPublishWarning');
MsgType := 'ChannelMngrAskBeforeAvailPublish';
end;
1: begin
_grid := rateGrid;
Msg := GetTranslatedText('shUI_ChannelManager_RatesPublishWarning');
MsgType := 'ChannelMngrAskBeforeRatesPublish';
end;
else
Exit;
end;
Screen.Cursor := crHourglass;
_grid.Tag := 1;
try
if pgcPages.ActivePageIndex = 0 then // Availability
begin
if cbxAvailType.ItemIndex = 2 then // Auto
value := '-1'
else if cbxAvailType.ItemIndex = 3 then // Set Current
value := '-2'
else if cbxAvailType.ItemIndex = 1 then // Set Max Availability
value := edtAvail.Text
else // Set value normally
value := edtAvail.Text;
end else
begin // Rates
if cbxAvailType.ItemIndex = 1 then // Auto
value := '-1'
else // Set value normally
value := edtAvail.Text;
end;
for iRowCounter := 1 to _grid.RowCount - 1 do
begin
for iColCounter := 1 to _grid.ColCount - 1 do
begin
if (_grid = grid) AND EditableCell(_grid, iRowCounter, iColCounter) then
SetAvailabilityValue(iRowCounter, value, _grid, iColCounter)
else if (_grid = rateGrid) AND isPriceCell(iColCounter, iRowCounter) then
SetRateValue(iColCounter, iRowCounter, value, _grid);
end;
end;
if _grid = rateGrid then
if cbxAvailType.ItemIndex = 2 - pgcPages.ActivePageIndex then
getPriceOfSpecificCell;
sPanel4Click(nil);
_grid.Invalidate;
finally
_grid.Tag := 0;
Screen.Cursor := crDefault;
Application.ProcessMessages;
end;
end;
procedure TfrmChannelAvailabilityManager.btnBackClick(Sender: TObject);
begin
startDate := startDate - NUMBER_OF_DAYS_DISPLAYED;
if TRUNC(startDate) < TRUNC(now) then
startDate := TRUNC(now);
dateEdit.Date := startDate;
RefreshGridsData;
end;
procedure TfrmChannelAvailabilityManager.btnBeginClick(Sender: TObject);
begin
startDate := TRUNC(now);
dateEdit.Date := startDate;
RefreshGridsData;
end;
procedure TfrmChannelAvailabilityManager.btnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmChannelAvailabilityManager.btnEndClick(Sender: TObject);
begin
startDate := TRUNC(now + CurrentChannelMan.FNumDays - NUMBER_OF_DAYS_DISPLAYED);
dateEdit.Date := startDate;
RefreshGridsData;
end;
procedure TfrmChannelAvailabilityManager.btnForwardClick(Sender: TObject);
begin
startDate := startDate + NUMBER_OF_DAYS_DISPLAYED;
if TRUNC(startDate) > TRUNC(now + CurrentChannelMan.FNumDays) then
startDate := TRUNC(now + CurrentChannelMan.FNumDays - NUMBER_OF_DAYS_DISPLAYED);
dateEdit.Date := startDate;
RefreshGridsData;
end;
function TfrmChannelAvailabilityManager.DayOfWeekIsIncludes(date: TDateTime): Boolean;
var
FDayOfWeek: integer;
begin
FDayOfWeek := DayOfWeek(date);
result := ((cbMon.Checked) AND (FDayOfWeek = 2)) OR ((cbTue.Checked) AND (FDayOfWeek = 3)) OR ((cbWen.Checked) AND (FDayOfWeek = 4)) OR
((cbThu.Checked) AND (FDayOfWeek = 5)) OR ((cbFri.Checked) AND (FDayOfWeek = 6)) OR ((cbSat.Checked) AND (FDayOfWeek = 7)) OR
((cbSun.Checked) AND (FDayOfWeek = 1));
end;
procedure TfrmChannelAvailabilityManager.dateEditAcceptDate(Sender: TObject; var ADate: TDateTime; var CanAccept: Boolean);
var
iCol: integer;
begin
//
CanAccept := (trunc(ADate) >= trunc(now)) AND (trunc(ADate) <= trunc(now) + CurrentChannelMan.FNumDays + 1);
if CanAccept then
begin
startDate := ADate;
RefreshGridsData();
iCol := 1;
grid.ScrollInView(1, grid.Row);
rateGrid.ScrollInView(iCol, rateGrid.Row);
try
case pgcPages.ActivePageIndex of
0:
ActiveControl := grid;
1:
ActiveControl := rateGrid;
end;
except
// Invisible controls cause failure
end;
end;
end;
procedure TfrmChannelAvailabilityManager.RemoveData;
begin
FreeGridObject(rateGrid);
FreeGridObject(grid);
end;
function TfrmChannelAvailabilityManager.isHiddenUnusedRow(iRow: integer): Boolean;
begin
result := rateGrid.Objects[0, iRow] = Pointer(11);
end;
function TfrmChannelAvailabilityManager.isAvailabilityRow(iRow: integer): Boolean;
begin
result := rateGrid.Objects[0, iRow] = Pointer(1);
end;
function TfrmChannelAvailabilityManager.isStopSellRow(iRow: integer): Boolean;
begin
result := rateGrid.Objects[0, iRow] = Pointer(2);
end;
function TfrmChannelAvailabilityManager.isMinStayRow(iRow: integer): Boolean;
begin
result := rateGrid.Objects[0, iRow] = Pointer(3);
end;
function TfrmChannelAvailabilityManager.isMaxStayRow(iRow: integer): Boolean;
begin
result := rateGrid.Objects[0, iRow] = Pointer(4);
end;
function TfrmChannelAvailabilityManager.isCloseOnArrivalRow(iRow: integer): Boolean;
begin
result := rateGrid.Objects[0, iRow] = Pointer(5);
end;
function TfrmChannelAvailabilityManager.isClosedOnDepartureRow(iRow: integer): Boolean;
begin
result := rateGrid.Objects[0, iRow] = Pointer(6);
end;
function TfrmChannelAvailabilityManager.isLOSArrivalDateBasedRow(iRow: integer): Boolean;
begin
result := rateGrid.Objects[0, iRow] = Pointer(7);
end;
function TfrmChannelAvailabilityManager.isSingleUsePriceRow(iRow: integer): Boolean;
begin
result := rateGrid.Objects[0, iRow] = Pointer(8);
end;
function TfrmChannelAvailabilityManager.isAnyCheckBoxRow(iRow: integer): Boolean;
begin
result := isStopSellRow(iRow) OR isCloseOnArrivalRow(iRow) OR isClosedOnDepartureRow(iRow) OR isLOSArrivalDateBasedRow(iRow);
end;
function TfrmChannelAvailabilityManager.SameTypeRows(iRow1, iRow2: integer): Boolean;
begin
result :=
(isPriceRow(iRow1) AND isPriceRow(iRow2))
OR
(isAvailabilityRow(iRow1) AND isAvailabilityRow(iRow2))
OR
(isStopSellRow(iRow1) AND isStopSellRow(iRow2))
OR
(isMinStayRow(iRow1) AND isMinStayRow(iRow2))
OR
(isMaxStayRow(iRow1) AND isMaxStayRow(iRow2))
OR
(isCloseOnArrivalRow(iRow1) AND isCloseOnArrivalRow(iRow2))
OR
(isClosedOnDepartureRow(iRow1) AND isClosedOnDepartureRow(iRow2))
OR
(isLOSArrivalDateBasedRow(iRow1) AND isLOSArrivalDateBasedRow(iRow2))
OR
(isSingleUsePriceRow(iRow1) AND isSingleUsePriceRow(iRow2));
end;
function TfrmChannelAvailabilityManager.getPriceDataOfRow(iCol, iRow: integer): TPriceData;
var
iPriceRow: integer;
begin
result := nil;
if (iCol < 1) OR (iRow < 1) then
exit;
iPriceRow := findPriceRowFrom(iRow);
if isPriceRow(iPriceRow) then
result := TPriceData(rateGrid.Objects[iCol, iPriceRow])
end;
function TfrmChannelAvailabilityManager.isCurrentlySelectedValueEdited(iCol, iRow: integer): Boolean;
var
PriceData: TPriceData;
begin
result := false;
if (iCol < 1) OR (iRow < 1) then
exit;
PriceData := getPriceDataOfRow(iCol, iRow);
if Assigned(PriceData) then
begin
if isPriceRow(iRow) then
result := PriceData.FPriceDirty
else if isAvailabilityRow(iRow) then
result := PriceData.FAvailabilityDirty
else if isStopSellRow(iRow) then
result := PriceData.FStopSellDirty
else if isMinStayRow(iRow) then
result := PriceData.FMinStayDirty
else if isMaxStayRow(iRow) then
result := PriceData.FMaxStayDirty
else if isCloseOnArrivalRow(iRow) then
result := PriceData.FCOADirty
else if isClosedOnDepartureRow(iRow) then
result := PriceData.FCODDirty
else if isLOSArrivalDateBasedRow(iRow) then
result := PriceData.FLOSArrivalDateBasedDirty
else if isSingleUsePriceRow(iRow) then
result := PriceData.FSingleUsePriceDirty
else if isStopSellRow(iRow) then
result := PriceData.FSingleUsePriceDirty;
end;
end;
function TfrmChannelAvailabilityManager.isAnySpecRow(iRow: integer): Boolean;
begin
result := isAvailabilityRow(iRow) OR isStopSellRow(iRow) OR isMinStayRow(iRow) OR isMaxStayRow(iRow) OR isCloseOnArrivalRow(iRow) OR
isClosedOnDepartureRow(iRow) OR isLOSArrivalDateBasedRow(iRow) or isSingleUsePriceRow(iRow);
end;
function TfrmChannelAvailabilityManager.isAnyEditBoxRow(iRow: integer): Boolean;
begin
result := isAvailabilityRow(iRow) OR isMinStayRow(iRow) OR isMaxStayRow(iRow) OR isSingleUsePriceRow(iRow) OR
(Assigned(rateGrid.Objects[1, iRow]) AND (rateGrid.Objects[1, iRow] IS TPriceData));
end;
function TfrmChannelAvailabilityManager.isAnyEditableRow(iRow: integer): Boolean;
begin
result := isAnySpecRow(iRow) OR isAnyEditBoxRow(iRow);
end;
function TfrmChannelAvailabilityManager.isPriceRow(iRow: integer): Boolean;
begin
result := (rateGrid.ColCount > 1) AND (iRow > 0) AND (Assigned(rateGrid.Objects[1, iRow]) AND (rateGrid.Objects[1, iRow] IS TPriceData));
end;
function TfrmChannelAvailabilityManager.isPriceCell(iCol, iRow: integer): Boolean;
begin
result := (iCol < rateGrid.ColCount) AND (iRow < rateGrid.RowCount) AND
(Assigned(rateGrid.Objects[iCol, iRow]) AND (rateGrid.Objects[iCol, iRow] IS TPriceData));
end;
function TfrmChannelAvailabilityManager.findPriceRowFrom(iRow: integer): integer;
var
i: integer;
begin
result := 1;
for i := iRow downto 1 do
if isPriceRow(i) then
begin
result := i;
break;
end;
end;
procedure TfrmChannelAvailabilityManager.FreeGridObject(aGrid: TadvStringGrid);
var
iRow, iCol: integer;
obj : TObject;
begin
try
for iRow := 1 to aGrid.RowCount - 1 do
for iCol := 1 to aGrid.ColCount - 1 do
begin
obj := aGrid.Objects[iCol, iRow];
if (obj <> nil) AND (obj IS TObject) then
begin
try
obj.Free;
except
end;
aGrid.Objects[iCol, iRow] := nil;
end
else if aGrid.HasCheckBox(iCol, iRow) then
begin
aGrid.RemoveCheckBox(iCol, iRow);
end;
end;
except
end;
aGrid.ClearAll;
end;
procedure TfrmChannelAvailabilityManager.FormClose(Sender: TObject; var Action: TCloseAction);
begin
pnlHolder.parent := self;
if embedded then
begin
Update;
Action := caFree;
end;
if Assigned(EmbedWindowCloseEvent) then
EmbedWindowCloseEvent(self);
timRecalc.enabled := false;
timStart.enabled := false;
Halting := true;
try
ThreadedDataGetter.Free;
except end;
try
RemoveData;
except end;
try FreeAndNil(rateGrid); except end;
try FreeAndNil(grid); except end;
try FreeAndNil(cbxShowLinkedCells); except end;
try FreeAndNil(cbxStopMinOptions); except end;
try FreeAndNil(pgcPages); except end;
action := caFree;
CHANNELMANAGER_IS_OPEN := False;
end;
procedure TfrmChannelAvailabilityManager.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := True;
if AnyRateOrRestrictionsChanges then
CanClose := MessageDLG(GetTranslatedText('shTx_ChannelAvailabilityManager_ChangesContinue'), mtWarning, [mbYes, mbCancel], 0) = mrYes;
end;
procedure TfrmChannelAvailabilityManager.FormCreate(Sender: TObject);
begin
RoomerDataSet := CreateNewDataSet;
pgcPages.Visible := False;
RoomerLanguage.TranslateThisForm(self);
glb.PerformAuthenticationAssertion(self); PlaceFormOnVisibleMonitor(self);
imgHelp.Hint := format('<body bgcolor="#0000FF">Color definitions in grid:<br><hr><br>' + '<font %s color="#FFFFFF"> </font>' +
'<font bgcolor="#0000FF" color="#FFFFFF"> Rate, availability or restriction has changed.</font><br>', [GetHTMLColor(clRed, true)]) +
format('<font %s color="#FFFFFF"> </font>' + '<font bgcolor="#0000FF" color="#FFFFFF"> Stop sell is active.</font><br>',
[GetHTMLColor(clAqua, true)]) + format('<font %s color="#FFFFFF"> </font>' +
'<font bgcolor="#0000FF" color="#FFFFFF"> Any restrictions active.</font><br>', [GetHTMLColor(clOlive, true)]);
Halting := false;
FCurrentNumDays := 400;