Example #1
0
 function index()
 {
     $this->lang->load('reservation/hotels', 'en');
     //print_r($this->total_room_price);
     $hotel_id = $this->input->get('hotel_id');
     //if hotel id is not set return error
     if (!$hotel_id) {
         exit('Error');
     }
     //get hotel info
     $hotel = $this->front_model->hotel_info($hotel_id);
     if (!$hotel) {
         exit('Hotel not found.');
     }
     //set reservation info false
     $data['reservation'] = false;
     //if change reservation
     if ($this->input->get('res_code') or $this->session->userdata('res_code')) {
         $reservation = $this->front_model->get_reservation($this->input->get('res_code'), $hotel_id);
         if ($reservation) {
             $data['reservation'] = $reservation;
             //set user extras
             $this->session->set_userdata('user_extras', json_decode($reservation->extras, TRUE));
             $this->session->set_userdata('user_cart', json_decode($reservation->rooms, TRUE));
             //set reservation code on session
             $this->session->set_userdata('res_code', $this->input->get('res_code'));
         }
     }
     //options
     $default_lang = $this->session->userdata('default_lang') ? $this->session->userdata('default_lang') : 'en';
     $this->start_date = $this->input->get('checkin') ? $this->input->get('checkin') : date('d-m-Y');
     $this->end_date = $this->input->get('checkout') ? $this->input->get('checkout') : date('d-m-Y', strtotime('+1 day', strtotime($this->start_date)));
     $this->adults = $this->input->get('adults') ? $this->input->get('adults') : '2';
     $this->children = $this->input->get('children') ? $this->input->get('children') : '0';
     $this->currency = $hotel->currency;
     //$this->setCurrency($hotel->currency);
     //$this->user_currency = isset($this->session->userdata('currency')) ? $this->session->userdata('currency') : $this->currency;
     $this->user_currency = ($this->input->get('cur') and strlen($this->input->get('cur')) == 3) ? $this->input->get('cur') : $this->currency;
     if ($this->user_currency != $this->currency) {
         $this->currency_rate = currency_rates($this->currency, $this->user_currency);
     }
     //make dates to yy-mm-dd format
     $this->start_date = date('Y-m-d', strtotime($this->start_date));
     $this->end_date = date('Y-m-d', strtotime($this->end_date));
     //salaklar geçmişe dönük rezervasyon yapmak isterse
     if (strtotime($this->start_date) < strtotime(date('Y-m-d'))) {
         $this->start_date = date('Y-m-d');
         //exit('Checkin Date Error');
     }
     //salaklar start date'i end date'den sonrası bir tarihe girerse falan
     if (strtotime($this->start_date) >= strtotime($this->end_date)) {
         //$this->end_date = date('d-m-Y',strtotime('+1 day',strtotime($this->start_date)));
         exit('Checkout Date Error');
     }
     //clear cart
     if (NULL != $this->input->get('time')) {
         $this->session->unset_userdata('user_cart');
     }
     //load languages
     $this->lang->load('reservation/rooms', $default_lang);
     $this->lang->load('reservation/policies', $default_lang);
     //get rooms
     $search = array('child' => $this->children, 'adults' => $this->adults, 'language' => $default_lang);
     $arr = array();
     $rooms = $this->front_model->get_hotel_rooms($hotel_id, $search);
     if (FALSE === $rooms) {
         $arr['rooms'] = 0;
     } else {
         foreach (date_range($this->start_date, $this->end_date) as $k => $d) {
             $arr['dates'][$d] = $d;
             //set nights
             $this->nights = count($arr['dates']) - 1;
             foreach ($rooms as $key => $r) {
                 $arr['rooms'][$r->id]['name'] = $r->name;
                 $arr['rooms'][$r->id]['title'] = $r->title;
                 $arr['rooms'][$r->id]['content'] = $r->content;
                 $arr['rooms'][$r->id]['units'] = $r->room_units;
                 $arr['rooms'][$r->id]['included'] = $r->included;
                 $arr['rooms'][$r->id]['max_capacity'] = $r->max_capacity;
                 $arr['rooms'][$r->id]['max_adult'] = $r->max_adult;
                 $arr['rooms'][$r->id]['max_child'] = $r->max_child;
                 $arr['rooms'][$r->id]['default_policy'] = $r->default_policy;
                 $arr['rooms'][$r->id]['photos'] = $this->front_model->get_room_photos($r->id);
                 //check if price is set for the day
                 if ($this->front_model->get_bar_by_room($d, $r->id)) {
                     $arr['rooms'][$r->id]['prices'][$d] = $this->front_model->get_bar_by_room($d, $r->id);
                 } else {
                     $arr['rooms'][$r->id]['prices'][$d]['available'] = 0;
                     $arr['rooms'][$r->id]['prices'][$d]['stoped_arrival'] = 1;
                     $arr['rooms'][$r->id]['prices'][$d]['stoped_departure'] = 1;
                     $arr['rooms'][$r->id]['prices'][$d]['base_price'] = 0;
                     $arr['rooms'][$r->id]['prices'][$d]['single_price'] = 0;
                     $arr['rooms'][$r->id]['prices'][$d]['double_price'] = 0;
                     $arr['rooms'][$r->id]['prices'][$d]['triple_price'] = 0;
                     $arr['rooms'][$r->id]['prices'][$d]['extra_adult'] = 0;
                 }
                 $arr['rooms'][$r->id]['prices'][$d]['room_name'] = $r->name;
                 $arr['rooms'][$r->id]['prices'][$d]['room_id'] = $r->id;
                 $arr['rooms'][$r->id]['prices'][$d]['room_capacity'] = $r->capacity;
                 $arr['rooms'][$r->id]['prices'][$d]['room_child'] = $r->min_child;
             }
         }
     }
     //get promotions
     $promotions = $this->front_model->get_promotions($hotel_id);
     //set promotions by rooms id
     if ($promotions) {
         $promotion = array();
         foreach ($promotions as $k => $p) {
             $rooms = explode(',', $p['rooms']);
             foreach ($rooms as $r => $room) {
                 $promotion[$room][$p['id']] = $p;
                 $promotion[$room][$p['id']]['rule'] = 1;
             }
         }
         $arr['promotions'] = $promotion;
     } else {
         $arr['promotions'] = [];
     }
     $data['options'] = array('nights' => $this->nights, 'adults' => $this->adults, 'children' => $this->children, 'checkin' => $this->start_date, 'checkout' => $this->end_date, 'currency' => $this->currency, 'user_currency' => $this->user_currency, 'currency_rate' => $this->currency_rate);
     $this->session->set_userdata('options', $data['options']);
     $data['hotel_info'] = $hotel;
     $data['hotel_photos'] = $this->front_model->get_hotel_photos($hotel_id);
     //$data['rooms'] 			= array_orderby($arr['rooms'],'single_price',SORT_ASC);
     $data['rooms'] = $arr['rooms'];
     //create prices and set session
     //by rooms and promotions
     $this->calculate_room_prices($data['rooms']);
     if (is_array($arr['promotions'])) {
         $this->calculate_promo_prices($arr['promotions']);
         //set promotion rules
         $data['promotion'] = $this->set_promotion_rules($arr['promotions']);
     } else {
         $data['promotion'] = false;
     }
     //Extras
     $data['extras'] = $this->front_model->get_extras($hotel_id, $default_lang);
     $this->calculate_extra_prices($data['extras']);
     $data['prices'] = $this->session->userdata('prices_all');
     $data['user_cart'] = $this->session->userdata('user_cart');
     $data['user_extras'] = $this->session->userdata('user_extras');
     $data['guest'] = $this->session->userdata('guest');
     echo '<!--';
     echo '<pre>';
     print_r($data);
     echo '-->';
     $this->load->view('front/index', $data);
 }
Example #2
0
function show_price2($price, $cur, $cur2)
{
    if ($cur != $cur2) {
        $rate = currency_rates($cur, $cur2);
        return number_format($price * $rate, 2, '.', '');
    }
    return number_format($price, 2, '.', '');
}