Skip to content

Commit ad45246

Browse files
authored
Merge pull request #168 from shreesh-webkul/gli-524
FIX: update room reallocation data
2 parents 0db3d94 + 11a885b commit ad45246

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

modules/hotelreservationsystem/classes/HotelBookingDetail.php

+18-13
Original file line numberDiff line numberDiff line change
@@ -962,16 +962,19 @@ public function reallocateRoomWithAvailableSameRoomType($current_room_id, $date_
962962
{
963963
$date_from = date('Y-m-d H:i:s', strtotime($date_from));
964964
$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';
967967
$data = array('id_room' => $swapped_room_id);
968968
$where = 'date_from=\''.pSQL($date_from).'\' AND date_to=\''.pSQL($date_to).'\' AND id_room='.
969969
(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)) {
975978
return true;
976979
}
977980
return false;
@@ -1002,19 +1005,21 @@ public function swapRoomWithAvailableSameRoomType($current_room_id, $date_from,
10021005
'\' AND `date_to`=\''.pSQL($date_to).'\' AND `id_room`='.(int)$current_room_id
10031006
);
10041007

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).
10071010
'\' AND `date_to`=\''.pSQL($date_to).'\' AND `id_room`='.(int)$swapped_room_id
10081011
);
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).
10111014
'\' AND `date_to`=\''.pSQL($date_to).'\' AND `id_room`='.(int)$current_room_id
10121015
);
10131016
$sql = 'UPDATE `'._DB_PREFIX_.'htl_cart_booking_data` SET `id_room`=IF(`id`='.(int)$idcrt1.','.
10141017
(int)$current_room_id.','.(int)$swapped_room_id.') WHERE `id` IN('.(int)$idcrt1.','.(int)$idcrt2.')';
10151018

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.')';
10181023

10191024
if ($result = Db::getInstance()->execute($sql)) {
10201025
$result2 = Db::getInstance()->execute($sql1);

0 commit comments

Comments
 (0)