-
Notifications
You must be signed in to change notification settings - Fork 557
/
Copy pathHotelBookingDetail.php
2040 lines (1809 loc) · 102 KB
/
HotelBookingDetail.php
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
<?php
/**
* 2010-2020 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <[email protected]>
* @copyright 2010-2020 Webkul IN
* @license https://store.webkul.com/license.html
*/
class HotelBookingDetail extends ObjectModel
{
private $allReqDates;
private $dltDates;
private $partAvaiDates; // used to remove cart rooms from partial available rooms
public $id;
public $id_product;
public $id_order;
public $id_order_detail;
public $id_cart;
public $id_room;
public $id_hotel;
public $id_customer;
public $booking_type;
public $comment;
public $check_in;
public $check_out;
public $date_from;
public $date_to;
public $total_price_tax_excl; // Total price paid for this date range for this room type
public $total_price_tax_incl; // Total price paid for this date range for this room type
public $total_paid_amount; // Advance payment amount for the room
public $is_back_order;
public $id_status;
public $is_refunded;
// public $available_for_order;
// hotel information/location/contact
public $hotel_name;
public $room_type_name;
public $city;
public $state;
public $country;
public $zipcode;
public $phone;
public $email;
public $check_in_time;
public $check_out_time;
public $room_num;
public $adult;
public $children;
public $date_add;
public $date_upd;
const STATUS_ALLOTED = 1;
const STATUS_CHECKED_IN = 2;
const STATUS_CHECKED_OUT = 3;
// booking allotment types
const ALLOTMENT_AUTO = 1;
const ALLOTMENT_MANUAL = 2;
public static $definition = array(
'table' => 'htl_booking_detail',
'primary' => 'id',
'fields' => array(
'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_order_detail' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_cart' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_room' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_hotel' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'booking_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_status' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'comment' => array('type' => self::TYPE_STRING),
'check_in' => array('type' => self::TYPE_DATE),
'check_out' => array('type' => self::TYPE_DATE),
'date_from' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'required' => true),
'date_to' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'required' => true),
'total_price_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true),
'total_price_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true),
'total_paid_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'default' => 0, 'required' => true),
'is_refunded' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
// 'available_for_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'is_back_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
// hotel information/location/contact
'room_num' => array('type' => self::TYPE_STRING, 'required' => true),
'room_type_name' => array('type' => self::TYPE_STRING, 'required' => true),
'hotel_name' => array('type' => self::TYPE_STRING, 'required' => true),
'city' => array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'size' => 64, 'required' => true),
'state' => array('type' => self::TYPE_STRING),
'country' => array('type' => self::TYPE_STRING, 'required' => true),
'zipcode' => array('type' => self::TYPE_STRING),
'phone' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32, 'required' => true),
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 255, 'required' => true),
'check_in_time' => array('type' => self::TYPE_STRING, 'required' => true),
'check_out_time' => array('type' => self::TYPE_STRING, 'required' => true),
'adult' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'children' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
),
);
protected $webserviceParameters = array(
'objectsNodeName' => 'bookings',
'objectNodeName' => 'booking',
'fields' => array(
'id_product' => array(
'xlink_resource' => array(
'resourceName' => 'products',
)
),
'id_hotel' => array(
'xlink_resource' => array(
'resourceName' => 'hotels',
)
),
'id_order' => array(
'xlink_resource' => array(
'resourceName' => 'orders',
)
),
),
'associations' => array(
'booking_extra_demands' => array(
'setter' => false,
'resource' => 'extra_demand',
'fields' => array('id' => array())
),
),
);
public function __construct($id = null, $id_lang = null, $id_shop = null)
{
$this->moduleInstance = Module::getInstanceByName('hotelreservationsystem');
parent::__construct($id);
}
public function getBookingDataParams($params)
{
if (!isset($params['room_type'])) {
$params['room_type'] = 0;
}
if (!isset($params['adult'])) {
$params['adult'] = 0;
}
if (!isset($params['children'])) {
$params['children'] = 0;
}
if (!isset($params['num_rooms'])) {
$params['num_rooms'] = 1;
}
if (!isset($params['for_calendar'])) {
$params['for_calendar'] = 0;
}
if (!isset($params['search_available'])) {
$params['search_available'] = 1;
}
if (!isset($params['search_partial'])) {
$params['search_partial'] = 1;
}
if (!isset($params['search_booked'])) {
$params['search_booked'] = 1;
}
if (!isset($params['search_unavai'])) {
$params['search_unavai'] = 1;
}
if (!isset($params['id_cart'])) {
$params['id_cart'] = 0;
}
if (!isset($params['id_guest'])) {
$params['id_guest'] = 0;
}
if (!isset($params['search_cart_rms'])) {
$params['search_cart_rms'] = 0;
}
if (!isset($params['only_active_roomtype'])) {
$params['only_active_roomtype'] = 1;
}
if (!isset($params['only_active_hotel'])) {
$params['only_active_hotel'] = 1;
}
return $params;
}
/**
* [getBookingData :: To get Array of rooms data].
*
* @param [type] $date_from [Start date of booking]
* @param [type] $date_to [End date of booking]
* @param [type] $hotel_id [Id of the hotel to which the room belongs]
* @param [type] $room_type [Id of the product to which the room belongs]
* @param int $adult []
* @param int $children []
* @param int $num_rooms [Number of rooms booked for the period $date_from to $date_to]
* @param int $for_calendar [Used for calender and also for getting stats of rooms]
* @param int $search_available [If you want only data information for available rooms]
* @param int $search_partial [If you want only data information for partial rooms]
* @param int $search_booked [If you want only data information for booked rooms]
* @param int $search_unavai [If you want only data information for unavailable rooms]
* @param int $id_cart [Id of the cart to which the room belongs at the time of booking]
* @param int $id_guest [Id guest of the customer Who booked the rooms]
* @param int $search_cart_rms [If you want data of the current cart in the admin office]
*
* @return [array] [Returns Array of rooms data ]
*
* Note: Adult and children both are used for front category page only in available rooms
* Note :: $for_calendar is used both for calender and also for getting stats of rooms
*/
public function getBookingData($params)
{
$this->context = Context::getContext();
// extract all keys and values of the array [$params] into variables and values
extract($this->getBookingDataParams($params));
if ($date_from && $date_to && $hotel_id) {
$date_from = date('Y-m-d H:i:s', strtotime($date_from));
$date_to = date('Y-m-d H:i:s', strtotime($date_to));
$obj_room_info = new HotelRoomInformation();
$obj_rm_type = new HotelRoomType();
if ($room_types = $obj_rm_type->getIdProductByHotelId(
$hotel_id,
$room_type,
$only_active_roomtype,
$only_active_hotel
)) {
$total_rooms = 0;
$num_booked = 0;
$num_unavail = 0;
$num_avail = 0;
$num_part_avai = 0;
$num_cart = 0;
$new_part_arr = array();
$booking_data = array();
$applyLosRestriction = true;
if ($search_partial) {
$this->partAvaiDates = array();
$this->allReqDates = $this->createDateRangeArray($date_from, $date_to, 1);
}
if (isset(Context::getContext()->employee->id)) {
if (!Configuration::get('PS_LOS_RESTRICTION_BO')) {
$applyLosRestriction = false;
}
}
foreach ($room_types as $key => $room_type) {
if ($search_partial) {
$this->dltDates = array();
}
$total_rooms += $obj_room_info->getHotelRoomInfo($room_type['id_product'], $hotel_id, 1);
// Get min & max LOS
$objRoomTypeRestriction = new HotelRoomTypeRestrictionDateRange();
$losRestriction = $objRoomTypeRestriction->getRoomTypeLengthOfStay($room_type['id_product'], $date_from);
$obj_product = new Product((int) $room_type['id_product']);
$product_name = $obj_product->name[Configuration::get('PS_LANG_DEFAULT')];
if ($search_cart_rms) {
if ($id_cart && $id_guest) {
$sql = 'SELECT cbd.`id_product`, cbd.`id_room`, cbd.`id_hotel`, cbd.`booking_type`, cbd.`comment`, rf.`room_num`, cbd.`date_from`, cbd.`date_to`
FROM `'._DB_PREFIX_.'htl_cart_booking_data` AS cbd
INNER JOIN `'._DB_PREFIX_.'htl_room_information` AS rf ON (rf.`id` = cbd.`id_room`)
WHERE cbd.`id_hotel`='.(int)$hotel_id.' AND cbd.`id_product` ='.(int)$room_type['id_product'].' AND cbd.`id_cart` = '.(int)$id_cart.' AND cbd.`id_guest` ='.(int)$id_guest.' AND cbd.`is_refunded` = 0 AND cbd.`is_back_order` = 0';
$cart_rooms = Db::getInstance()->executeS($sql);
} else {
$cart_rooms = array();
}
$num_cart += count($cart_rooms);
}
if ($search_booked) {
$sql = 'SELECT bd.`id_product`, bd.`id_room`, bd.`id_hotel`, bd.`id_customer`, bd.`booking_type`, bd.`id_status` AS booking_status, bd.`comment`, rf.`room_num`, bd.`date_from`, bd.`date_to`
FROM `'._DB_PREFIX_.'htl_booking_detail` AS bd
INNER JOIN `'._DB_PREFIX_.'htl_room_information` AS rf ON (rf.`id` = bd.`id_room`)
WHERE bd.`id_hotel`='.(int)$hotel_id.' AND bd.`id_product` ='.(int)$room_type['id_product'].' AND bd.`is_refunded` = 0 AND bd.`is_back_order` = 0 AND IF(bd.`id_status` = '. self::STATUS_CHECKED_OUT .', bd.`date_from` <= \''.pSQL($date_from).'\' AND bd.`check_out` >= \''.pSQL($date_to).'\', bd.`date_from` <= \''.pSQL($date_from).'\' AND bd.date_to >= \''.pSQL($date_to).'\')';
$booked_rooms = Db::getInstance()->executeS($sql);
foreach ($booked_rooms as $booked_k => $booked_v) {
$booked_rooms[$booked_k]['detail'][] = array(
'date_from' => $booked_v['date_from'],
'date_to' => $booked_v['date_to'],
'id_customer' => $booked_v['id_customer'],
'booking_type' => $booked_v['booking_type'],
'booking_status' => $booked_v['booking_status'],
'comment' => $booked_v['comment'],
);
unset($booked_rooms[$booked_k]['date_from']);
unset($booked_rooms[$booked_k]['date_to']);
unset($booked_rooms[$booked_k]['id_customer']);
unset($booked_rooms[$booked_k]['booking_type']);
unset($booked_rooms[$booked_k]['booking_status']);
unset($booked_rooms[$booked_k]['comment']);
}
$num_booked += count($booked_rooms);
}
if ($search_unavai) {
$sql1 = 'SELECT `id_product`, `id_hotel`, `room_num`, `comment` AS `room_comment`
FROM `'._DB_PREFIX_.'htl_room_information`
WHERE `id_hotel`='.(int)$hotel_id.' AND `id_product` ='.(int)$room_type['id_product'].' AND (`id_status` = '. HotelRoomInformation::STATUS_INACTIVE;
if ($applyLosRestriction) {
$sql1 .= ' OR ( DATEDIFF(\''.$date_to.'\', \''.$date_from.'\') < '.(int)$losRestriction['min_los'];
if ((int)$losRestriction['max_los']) {
$sql1 .= ' OR DATEDIFF(\''.$date_to.'\', \''.$date_from.'\') > '.(int)$losRestriction['max_los'];
}
$sql1 .= ')';
}
$sql1 .= ')';
$sql2 = 'SELECT hri.`id_product`, hri.`id_hotel`, hri.`room_num`, hri.`comment` AS `room_comment`
FROM `'._DB_PREFIX_.'htl_room_information` AS hri
INNER JOIN `'._DB_PREFIX_.'htl_room_disable_dates` AS hrdd ON (hrdd.`id_room_type` = hri.`id_product` AND hrdd. id_room = hri.`id`)
WHERE hri.`id_hotel`='.$hotel_id.' AND hri.`id_product` ='.$room_type['id_product'].' AND hri.`id_status` = '. HotelRoomInformation::STATUS_TEMPORARY_INACTIVE .' AND hrdd.`date_from` <= \''.pSql($date_from).'\' AND hrdd.`date_to` >= \''.pSql($date_to).'\'';
$sql = $sql1.' UNION '.$sql2;
$unavail_rooms = Db::getInstance()->executeS($sql);
$num_unavail += count($unavail_rooms);
}
if ($search_available) {
$exclude_ids = 'SELECT `id_room`
FROM `'._DB_PREFIX_.'htl_booking_detail`
WHERE `is_back_order` = 0 AND `is_refunded` = 0 AND IF(`id_status` = '. self::STATUS_CHECKED_OUT.', (
(DATE_FORMAT(`check_out`, "%Y-%m-%d") > \''.pSQL($date_from).'\' AND DATE_FORMAT(`check_out`, "%Y-%m-%d") <= \''.PSQL($date_to).'\') AND (
(`date_from` <= \''.pSQL($date_from).'\' AND `check_out` > \''.pSQL($date_from).'\' AND `check_out` <= \''.PSQL($date_to).'\') OR
(`date_from` >= \''.pSQL($date_from).'\' AND `check_out` > \''.pSQL($date_from).'\' AND `check_out` <= \''.pSQL($date_to).'\') OR
(`date_from` >= \''.pSQL($date_from).'\' AND `date_from` < \''.pSQL($date_to).'\' AND `check_out` >= \''.pSQL($date_to).'\') OR
(`date_from` <= \''.pSQL($date_from).'\' AND `check_out` >= \''.pSQL($date_to).'\')
)
), (
(`date_from` <= \''.pSQL($date_from).'\' AND `date_to` > \''.pSQL($date_from).'\' AND `date_to` <= \''.PSQL($date_to).'\') OR
(`date_from` >= \''.pSQL($date_from).'\' AND `date_to` <= \''.pSQL($date_to).'\') OR
(`date_from` >= \''.pSQL($date_from).'\' AND `date_from` < \''.pSQL($date_to).'\' AND `date_to` >= \''.pSQL($date_to).'\') OR
(`date_from` <= \''.pSQL($date_from).'\' AND `date_to` >= \''.pSQL($date_to).'\')
))';
if (!empty($id_cart) && !empty($id_guest)) {
$exclude_ids .= ' UNION
SELECT `id_room`
FROM `'._DB_PREFIX_.'htl_cart_booking_data`
WHERE id_cart='.(int)$id_cart.' AND id_guest='.(int)$id_guest.' AND is_refunded = 0 AND is_back_order = 0 AND ((date_from <= \''.pSQL($date_from).'\' AND date_to > \''.pSQL($date_from).'\' AND date_to <= \''.pSQL($date_to).'\') OR (date_from > \''.pSQL($date_from).'\' AND date_to < \''.pSQL($date_to).'\') OR (date_from >= \''.pSQL($date_from).'\' AND date_from < \''.pSQL($date_to).'\' AND date_to >= \''.pSQL($date_to).'\') OR (date_from < \''.pSQL($date_from).'\' AND date_to > \''.pSQL($date_to).'\'))';
}
// For excludes temporary disable rooms
$exclude_ids .= ' UNION
SELECT hri.`id` AS id_room
FROM `'._DB_PREFIX_.'htl_room_information` AS hri
INNER JOIN `'._DB_PREFIX_.'htl_room_disable_dates` AS hrdd ON (hrdd.`id_room_type` = hri.`id_product` AND hrdd.`id_room` = hri.`id`)
WHERE hri.`id_hotel`='.(int)$hotel_id.' AND hri.`id_product` ='.(int)$room_type['id_product'].' AND hri.`id_status` = '. HotelRoomInformation::STATUS_TEMPORARY_INACTIVE .' AND (hrdd.`date_from` <= \''.pSql($date_to).'\' AND hrdd.`date_to` >= \''.pSql($date_from).'\')';
$selectAvailRoomSearch = 'SELECT ri.`id` AS `id_room`, ri.`id_product`, ri.`id_hotel`, ri.`room_num`, ri.`comment` AS `room_comment`';
$joinAvailRoomSearch = '';
$whereAvailRoomSearch = 'WHERE ri.`id_hotel`='.(int)$hotel_id.' AND ri.`id_product`='.(int)$room_type['id_product'].' AND ri.`id_status` != '. HotelRoomInformation::STATUS_INACTIVE;
// Check min & max LOS restrictions
if ($applyLosRestriction) {
$whereAvailRoomSearch .= ' AND DATEDIFF(\''.$date_to.'\', \''.$date_from.'\') >= '.(int)$losRestriction['min_los'];
// check max LOS restriction is greater than zero
if ((int)$losRestriction['max_los']) {
$whereAvailRoomSearch .= ' AND DATEDIFF(\''.$date_to.'\', \''.$date_from.'\') <= '.(int)$losRestriction['max_los'];
}
}
$whereAvailRoomSearch .= ' AND ri.`id` NOT IN ('.$exclude_ids.')';
$groupByAvailRoomSearch = '';
$orderByAvailRoomSearch = '';
$orderWayAvailRoomSearch = '';
Hook::exec('actionAvailRoomSearchSqlModifier',
array(
'select' => &$selectAvailRoomSearch,
'join' => &$joinAvailRoomSearch,
'where' => &$whereAvailRoomSearch,
'group_by' => &$groupByAvailRoomSearch,
'order_by' => &$orderByAvailRoomSearch,
'order_way' => &$orderWayAvailRoomSearch,
'params' => array(
'id_hotel' => $hotel_id,
'id_product' => $room_type['id_product'],
'date_from' => $date_from,
'date_to' => $date_to
)
)
);
$sql = $selectAvailRoomSearch;
$sql .= ' FROM `'._DB_PREFIX_.'htl_room_information` AS ri';
$sql .= ' '.$joinAvailRoomSearch;
$sql .= ' '.$whereAvailRoomSearch;
$sql .= ' '.$groupByAvailRoomSearch;
$sql .= ' '.$orderByAvailRoomSearch;
$sql .= ' '.$orderWayAvailRoomSearch;
$avai_rooms = Db::getInstance()->executeS($sql);
$num_avail += count($avai_rooms);
}
if ($search_partial) {
$sql1 = 'SELECT bd.`id_product`, bd.`id_room`, bd.`id_hotel`, bd.`id_customer`, bd.`booking_type`, bd.`id_status` AS booking_status, bd.`comment` AS `room_comment`, rf.`room_num`, bd.`date_from`, IF(bd.`id_status` = '. self::STATUS_CHECKED_OUT .', bd.`check_out`, bd.`date_to`) AS `date_to`
FROM `'._DB_PREFIX_.'htl_booking_detail` AS bd
INNER JOIN `'._DB_PREFIX_.'htl_room_information` AS rf ON (rf.`id` = bd.`id_room`)
WHERE bd.`id_hotel`='.(int)$hotel_id.' AND bd.`id_product`='.(int)$room_type['id_product'].' AND rf.`id_status` != '. HotelRoomInformation::STATUS_INACTIVE .' AND bd.`is_back_order` = 0 AND bd.`is_refunded` = 0 AND IF(bd.`id_status` = '. self::STATUS_CHECKED_OUT .', (
(DATE_FORMAT(`check_out`, "%Y-%m-%d") > \''.pSQL($date_from).'\' AND DATE_FORMAT(`check_out`, "%Y-%m-%d") < \''.PSQL($date_to).'\') AND (
(bd.`date_from` <= \''.pSQL($date_from).'\' AND bd.`check_out` > \''.pSQL($date_from).'\' AND bd.`check_out` < \''.pSQL($date_to).'\') OR
(bd.`date_from` > \''.pSQL($date_from).'\' AND bd.`date_from` < \''.pSQL($date_to).'\' AND bd.`check_out` >= \''.pSQL($date_to).'\') OR
(bd.`date_from` > \''.pSQL($date_from).'\' AND bd.`date_from` < \''.pSQL($date_to).'\' AND bd.`check_out` > \''.pSQL($date_from).'\' AND bd.`check_out` < \''.pSQL($date_to).'\')
)
), (
(bd.`date_from` <= \''.pSQL($date_from).'\' AND bd.`date_to` > \''.pSQL($date_from).'\' AND bd.`date_to` < \''.pSQL($date_to).'\') OR
(bd.`date_from` > \''.pSQL($date_from).'\' AND bd.`date_from` < \''.pSQL($date_to).'\' AND bd.`date_to` >= \''.pSQL($date_to).'\') OR
(bd.`date_from` > \''.pSQL($date_from).'\' AND bd.`date_from` < \''.pSQL($date_to).'\' AND bd.`date_to` < \''.pSQL($date_to).'\')
))';
$sql2 = 'SELECT hri.`id_product`, hrdd.`id_room`, hri.`id_hotel`, 0 AS `id_customer`, 0 AS `booking_type`, 0 AS `booking_status`, 0 AS `room_comment`, hri.`room_num`, hrdd.`date_from`, hrdd.`date_to`
FROM `'._DB_PREFIX_.'htl_room_information` AS hri
INNER JOIN `'._DB_PREFIX_.'htl_room_disable_dates` AS hrdd ON (hrdd.`id_room_type` = hri.`id_product` AND hrdd.`id_room` = hri.`id`)
WHERE hri.`id_hotel`='.(int)$hotel_id.' AND hri.`id_product`='.(int)$room_type['id_product'].' AND
hri.`id_status` = '. HotelRoomInformation::STATUS_TEMPORARY_INACTIVE .' AND (
(hrdd.`date_from` <= \''.pSQL($date_from).'\' AND hrdd.`date_to` > \''.pSQL($date_from).'\' AND hrdd.`date_to` < \''.pSQL($date_to).'\') OR
(hrdd.`date_from` > \''.pSQL($date_from).'\' AND hrdd.`date_from` < \''.pSQL($date_to).'\' AND hrdd.`date_to` >= \''.pSQL($date_to).'\') OR
(hrdd.`date_from` > \''.pSQL($date_from).'\' AND hrdd.`date_from` < \''.pSQL($date_to).'\' AND hrdd.`date_to` < \''.pSQL($date_to).'\')
)';
// $part_arr2 = Db::getInstance()->executeS($sql2);
// $part_arr = array_merge($part_arr1 ? $part_arr1 : array(), $part_arr2 ? $part_arr2 : array());
$sql = $sql1.' UNION '.$sql2;
// NOTE:: Before code if written to use "ORDER BY" with union
$sql = 'SELECT s.*
FROM ('.$sql.') AS s
ORDER BY s.`id_room`';
$part_arr = Db::getInstance()->executeS($sql);
$partial_avai_rooms = array();
foreach ($part_arr as $pr_val) {
$partial_avai_rooms[$pr_val['id_room']]['id_product'] = $pr_val['id_product'];
$partial_avai_rooms[$pr_val['id_room']]['id_room'] = $pr_val['id_room'];
$partial_avai_rooms[$pr_val['id_room']]['id_hotel'] = $pr_val['id_hotel'];
$partial_avai_rooms[$pr_val['id_room']]['room_num'] = $pr_val['room_num'];
if ($pr_val['id_customer']) {
$partial_avai_rooms[$pr_val['id_room']]['booked_dates'][] = array(
'date_from' => $pr_val['date_from'],
'date_to' => $pr_val['date_to'],
'id_customer' => $pr_val['id_customer'],
'booking_type' => $pr_val['booking_type'],
'booking_status' => $pr_val['booking_status'],
'comment' => $pr_val['room_comment']
);
}
if (!isset($partial_avai_rooms[$pr_val['id_room']]['avai_dates'])) {
if (($pr_val['date_from'] <= $date_from) && ($pr_val['date_to'] > $date_from) && ($pr_val['date_to'] < $date_to)) {
// from lower to middle range
$forRange = $this->createDateRangeArray($pr_val['date_to'], $date_to, 0, $pr_val['id_room']);
$available_dates = $this->getPartialRange($forRange, $pr_val['id_room'], $key);
} elseif (($pr_val['date_from'] > $date_from) && ($pr_val['date_from'] < $date_to) && ($pr_val['date_to'] >= $date_to)) {
// from middle to higher range
$forRange = $this->createDateRangeArray($date_from, $pr_val['date_from'], 0, $pr_val['id_room']);
$available_dates = $this->getPartialRange($forRange, $pr_val['id_room'], $key);
} elseif (($pr_val['date_from'] > $date_from) && ($pr_val['date_from'] < $date_to) && ($pr_val['date_to'] > $date_from) && ($pr_val['date_to'] < $date_to)) {
// between range
$forRange1 = $this->createDateRangeArray($date_from, $pr_val['date_from'], 0, $pr_val['id_room']);
$init_range = $this->getPartialRange($forRange1, $pr_val['id_room'], $key);
$forRange2 = $this->createDateRangeArray($pr_val['date_to'], $date_to, 0, $pr_val['id_room']);
$last_range = $this->getPartialRange($forRange2, $pr_val['id_room'], $key);
$available_dates = $init_range + $last_range;
}
$partial_avai_rooms[$pr_val['id_room']]['avai_dates'] = $available_dates;
} else {
/*
* Note :: createDateRangeArray function check and unset dates from allReqDates(array) but below it will only return array of date because dates already been removed from "if" condition
*/
$bk_dates = $this->createDateRangeArray($pr_val['date_from'], $pr_val['date_to'], 0, 0, 0);
if (count($bk_dates) >= 2) {
for ($i = 0; $i < count($bk_dates) - 1; ++$i) {
$dateJoin = strtotime($bk_dates[$i]);
if (isset($partial_avai_rooms[$pr_val['id_room']]['avai_dates'][$dateJoin])) {
if (isset($this->dltDates[$pr_val['id_room']]) && $this->dltDates[$pr_val['id_room']]) {
$this->allReqDates[] = $bk_dates[$i];
}
unset($partial_avai_rooms[$pr_val['id_room']]['avai_dates'][$dateJoin]);
unset($this->partAvaiDates[$pr_val['id_room'].$dateJoin]);
}
}
}
}
}
$rm_part_avai = count($partial_avai_rooms);
$num_part_avai += $rm_part_avai;
}
// if (!$for_calendar)
// {
$booking_data['rm_data'][$key]['name'] = $product_name;
$booking_data['rm_data'][$key]['id_product'] = (int) $room_type['id_product'];
if ($search_available) {
$booking_data['rm_data'][$key]['data']['available'] = $avai_rooms;
}
if ($search_unavai) {
$booking_data['rm_data'][$key]['data']['unavailable'] = $unavail_rooms;
}
if ($search_booked) {
$booking_data['rm_data'][$key]['data']['booked'] = $booked_rooms;
}
if ($search_partial) {
$booking_data['rm_data'][$key]['data']['partially_available'] = $partial_avai_rooms;
}
if ($search_cart_rms) {
$booking_data['rm_data'][$key]['data']['cart_rooms'] = $cart_rooms;
}
// }
}
if ($search_partial) {
foreach ($booking_data['rm_data'] as $bk_data_key => $bk_data_val) {
foreach ($bk_data_val['data']['partially_available'] as $part_rm_key => $part_rm_val) {
if (empty($part_rm_val['avai_dates'])) {
unset($booking_data['rm_data'][$bk_data_key]['data']['partially_available'][$part_rm_key]['avai_dates']);
$booking_data['rm_data'][$bk_data_key]['data']['partially_available'][$part_rm_key]['detail'] = $booking_data['rm_data'][$bk_data_key]['data']['partially_available'][$part_rm_key]['booked_dates'];
unset($booking_data['rm_data'][$bk_data_key]['data']['partially_available'][$part_rm_key]['booked_dates']);
if ($search_booked) {
$booking_data['rm_data'][$bk_data_key]['data']['booked'] = array_merge($booking_data['rm_data'][$bk_data_key]['data']['booked'], array($booking_data['rm_data'][$bk_data_key]['data']['partially_available'][$part_rm_key]));
$num_booked += 1;
unset($booking_data['rm_data'][$bk_data_key]['data']['partially_available'][$part_rm_key]);
}
$num_part_avai -= 1;
} elseif (!empty($this->allReqDates)) {
unset($booking_data['rm_data'][$bk_data_key]['data']['partially_available'][$part_rm_key]['avai_dates']);
unset($booking_data['rm_data'][$bk_data_key]['data']['partially_available'][$part_rm_key]['booked_dates']);
if ($search_unavai) {
$booking_data['rm_data'][$bk_data_key]['data']['partially_available'][$part_rm_key]['room_comment'] = '';
$booking_data['rm_data'][$bk_data_key]['data']['unavailable'] = array_merge($booking_data['rm_data'][$bk_data_key]['data']['unavailable'], array($booking_data['rm_data'][$bk_data_key]['data']['partially_available'][$part_rm_key]));
$num_unavail += 1;
unset($booking_data['rm_data'][$bk_data_key]['data']['partially_available'][$part_rm_key]);
}
$num_part_avai -= 1;
}
}
// Remove Cart Rooms from Partial available rooms
if ($search_cart_rms) {
foreach ($bk_data_val['data']['cart_rooms'] as $cart_key => $cart_val) {
if (isset($this->partAvaiDates[$cart_val['id_room'].strtotime($cart_val['date_from'])])) {
$rm_data_key = $this->partAvaiDates[$cart_val['id_room'].strtotime($cart_val['date_from'])]['rm_data_key'];
unset($booking_data['rm_data'][$rm_data_key]['data']['partially_available'][$cart_val['id_room']]['avai_dates'][strtotime($cart_val['date_from'])]);
if (empty($booking_data['rm_data'][$rm_data_key]['data']['partially_available'][$cart_val['id_room']]['avai_dates'])) {
unset($booking_data['rm_data'][$rm_data_key]['data']['partially_available'][$cart_val['id_room']]);
$num_part_avai -= 1;
}
}
}
unset($this->partAvaiDates);
}
}
}
if ($for_calendar) {
unset($booking_data['rm_data']);
}
$booking_data['stats']['total_rooms'] = $total_rooms;
if ($search_booked) {
$booking_data['stats']['num_booked'] = $num_booked;
}
if ($search_unavai) {
$booking_data['stats']['num_unavail'] = $num_unavail;
}
if ($search_available) {
$booking_data['stats']['num_avail'] = $num_avail;
}
if ($search_partial) {
$booking_data['stats']['num_part_avai'] = $num_part_avai;
}
if ($search_partial) {
$booking_data['stats']['num_cart'] = $num_cart;
}
return $booking_data;
}
}
}
// This function algo is same as available rooms algo and it not similar to booked rooms algo.
public function chechRoomBooked($id_room, $date_from, $date_to)
{
$sql = 'SELECT `id_product`, `id_order`, `id_cart`, `id_room`, `id_hotel`, `id_customer`
FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `id_room` = '.(int)$id_room.
' AND `is_back_order` = 0 AND `is_refunded` = 0 AND ((date_from <= \''.pSQL($date_from).'\' AND date_to > \''.
pSQL($date_from).'\' AND date_to <= \''.pSQL($date_to).'\') OR (date_from > \''.pSQL($date_from).
'\' AND date_to < \''.pSQL($date_to).'\') OR (date_from >= \''.pSQL($date_from).'\' AND date_from < \''.
pSQL($date_to).'\' AND date_to >= \''.pSQL($date_to).'\') OR (date_from < \''.pSQL($date_from).
'\' AND date_to > \''.pSQL($date_to).'\'))';
return Db::getInstance()->getRow($sql);
}
/**
* [createDateRangeArray :: This function will return array of dates from date_form to date_to (Not including date_to)
* if ($for_check == 0)
* {
* Then this function will remove these dates from $allReqDates this array
* }].
*
* @param [date] $strDateFrom [Start date of the date range]
* @param [date] $strDateTo [End date of the date range]
* @param int $for_check [
* if ($for_check == 0)
* {
* Then this function will remove these dates from $allReqDates this array
* }
* if ($for_check == 0)
* {
* This function will return array of dates from date_form to date_to (Not including date_to)
* }
* ]
*
* @return [array] [Returns array of the dates]
*/
public function createDateRangeArray($strDateFrom, $strDateTo, $for_check = 0, $id_room = 0, $dlt_date = 1)
{
$aryRange = array();
$iDateFrom = mktime(1, 0, 0, substr($strDateFrom, 5, 2), substr($strDateFrom, 8, 2), substr($strDateFrom, 0, 4));
$iDateTo = mktime(1, 0, 0, substr($strDateTo, 5, 2), substr($strDateTo, 8, 2), substr($strDateTo, 0, 4));
if ($iDateTo >= $iDateFrom) {
$entryDate = date('Y-M-d', $iDateFrom);
array_push($aryRange, $entryDate); // first entry
if ($dlt_date) {
$this->checkAllDatesCover($entryDate, $id_room);
}
while ($iDateFrom < $iDateTo) {
$iDateFrom += 86400; // add 24 hours
if ($iDateFrom != $iDateTo || !$for_check) {
// to stop last entry in check partial case
$entryDate = date('Y-M-d', $iDateFrom);
array_push($aryRange, $entryDate);
if ($iDateFrom != $iDateTo && $dlt_date) {
$this->checkAllDatesCover($entryDate, $id_room);
}
}
}
}
return $aryRange;
}
/**
* [checkAllDatesCover description :: Check the passed date is available in the array $allReqDates if available then removes date from array $all_date_arr].
*
* @param [date] $dateCheck [Date to checked in the array $allReqDates]
*
* @return [boolean] [Returns true]
*/
public function checkAllDatesCover($dateCheck, $id_room)
{
if (isset($this->allReqDates) && !empty($this->allReqDates)) {
if (($key = array_search($dateCheck, $this->allReqDates)) !== false) {
if ($id_room) {
$this->dltDates[$id_room] = $dateCheck;
}
unset($this->allReqDates[$key]);
}
}
return true;
}
/**
* [getPartialRange :: To get array containing ].
* @param [array] $dateArr [Array containing dates]
* @return [array] [IF passed array of dates contains more than one date then returns ]
*/
public function getPartialRange($dateArr, $id_room = 0, $rm_data_key = false)
{
$dateRange = array();
if (count($dateArr) >= 2) {
for ($i = 0; $i < count($dateArr) - 1; ++$i) {
$dateRange[strtotime($dateArr[$i])] = array('date_from' => $dateArr[$i], 'date_to' => $dateArr[$i + 1]);
if ($id_room && ($rm_data_key !== false)) {
$this->partAvaiDates[$id_room.strtotime($dateArr[$i])] = array('rm_data_key' => $rm_data_key);
}
}
} else {
$dateRange = $dateArr;
}
return $dateRange;
}
/**
* [getNumberOfDays ::To get number of datys between two dates].
*
* @param [date] $dateFrom [Start date of the booking]
* @param [date] $dateTo [End date of the booking]
*
* @return [int] [Returns number of days between two dates]
*/
public function getNumberOfDays($dateFrom, $dateTo)
{
$startDate = new DateTime($dateFrom);
$endDate = new DateTime($dateTo);
$daysDifference = $startDate->diff($endDate)->days;
return $daysDifference;
}
/**
* [getBookingDataByOrderId :: To get booking information by id order].
*
* @param [int] $order_id [Id of the order]
*
* @return [array|false] [If data found Returns the array containing the information of the booking of an order else returns false]
*/
public function getBookingDataByOrderId($order_id)
{
return Db::getInstance()->executeS(
'SELECT * FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `id_order`='.(int)$order_id
);
}
/**
* [updateBookingOrderStatusBYOrderId :: To update the order status of a room in the booking].
* @param [int] $order_id [Id of the order]
* @param [int] $new_status [Id of the new status of the order to be updated]
* @param [int] $id_room [Id of the room which order status is to be ypdated]
* @return [Boolean] [Returns true if successfully updated else returns false]
*/
public function updateBookingOrderStatusByOrderId(
$idOrder,
$newStatus,
$idRoom,
$dateFrom,
$dateTo,
$statusDate = ''
) {
$roomBookingData = $this->getRoomBookingData($idRoom, $idOrder, $dateFrom, $dateTo);
$objHotelBookingDetail = new self($roomBookingData['id']);
if (Validate::isLoadedObject($objHotelBookingDetail)) {
if ($statusDate) {
$statusDate = date('Y-m-d H:i:s', strtotime($statusDate));
} else {
$statusDate = date('Y-m-d H:i:s');
}
if ($newStatus == self::STATUS_CHECKED_IN) {
$objHotelBookingDetail->id_status = $newStatus;
$objHotelBookingDetail->check_in = ($statusDate > $dateTo ? $dateTo : $statusDate);
} elseif ($newStatus == self::STATUS_CHECKED_OUT) {
$objHotelBookingDetail->id_status = $newStatus;
$objHotelBookingDetail->check_out = ($statusDate > $dateTo ? $dateTo : $statusDate);
} else {
$objHotelBookingDetail->id_status = $newStatus;
$objHotelBookingDetail->check_in = '';
$objHotelBookingDetail->check_out = '';
}
return $objHotelBookingDetail->save();
}
return false;
}
/**
* [DataForFrontSearch ].
*
* @param [date] $date_from [Start date of the booking]
* @param [date] $date_to [End date of the booking]
* @param [int] $id_hotel [Id of the Hotel]
* @param [int] $id_product [ID of the product]
* @param [int] $for_room_type [used for product page and category page for block cart]
* @param [int] $adult []
* @param [int] $children []
* @param [] $ratting [description]
* @param [] $amenities [description]
* @param [] $price [description]
* @param [int] $id_cart [Id of the cart]
* @param [int] $id_guest [Id of the guest]
*
* @return [array] [Returns true if successfully updated else returns false]
* Note:: $for_room_type is used for product page and category page for block cart
*/
public function DataForFrontSearch($date_from, $date_to, $id_hotel, $id_product = 0, $for_room_type = 0, $adult = 0, $children = 0, $ratting = -1, $amenities = 0, $price = 0, $id_cart = 0, $id_guest = 0)
{
// if (Module::isInstalled('productcomments')) {
// require_once _PS_MODULE_DIR_.'productcomments/ProductComment.php';
// }
$this->context = Context::getContext();
$bookingParams = array();
$bookingParams['date_from'] = $date_from;
$bookingParams['date_to'] = $date_to;
$bookingParams['hotel_id'] = $id_hotel;
$bookingParams['room_type'] = $id_product;
$bookingParams['adult'] = $adult;
$bookingParams['children'] = $children;
$bookingParams['num_rooms'] = 0;
$bookingParams['for_calendar'] = 0;
$bookingParams['search_available'] = 1;
$bookingParams['search_partial'] = 0;
$bookingParams['search_booked'] = 0;
$bookingParams['search_unavai'] = 0;
$bookingParams['id_cart'] = $id_cart;
$bookingParams['id_guest'] = $id_guest;
$booking_data = $this->getBookingData($bookingParams);
if (!$for_room_type) {
if (!empty($booking_data)) {
$obj_rm_type = new HotelRoomType();
foreach ($booking_data['rm_data'] as $key => $value) {
if (empty($value['data']['available'])) {
unset($booking_data['rm_data'][$key]);
} else {
$prod_ratting = 0;
// if (Module::isInstalled('productcomments')) {
// $prod_ratting = ProductComment::getAverageGrade($value['id_product'])['grade'];
// }
// if (empty($prod_ratting)) {
// $prod_ratting = 0;
// }
// if ($prod_ratting < $ratting && $ratting != -1) {
// unset($booking_data['rm_data'][$key]);
// } else
// {
$product = new Product($value['id_product'], false, $this->context->language->id);
$product_feature = $product->getFrontFeaturesStatic($this->context->language->id, $value['id_product']);
$prod_amen = array();
if (!empty($amenities) && $amenities) {
$prod_amen = $amenities;
foreach ($product_feature as $a_key => $a_val) {
if (($pa_key = array_search($a_val['id_feature'], $prod_amen)) !== false) {
unset($prod_amen[$pa_key]);
if (empty($prod_amen)) {
break;
}
}
}
if (!empty($prod_amen)) {
unset($booking_data['rm_data'][$key]);
}
}
if (empty($prod_amen)) {
$prod_price = Product::getPriceStatic($value['id_product'], self::useTax());
$productPriceWithoutReduction = $product->getPriceWithoutReduct(!self::useTax());
$productFeaturePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay($value['id_product'], $date_from, $date_to, self::useTax());
if (empty($price) || ($price['from'] <= $prod_price && $price['to'] >= $prod_price)) {
$cover_image_arr = $product->getCover($value['id_product']);
if (!empty($cover_image_arr)) {
$cover_img = $this->context->link->getImageLink($product->link_rewrite, $product->id.'-'.$cover_image_arr['id_image'], 'home_default');
} else {
$cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code.'-default', 'home_default');
}
$room_left = count($booking_data['rm_data'][$key]['data']['available']);
$rm_dtl = $obj_rm_type->getRoomTypeInfoByIdProduct($value['id_product']);
$booking_data['rm_data'][$key]['name'] = $product->name;
$booking_data['rm_data'][$key]['image'] = $cover_img;
$booking_data['rm_data'][$key]['description'] = $product->description_short;
$booking_data['rm_data'][$key]['feature'] = $product_feature;
$booking_data['rm_data'][$key]['price'] = $prod_price;
$booking_data['rm_data'][$key]['price_without_reduction'] = $productPriceWithoutReduction;
$booking_data['rm_data'][$key]['feature_price'] = $productFeaturePrice;
$booking_data['rm_data'][$key]['feature_price_diff'] = $productPriceWithoutReduction - $productFeaturePrice;
// if ($room_left <= (int)Configuration::get('WK_ROOM_LEFT_WARNING_NUMBER'))
$booking_data['rm_data'][$key]['room_left'] = $room_left;
$booking_data['rm_data'][$key]['adult'] = $rm_dtl['adult'];
$booking_data['rm_data'][$key]['children'] = $rm_dtl['children'];
$booking_data['rm_data'][$key]['ratting'] = $prod_ratting;
// if (Module::isInstalled('productcomments')) {
// $booking_data['rm_data'][$key]['num_review'] = ProductComment::getCommentNumber($value['id_product']);
// }
if (Configuration::get('PS_REWRITING_SETTINGS')) {
$booking_data['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($product).'?date_from='.$date_from.'&date_to='.$date_to;
} else {
$booking_data['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($product).'&date_from='.$date_from.'&date_to='.$date_to;
}
} else {
unset($booking_data['rm_data'][$key]);
}
}
// }
}
}
}
}
return $booking_data;
}
/**
* [getAvailableRoomsForReallocation :: Get the available rooms For the reallocation of the selected room].
*
* @param [date] $date_from[Start date of booking of the room to be swapped with available rooms]
* @param [date] $date_to [End date of booking of the room to be swapped with available rooms]
* @param [int] $room_type [Id of the product to which the room belongs to be swapped]
* @param [int] $hotel_id [Id of the Hotel to which the room belongs to be swapped]
*
* @return [array|false] [Returs array of the available rooms for swapping if rooms found else returnss false]
*/
public function getAvailableRoomsForReallocation($date_from, $date_to, $room_type, $hotel_id)
{
if (isset($_COOKIE['wk_id_cart'])) {
$current_admin_cart_id = $_COOKIE['wk_id_cart'];
}
$exclude_ids = 'SELECT `id_room` FROM `'._DB_PREFIX_.'htl_booking_detail`
WHERE `date_from` < \''.pSQL($date_to).'\' AND `date_to` > \''.pSQL($date_from).'\'
AND `is_refunded`=0 AND `is_back_order`=0
UNION
SELECT hri.`id` AS id_room
FROM `'._DB_PREFIX_.'htl_room_information` AS hri
INNER JOIN `'._DB_PREFIX_.'htl_room_disable_dates` AS hrdd ON (hrdd.`id_room_type` = hri.`id_product` AND hrdd.`id_room` = hri.`id`)
WHERE hri.`id_hotel`='.(int)$hotel_id.' AND hri.`id_product` ='.(int)$room_type.'
AND hri.`id_status` = '. HotelRoomInformation::STATUS_TEMPORARY_INACTIVE .'
AND (hrdd.`date_from` <= \''.pSql($date_to).'\' AND hrdd.`date_to` >= \''.pSql($date_from).'\')';
if (isset($current_admin_cart_id) && $current_admin_cart_id) {
$sql = 'SELECT `id` AS `id_room`, `id_product`, `id_hotel`, `room_num`, `comment` AS `room_comment`
FROM `'._DB_PREFIX_.'htl_room_information`
WHERE `id_hotel`='.(int)$hotel_id.' AND `id_product`='.(int)$room_type.'
AND (id_status = '. HotelRoomInformation::STATUS_ACTIVE .' or id_status = '. HotelRoomInformation::STATUS_TEMPORARY_INACTIVE .')
AND `id` NOT IN ('.$exclude_ids.')
AND `id` NOT IN (SELECT `id_room` FROM `'._DB_PREFIX_.'htl_cart_booking_data` WHERE `id_cart`='.
(int)$current_admin_cart_id.')';
} else {