@@ -962,16 +962,19 @@ public function reallocateRoomWithAvailableSameRoomType($current_room_id, $date_
962
962
{
963
963
$ date_from = date ('Y-m-d H:i:s ' , strtotime ($ date_from ));
964
964
$ date_to = date ('Y-m-d H:i:s ' , strtotime ($ date_to ));
965
- $ table = 'htl_booking_detail ' ;
966
- $ table2 = 'htl_cart_booking_data ' ;
965
+ $ table = 'htl_cart_booking_data ' ;
966
+ $ table2 = 'htl_booking_detail ' ;
967
967
$ data = array ('id_room ' => $ swapped_room_id );
968
968
$ where = 'date_from= \'' .pSQL ($ date_from ).'\' AND date_to= \'' .pSQL ($ date_to ).'\' AND id_room= ' .
969
969
(int )$ current_room_id ;
970
- $ result = Db::getInstance ()->update ($ table , $ data , $ where );
971
- $ result2 = Db::getInstance ()->update ($ table2 , $ data , $ where );
972
- if ($ result ) {
973
- $ result2 = Db::getInstance ()->update ($ table2 , $ data , $ where );
974
- if ($ result2 ) {
970
+
971
+ if ($ result = Db::getInstance ()->update ($ table , $ data , $ where )) {
972
+ if ($ room_num = Db::getInstance ()->getValue (
973
+ 'SELECT `room_num` FROM ` ' ._DB_PREFIX_ .'htl_room_information` WHERE `id` = ' .$ swapped_room_id
974
+ )) {
975
+ $ data ['room_num ' ] = $ room_num ;
976
+ }
977
+ if ($ result2 = Db::getInstance ()->update ($ table2 , $ data , $ where )) {
975
978
return true ;
976
979
}
977
980
return false ;
@@ -1002,19 +1005,21 @@ public function swapRoomWithAvailableSameRoomType($current_room_id, $date_from,
1002
1005
'\' AND `date_to`= \'' .pSQL ($ date_to ).'\' AND `id_room`= ' .(int )$ current_room_id
1003
1006
);
1004
1007
1005
- $ id1 = Db::getInstance ()->getValue (
1006
- 'SELECT `id` FROM ` ' ._DB_PREFIX_ .'htl_booking_detail` WHERE `date_from`= \'' .pSQL ($ date_from ).
1008
+ $ swap_room = Db::getInstance ()->getRow (
1009
+ 'SELECT `id`, `room_num` FROM ` ' ._DB_PREFIX_ .'htl_booking_detail` WHERE `date_from`= \'' .pSQL ($ date_from ).
1007
1010
'\' AND `date_to`= \'' .pSQL ($ date_to ).'\' AND `id_room`= ' .(int )$ swapped_room_id
1008
1011
);
1009
- $ id2 = Db::getInstance ()->getValue (
1010
- 'SELECT `id` FROM ` ' ._DB_PREFIX_ .'htl_booking_detail` WHERE `date_from`= \'' .pSQL ($ date_from ).
1012
+ $ curr_room = Db::getInstance ()->getRow (
1013
+ 'SELECT `id`, `room_num` FROM ` ' ._DB_PREFIX_ .'htl_booking_detail` WHERE `date_from`= \'' .pSQL ($ date_from ).
1011
1014
'\' AND `date_to`= \'' .pSQL ($ date_to ).'\' AND `id_room`= ' .(int )$ current_room_id
1012
1015
);
1013
1016
$ sql = 'UPDATE ` ' ._DB_PREFIX_ .'htl_cart_booking_data` SET `id_room`=IF(`id`= ' .(int )$ idcrt1 .', ' .
1014
1017
(int )$ current_room_id .', ' .(int )$ swapped_room_id .') WHERE `id` IN( ' .(int )$ idcrt1 .', ' .(int )$ idcrt2 .') ' ;
1015
1018
1016
- $ sql1 = 'UPDATE ` ' ._DB_PREFIX_ .'htl_booking_detail` SET `id_room`=IF(`id`= ' .(int )$ id1 .', ' .(int )$ current_room_id .
1017
- ', ' .(int )$ swapped_room_id .') WHERE `id` IN( ' .(int )$ id1 .', ' .(int )$ id2 .') ' ;
1019
+ $ sql1 = 'UPDATE ` ' ._DB_PREFIX_ .'htl_booking_detail`
1020
+ SET `id_room`=IF(`id`= ' .(int )$ swap_room ['id ' ].', ' .(int )$ current_room_id .', ' .(int )$ swapped_room_id .'),
1021
+ `room_num`=IF(`id`= ' .(int )$ swap_room ['id ' ].', \'' .$ curr_room ['room_num ' ].'\', \'' .$ swap_room ['room_num ' ].'\')
1022
+ WHERE `id` IN( ' .(int )$ swap_room ['id ' ].', ' .(int )$ curr_room .') ' ;
1018
1023
1019
1024
if ($ result = Db::getInstance ()->execute ($ sql )) {
1020
1025
$ result2 = Db::getInstance ()->execute ($ sql1 );
0 commit comments