public function ajaxProcessDeleteHotelRoom() { $id_htl_info = Tools::getValue('id'); $obj_room_info = new HotelRoomInformation(); $return = $obj_room_info->deleteHotelRoomInfoById($id_htl_info); echo $return; }
protected function processBulkDelete() { if (is_array($this->boxes) && !empty($this->boxes)) { foreach ($this->boxes as $key => $value) { $obj_branch_features = new HotelBranchFeatures(); $obj_htl_cart_data = new HotelCartBookingData(); $obj_htl_img = new HotelImage(); $obj_htl_rm_info = new HotelRoomInformation(); $obj_htl_rm_type = new HotelRoomType(); $ids_product = $obj_htl_rm_type->getIdProductByHotelId($value); if (isset($ids_product) && $ids_product) { foreach ($ids_product as $key_prod => $value_prod) { $delete_cart_data = $obj_htl_cart_data->deleteBookingCartDataNotOrderedByProductId($value_prod['id_product']); $delete_room_info = $obj_htl_rm_info->deleteByProductId($value_prod['id_product']); $delete_room_type = $obj_htl_rm_type->deleteByProductId($value_prod['id_product']); $obj_product = new Product($value_prod['id_product']); $delete_product = $obj_product->delete(); } } $delete_branch_features = $obj_branch_features->deleteBranchFeaturesByHotelId($object->id); $htl_all_images = $obj_htl_img->getAllImagesByHotelId($object->id); foreach ($htl_all_images as $key_img => $value_img) { $path_img = _PS_MODULE_DIR_ . 'hotelreservationsystem/views/img/hotel_img/' . $value_img['hotel_image_id'] . '.jpg'; @unlink($path_img); } $delete_htl_img = $obj_htl_img->deleteByHotelId($object->id); } parent::processBulkDelete(); } else { $this->errors[] = Tools::displayError('You must select at least one element to delete.'); } }
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; } }
public function createDummyDataForProject() { //delete privious products of prestashop $all_products = Product::getSimpleProducts(Configuration::get('PS_LANG_DEFAULT')); foreach ($all_products as $key_pro => $value_pro) { $obj_product = new Product($value_pro['id_product']); $obj_product->delete(); } // first add a hotel................. $def_cont_id = Country::getDefaultCountryId(); $obj_hotel_info = new HotelBranchInformation(); $obj_hotel_info->active = 1; $obj_hotel_info->hotel_name = "The Hotel Prime"; $obj_hotel_info->phone = 01234567; $obj_hotel_info->email = "*****@*****.**"; $obj_hotel_info->check_in = '12:00'; $obj_hotel_info->check_out = '12:00'; $obj_hotel_info->short_description = $this->l('Nice place to stay'); $obj_hotel_info->description = $this->l('Nice place to stay'); $obj_hotel_info->rating = 3; $obj_hotel_info->city = 'Nainital'; $states = State::getStatesByIdCountry($def_cont_id); $state_id = $states[0]['id_state']; $obj_hotel_info->state_id = $state_id; $obj_hotel_info->country_id = $def_cont_id; $obj_hotel_info->zipcode = 263001; $obj_hotel_info->policies = $this->l('1. intelligentsia tattooed pop-up salvia asymmetrical mixtape meggings tousled ramps VHS cred. 2. intelligentsia tattooed pop-up salvia asymmetrical mixtape meggings tousled ramps VHS cred. 3. intelligentsia tattooed pop-up salvia asymmetrical mixtape meggings tousled ramps VHS cred. 4. intelligentsia tattooed pop-up salvia asymmetrical mixtape meggings tousled ramps VHS cred.'); $obj_hotel_info->address = 'Near post office, Mallital, Nainital'; $obj_hotel_info->save(); $htl_id = $obj_hotel_info->id; $grp_ids = array(); $obj_grp = new Group(); $data_grp_ids = $obj_grp->getGroups(1, $id_shop = false); foreach ($data_grp_ids as $key => $value) { $grp_ids[] = $value['id_group']; } $country_name = (new Country())->getNameById(Configuration::get('PS_LANG_DEFAULT'), $def_cont_id); $cat_country = $this->addCategory($country_name, false, $grp_ids); if ($cat_country) { $states = State::getStatesByIdCountry($def_cont_id); $state_name = $states[0]['name']; $cat_state = $this->addCategory($state_name, $cat_country, $grp_ids); } if ($cat_state) { $cat_city = $this->addCategory('DefCity', $cat_state, $grp_ids); } if ($cat_city) { $cat_hotel = $this->addCategory('The Hotel Prime', $cat_city, $grp_ids, 1, $htl_id); } if ($cat_hotel) { $obj_hotel_info = new HotelBranchInformation($htl_id); $obj_hotel_info->id_category = $cat_hotel; $obj_hotel_info->save(); } $branch_ftr_ids = array(1, 2, 4, 7, 8, 9, 11, 12, 14, 16, 17, 18, 21); foreach ($branch_ftr_ids as $key_ftr => $value_ftr) { $htl_ftr_obj = new HotelBranchFeatures(); $htl_ftr_obj->id_hotel = $htl_id; $htl_ftr_obj->feature_id = $value_ftr; $htl_ftr_obj->save(); } $prod_arr = array('Delux Rooms', 'Executive Rooms', 'luxury Rooms'); $img_num = 1; foreach ($prod_arr as $key_prod => $value_prod) { // Add Product $product = new Product(); $product->name = array(); $product->description = array(); $product->description_short = array(); $product->link_rewrite = array(); foreach (Language::getLanguages(true) as $lang) { $product->name[$lang['id_lang']] = $value_prod; $product->description[$lang['id_lang']] = $this->l('Fashion axe kogi yuccie, ramps shabby chic direct trade before they sold out distillery bicycle rights. Slow-carb +1 quinoa VHS. +1 brunch trust fund, meggings chartreuse sustainable everyday carry tumblr hoodie tacos tilde ramps post-ironic fixie.'); $product->description_short[$lang['id_lang']] = $this->l('Fashion axe kogi yuccie, ramps shabby chic direct trade before they sold out distillery bicycle rights. Slow-carb +1 quinoa VHS. +1 brunch trust fund, meggings chartreuse sustainable everyday carry tumblr hoodie tacos tilde ramps post-ironic fixie.'); $product->link_rewrite[$lang['id_lang']] = Tools::link_rewrite('Super Delux Rooms'); } $product->id_shop_default = Context::getContext()->shop->id; $product->id_category_default = 2; $product->price = 1000; $product->active = 1; $product->quantity = 99999999; $product->is_virtual = 1; $product->indexed = 1; $product->save(); $product_id = $product->id; Search::indexation(Tools::link_rewrite($value_prod), $product_id); $product->addToCategories(2); StockAvailable::updateQuantity($product_id, null, 99999999); //image upload for products $count = 0; $have_cover = false; $old_path = _PS_MODULE_DIR_ . $this->name . '/views/img/prod_imgs/' . $img_num . '.png'; $image_obj = new Image(); $image_obj->id_product = $product_id; $image_obj->position = Image::getHighestPosition($product_id) + 1; if ($count == 0) { if (!$have_cover) { $image_obj->cover = 1; } } else { $image_obj->cover = 0; } $image_obj->add(); $new_path = $image_obj->getPathForCreation(); $imagesTypes = ImageType::getImagesTypes('products'); foreach ($imagesTypes as $image_type) { ImageManager::resize($old_path, $new_path . '-' . $image_type['name'] . '.jpg', $image_type['width'], $image_type['height']); } ImageManager::resize($old_path, $new_path . '.jpg'); for ($k = 1; $k <= 5; $k++) { $htl_room_info_obj = new HotelRoomInformation(); $htl_room_info_obj->id_product = $product_id; $htl_room_info_obj->id_hotel = $htl_id; $htl_room_info_obj->room_num = 'A' . $i . '-10' . $k; $htl_room_info_obj->id_status = 1; $htl_room_info_obj->floor = 'first'; $htl_room_info_obj->save(); } $htl_rm_type = new HotelRoomType(); $htl_rm_type->id_product = $product_id; $htl_rm_type->id_hotel = $htl_id; $htl_rm_type->adult = 2; $htl_rm_type->children = 2; $htl_rm_type->save(); $img_num++; // Add features to the product $ftr_arr = array(0 => 8, 1 => 9, 2 => 10, 3 => 11); $ftr_val_arr = array(0 => 34, 1 => 35, 2 => 36, 3 => 37); foreach ($ftr_arr as $key_htl_ftr => $val_htl_ftr) { $product->addFeaturesToDB($val_htl_ftr, $ftr_val_arr[$key_htl_ftr]); } } return true; }