<?php
function newdatesearch($date)
{
    list($m, $d, $a) = explode("/", $date);
    return $a . "-" . $m . "-" . $d;
}
//ROOM SEARCH
$checkinsearch = newdatesearch($checkin);
$checkoutsearch = newdatesearch($checkout);
$roomsearch = mysqli_query($conn, "SELECT hrt.room_type_id,hrt.room_type_name,hrt.room_type_capacity,(hrt.room_type_inventory - IFNULL(bca.cantidad,0)) AS disponibles, hrp.room_person,hrp.room_price,hot.hotel_tax FROM hotel_room_type AS hrt JOIN hotels AS hot ON hrt.hotel_id = hot.hotel_id JOIN (SELECT price_description,room_type_id,room_person,room_price,price_status,price_deleted FROM hotel_room_price WHERE room_person = '2' AND price_status = 'Y') AS hrp ON hrt.room_type_id = hrp.room_type_id LEFT OUTER JOIN (SELECT room_type_id, MAX(total_room + blocked_inventory) AS cantidad FROM booking_check_avilability WHERE check_in_date >= '$checkinsearch' AND check_out_date <= '$checkoutsearch' GROUP BY room_type_id) AS bca ON hrt.room_type_id = bca.room_type_id WHERE hrt.hotel_id = '$hotelid' AND hrt.deleted = '0' AND hrt.active = '1' AND hrt.room_type_capacity >= '$maxguests' HAVING disponibles >= '$rooms' ");
$roomsearchtotal = mysqli_num_rows($roomsearch);
if ($roomsearchtotal > 0) {
    
    while ($roomsearchData = mysqli_fetch_array($roomsearch)) {
        $room_price         = $roomsearchData['room_price'];
        $roompricetotaldias = $diasestadia * $room_price;
        $room_taxfee        = $roomsearchData['hotel_tax'] / 100;
        $room_taxfee        = number_format($room_taxfee, 2, '.', '');
        $roomtaxfeetotal    = $roompricetotaldias * $room_taxfee;
        $room_code          = $roomsearchData['room_type_id'];
        $room_name          = $roomsearchData['room_type_name'];
        $room_capacity      = $roomsearchData['room_type_capacity'];
        $camposrooms        = array(
            'room_code' => $room_code,
            'room_name' => $room_name,
            'room_capacity' => $room_capacity,
            'room_price' => $room_price,
            'room_price_total' => $roompricetotaldias,
            'taxfee' => $roomtaxfeetotal,
            'ratekey' => '',
            'ratecode' => '',
            'ota' => 'BK'
        );
        array_push($arrayroomssearch, $camposrooms);
    }
    
}
?>