Ejemplo n.º 1
0
 public function _get_availability_hotel_room()
 {
     $list_date = array();
     $room_id = STInput::request('post_id', '');
     $check_in = STInput::request('start', '');
     $check_out = STInput::request('end', '');
     $hotel_id = intval(get_post_meta($room_id, 'room_parent', true));
     $allow_full_day = get_post_meta($hotel_id, 'allow_full_day', true);
     if (!$allow_full_day || $allow_full_day == '') {
         $allow_full_day = 'on';
     }
     $year = date('Y', $check_in);
     if (empty($year)) {
         $year = date('Y');
     }
     $year2 = date('Y', $check_out);
     if (empty($year2)) {
         $year2 = date('Y');
     }
     $month = date('m', $check_in);
     if (empty($month)) {
         $month = date('m');
     }
     $month2 = date('m', $check_out);
     if (empty($month2)) {
         $month2 = date('m');
     }
     $result = HotelHelper::_get_full_ordered($room_id, $month, $month2, $year, $year2);
     $number_room = get_post_meta($room_id, 'number_room', true);
     $min_max = HotelHelper::_get_min_max_date_ordered($room_id, $year, $year2);
     if (is_array($min_max) && count($min_max) && is_array($result) && count($result)) {
         $disable = array();
         for ($i = intval($min_max['min_date']); $i <= intval($min_max['max_date']); $i = strtotime('+1 day', $i)) {
             $num_room = 0;
             foreach ($result as $key => $date) {
                 if ($allow_full_day == 'on') {
                     if ($i >= intval($date['check_in_timestamp']) && $i <= intval($date['check_out_timestamp'])) {
                         $num_room += $date['number_room'];
                     }
                 } else {
                     if ($i > intval($date['check_in_timestamp']) && $i < intval($date['check_out_timestamp'])) {
                         $num_room += $date['number_room'];
                     }
                 }
             }
             $disable[$i] = $num_room;
         }
         if (count($disable)) {
             foreach ($disable as $key => $num_room) {
                 if (intval($num_room) >= $number_room) {
                     $list_date[] = date(TravelHelper::getDateFormat(), $key);
                 }
             }
         }
     }
     $list_date_2 = AvailabilityHelper::_getDisableCustomDate($room_id, $month, $month2, $year, $year2);
     $date1 = strtotime($year . '-' . $month . '-01');
     $date2 = strtotime($year2 . '-' . $month2 . '-01');
     $date2 = strtotime(date('Y-m-t', $date2));
     $today = strtotime(date('Y-m-d'));
     $return = array();
     $booking_period = intval(get_post_meta($hotel_id, 'hotel_booking_period', true));
     for ($i = $date1; $i <= $date2; $i = strtotime('+1 day', $i)) {
         $period = TravelHelper::dateDiff(date('Y-m-d', $today), date('Y-m-d', $i));
         $d = date(TravelHelper::getDateFormat(), $i);
         if (in_array($d, $list_date)) {
             $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'booked');
         } else {
             if ($i < $today) {
                 $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'past');
             } else {
                 if (in_array($d, $list_date_2)) {
                     $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'disabled');
                 } else {
                     if ($period < $booking_period) {
                         $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'disabled');
                     } else {
                         $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'avalable', 'price' => TravelHelper::format_money(STPrice::getRoomPriceOnlyCustomPrice($room_id, $i, strtotime('+1 day', $i), 1)));
                     }
                 }
             }
         }
     }
     echo json_encode($return);
     die;
 }