/**
  * @param Product $obj
  * @throws Exception
  * @throws PrestaShopException
  * @throws SmartyException
  */
 public function initFormConfiguration($obj)
 {
     $data = $this->createTemplate($this->tpl_form);
     if ($obj->id) {
         if ($this->product_exists_in_shop) {
             $obj_htl_info = new HotelBranchInformation();
             $htl_info = $obj_htl_info->hotelsNameAndId();
             if ($htl_info) {
                 $obj_room_status = new HotelRoomStatus();
                 $rm_status = $obj_room_status->getAllRoomStatus();
                 $obj_room_type = new HotelRoomType();
                 $htl_room_type = $obj_room_type->getRoomTypeInfoByIdProduct($obj->id);
                 if ($htl_room_type) {
                     $data->assign('htl_room_type', $htl_room_type);
                     $htl_full_info = $obj_htl_info->hotelBranchInfoById($htl_room_type['id_hotel']);
                     $data->assign('htl_full_info', $htl_full_info);
                     $obj_room_info = new HotelRoomInformation();
                     $htl_room_info = $obj_room_info->getHotelRoomInfo($obj->id, $htl_room_type['id_hotel']);
                     if ($htl_room_info) {
                         $data->assign('htl_room_info', $htl_room_info);
                     }
                 }
                 $data->assign(array('product' => $obj, 'htl_info' => $htl_info, 'rm_status' => $rm_status));
             } else {
                 $this->displayWarning($this->l('Add Hotel Before configurate this product.'));
             }
         } else {
             $this->displayWarning($this->l('You must save the product in this shop before managing hotel configuration.'));
         }
     } else {
         $this->displayWarning($this->l('You must save this product before managing hotel configuration.'));
     }
     $this->tpl_form_vars['custom_form'] = $data->fetch();
 }
Exemplo n.º 2
0
 public function getBookingData($date_from, $date_to, $hotel_id, $room_type, $adult = 0, $children = 0, $num_rooms = 1, $for_calendar = 0, $search_available = 1, $search_partial = 1, $search_booked = 1, $search_unavai = 1, $id_cart = 0, $id_guest = 0, $search_cart_rms = 0)
 {
     $date_from = date('Y-m-d H:i:s', strtotime($date_from));
     $date_to = date('Y-m-d H:i:s', strtotime($date_to));
     $obj_room_info = new HotelRoomInformation();
     //For check-in and check-out time
     //
     // $obj_hotel_info = new HotelBranchInformation();
     // $hotel_info = $obj_hotel_info->hotelBranchInfoById($hotel_id);
     // $date_from = date('Y-m-d H:i:s', strtotime("$date_from +".date('H',strtotime($hotel_info['check_in']))." hours +".date('i', strtotime($hotel_info['check_in']))." minutes"));
     // $date_to = date('Y-m-d H:i:s', strtotime("$date_to +".date('H', strtotime($hotel_info['check_out']))." hours +".date('i', strtotime($hotel_info['check_out']))." minutes"));
     $obj_rm_type = new HotelRoomType();
     $room_types = $obj_rm_type->getIdProductByHotelId($hotel_id, $room_type);
     if ($room_types) {
         $total_rooms = 0;
         $num_booked = 0;
         $num_unavail = 0;
         $num_avail = 0;
         $num_part_avai = 0;
         $num_cart = 0;
         foreach ($room_types as $key => $room_type) {
             $total_rooms += $obj_room_info->getHotelRoomInfo($room_type['id_product'], $hotel_id, 1);
             $product_name = (new Product((int) $room_type['id_product']))->name[Configuration::get('PS_LANG_DEFAULT')];
             if ($search_cart_rms) {
                 $sql = "SELECT cbd.id_product, cbd.id_room, cbd.id_hotel, cbd.booking_type, cbd.comment, rf.room_num, cbd.date_from, cbd.date_to \n\t\t\t\t\t\t\tFROM `" . _DB_PREFIX_ . "htl_cart_booking_data` AS cbd\n\t\t\t\t\t\t\tINNER JOIN `" . _DB_PREFIX_ . "htl_room_information` AS rf ON (rf.id = cbd.id_room)\n\t\t\t\t\t\t\tWHERE cbd.id_hotel=" . $hotel_id . " AND cbd.id_product =" . $room_type['id_product'] . " AND cbd.id_cart = " . $id_cart . " AND cbd.id_guest =" . $id_guest;
                 $cart_rooms = Db::getInstance()->executeS($sql);
                 $num_cart += count($cart_rooms);
             }
             if ($search_booked) {
                 $sql = "SELECT bd.id_product, bd.id_room, bd.id_hotel, bd.id_customer, bd.booking_type, bd.id_status AS booking_status, bd.comment, rf.room_num, bd.date_from, bd.date_to \n\t\t\t\t\t\t\tFROM `" . _DB_PREFIX_ . "htl_booking_detail` AS bd\n\t\t\t\t\t\t\tINNER JOIN `" . _DB_PREFIX_ . "htl_room_information` AS rf ON (rf.id = bd.id_room)\n\t\t\t\t\t\t\tWHERE bd.id_hotel=" . $hotel_id . " AND bd.id_product =" . $room_type['id_product'] . " AND bd.date_from <= '{$date_from}' AND bd.date_to >='{$date_to}'";
                 $booked_rooms = Db::getInstance()->executeS($sql);
                 $num_booked += count($booked_rooms);
             }
             if ($search_unavai) {
                 $sql = "SELECT `id_product`, `id_hotel`, `room_num`, `comment` AS `room_comment` FROM `" . _DB_PREFIX_ . "htl_room_information` WHERE id_hotel=" . $hotel_id . " AND id_product =" . $room_type['id_product'] . " AND id_status = 2";
                 $unavail_rooms = Db::getInstance()->executeS($sql);
                 $num_unavail += count($unavail_rooms);
             }
             if ($search_available) {
                 $exclude_ids = "SELECT id_room \n\t\t\t\t\t\t\t\tFROM " . _DB_PREFIX_ . "htl_booking_detail \n\t\t\t\t\t\t\t\tWHERE (date_from <= '{$date_from}' AND date_to > '{$date_from}' AND date_to <= '{$date_to}') OR (date_from > '{$date_from}' AND date_to < '{$date_to}') OR (date_from >= '{$date_from}' AND date_from < '{$date_to}' AND date_to >= '{$date_to}') OR (date_from < '{$date_from}' AND date_to > '{$date_to}')";
                 if (!empty($id_cart) && !empty($id_guest)) {
                     $exclude_ids .= " UNION\n\t\t\t\t\t\t\t\tSELECT id_room \n\t\t\t\t\t\t\t\tFROM " . _DB_PREFIX_ . "htl_cart_booking_data \n\t\t\t\t\t\t\t\tWHERE id_cart=" . $id_cart . " AND id_guest=" . $id_guest . " AND ((date_from <= '{$date_from}' AND date_to > '{$date_from}' AND date_to <= '{$date_to}') OR (date_from > '{$date_from}' AND date_to < '{$date_to}') OR (date_from >= '{$date_from}' AND date_from < '{$date_to}' AND date_to >= '{$date_to}') OR (date_from < '{$date_from}' AND date_to > '{$date_to}'))";
                 }
                 $sql = "SELECT ri.`id` AS `id_room`, ri.`id_product`, ri.`id_hotel`, ri.`room_num`, ri.`comment` AS `room_comment` \n\t\t\t\t\t\t\tFROM `" . _DB_PREFIX_ . "htl_room_information` AS ri ";
                 if ($adult || $children) {
                     $sql .= "INNER JOIN " . _DB_PREFIX_ . "htl_room_type AS rt ON (rt.id_product = ri.id_product AND rt.id_hotel = ri.id_hotel";
                     if ($adult) {
                         $sql .= " AND rt.adult >= " . $adult;
                     }
                     if ($children) {
                         $sql .= " AND rt.children >= " . $children;
                     }
                     $sql .= ")";
                 }
                 $sql .= " WHERE ri.id_hotel=" . $hotel_id . " AND ri.id_product=" . $room_type['id_product'] . " AND ri.id_status = 1 AND ri.id NOT IN (" . $exclude_ids . ")";
                 $avai_rooms = Db::getInstance()->executeS($sql);
                 $num_avail += count($avai_rooms);
             }
             if ($search_partial) {
                 $sql = "SELECT bd.id_product, bd.id_room, bd.id_hotel, bd.id_customer, bd.booking_type, bd.id_status AS booking_status, bd.comment AS `room_comment`, rf.room_num, bd.date_from, bd.date_to\n\t\t\t\t\t\t\tFROM `" . _DB_PREFIX_ . "htl_booking_detail` AS bd \n\t\t\t\t\t\t\tINNER JOIN `" . _DB_PREFIX_ . "htl_room_information` AS rf ON (rf.id = bd.id_room AND rf.id_status = 1)\n\t\t\t\t\t\t\tWHERE bd.id_hotel=" . $hotel_id . " AND bd.id_product=" . $room_type['id_product'] . " AND ((bd.date_from <= '{$date_from}' AND bd.date_to > '{$date_from}' AND bd.date_to < '{$date_to}') OR (bd.date_from > '{$date_from}' AND bd.date_from < '{$date_to}' AND bd.date_to >= '{$date_to}') OR (bd.date_from > '{$date_from}' AND bd.date_from < '{$date_to}' AND bd.date_to < '{$date_to}'))";
                 $partial_avai_rooms = Db::getInstance()->executeS($sql);
                 $rm_part_avai = count($partial_avai_rooms);
                 $this->all_dates_arr = $this->createDateRangeArray($date_from, $date_to, 1);
                 if (!$for_calendar) {
                     foreach ($partial_avai_rooms as $r_key => $r_val) {
                         if ($r_val['date_from'] <= $date_from && $r_val['date_to'] > $date_from && $r_val['date_to'] < $date_to) {
                             $forRange = $this->createDateRangeArray($r_val['date_to'], $date_to);
                             $available_dates = $this->getPartialRange($forRange);
                         } elseif ($r_val['date_from'] > $date_from && $r_val['date_from'] < $date_to && $r_val['date_to'] >= $date_to) {
                             $forRange = $this->createDateRangeArray($date_from, $r_val['date_from']);
                             $available_dates = $this->getPartialRange($forRange);
                         } elseif ($r_val['date_from'] > $date_from && $r_val['date_from'] < $date_to && $r_val['date_to'] > $date_from && $r_val['date_to'] < $date_to) {
                             $forRange1 = $this->createDateRangeArray($date_from, $r_val['date_from']);
                             $init_range = $this->getPartialRange($forRange1);
                             $forRange2 = $this->createDateRangeArray($r_val['date_to'], $date_to);
                             $last_range = $this->getPartialRange($forRange2);
                             $available_dates = array_merge($init_range, $last_range);
                         }
                         $partial_avai_rooms[$r_key]['avai_dates'] = $available_dates;
                     }
                     if (!empty($this->all_dates_arr)) {
                         $num_unavail += $rm_part_avai;
                         $rm_part_avai = 0;
                         $unavail_rooms = array_merge($unavail_rooms, $partial_avai_rooms);
                         $partial_avai_rooms = false;
                     }
                     $num_part_avai += $rm_part_avai;
                 }
             }
             if (!$for_calendar) {
                 $booking_data['rm_data'][$key]['name'] = $product_name;
                 $booking_data['rm_data'][$key]['id_product'] = (new Product((int) $room_type['id_product']))->id;
                 if ($search_available) {
                     $booking_data['rm_data'][$key]['data']['available'] = $avai_rooms;
                 }
                 if ($search_unavai) {
                     $booking_data['rm_data'][$key]['data']['unavailable'] = $unavail_rooms;
                 }
                 if ($search_booked) {
                     $booking_data['rm_data'][$key]['data']['booked'] = $booked_rooms;
                 }
                 if ($search_partial) {
                     $booking_data['rm_data'][$key]['data']['partially_available'] = $partial_avai_rooms;
                 }
                 if ($search_cart_rms) {
                     $booking_data['rm_data'][$key]['data']['cart_rooms'] = $cart_rooms;
                 }
             }
         }
         $booking_data['stats']['total_rooms'] = $total_rooms;
         if ($search_booked) {
             $booking_data['stats']['num_booked'] = $num_booked;
         }
         if ($search_unavai) {
             $booking_data['stats']['num_unavail'] = $num_unavail;
         }
         if ($search_available) {
             $booking_data['stats']['num_avail'] = $num_avail;
         }
         if ($search_partial) {
             $booking_data['stats']['num_part_avai'] = $num_part_avai;
         }
         if ($search_partial) {
             $booking_data['stats']['num_cart'] = $num_cart;
         }
         return $booking_data;
     }
 }