Merge branch 'Qloapps:develop' into gli-3097
This commit is contained in:
@@ -363,7 +363,7 @@ class AdminCartsControllerCore extends AdminController
|
||||
$objServiceProductCartDetail = new ServiceProductCartDetail();
|
||||
$hotelProducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$cart->id,
|
||||
[Product::SELLING_PREFERENCE_HOTEL_STANDALONE, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE],
|
||||
[],
|
||||
$idHotel = null,
|
||||
0,
|
||||
null,
|
||||
@@ -377,9 +377,15 @@ class AdminCartsControllerCore extends AdminController
|
||||
1
|
||||
);
|
||||
|
||||
$hotelProducts = array_filter($hotelProducts, function ($product) {
|
||||
return $product['id_hotel'] > 0 && $product['id_hotel_cart_booking'] == 0;
|
||||
});
|
||||
|
||||
$standaloneProducts = $objServiceProductCartDetail->getServiceProductsInCart(
|
||||
$cart->id,
|
||||
[Product::SELLING_PREFERENCE_STANDALONE]
|
||||
[],
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
if (count($standaloneProducts)) {
|
||||
@@ -1172,34 +1178,47 @@ class AdminCartsControllerCore extends AdminController
|
||||
if (Configuration::get('PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING')) {
|
||||
// get all services
|
||||
$objProduct = new Product();
|
||||
$hotelServiceProducts = $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE);
|
||||
$roomTypeServiceProducts = $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE);
|
||||
$serviceProducts = array_merge($roomTypeServiceProducts, $hotelServiceProducts);
|
||||
$serviceProducts = array_values(array_filter(
|
||||
$objProduct->getServiceProducts(true),
|
||||
function ($serviceProduct) {
|
||||
return Product::isSellableWithRoomType($serviceProduct['id_product']);
|
||||
}
|
||||
));
|
||||
if ($serviceProducts) {
|
||||
foreach ($serviceProducts as $key => $servProduct) {
|
||||
|
||||
if (!Product::isAvailableWhenOutOfStock(StockAvailable::outOfStock((int)$servProduct['id_product']))
|
||||
&& Product::getQuantity((int)$servProduct['id_product']) <= 0
|
||||
) {
|
||||
unset($serviceProducts[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$numDays = Product::getServicePriceBillableDays(
|
||||
$servProduct['price_calculation_method'],
|
||||
$dateFrom,
|
||||
$dateTo
|
||||
);
|
||||
|
||||
$serviceProducts[$key]['price_tax_exc'] = Product::getServiceProductPrice(
|
||||
$servProduct['id_product'],
|
||||
0,
|
||||
0,
|
||||
$idProduct,
|
||||
false,
|
||||
1,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
$idCart
|
||||
) / max($numDays, 1);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
|
||||
$serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($idProduct, 1, 0, false, 2, null);
|
||||
}
|
||||
|
||||
if ($serviceProducts) {
|
||||
foreach ($serviceProducts as $key => $servProduct) {
|
||||
$numDays = 1;
|
||||
if (Product::PRICE_CALCULATION_METHOD_PER_DAY == $servProduct['price_calculation_method']) {
|
||||
$numDays = HotelHelper::getNumberOfDays($dateFrom, $dateTo);
|
||||
}
|
||||
$serviceProducts[$key]['price_tax_exc'] = Product::getServiceProductPrice(
|
||||
$servProduct['id_product'],
|
||||
0,
|
||||
0,
|
||||
$idProduct,
|
||||
false,
|
||||
1,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
$idCart
|
||||
)/$numDays;
|
||||
}
|
||||
}
|
||||
|
||||
$objServiceProductCartDetail = new ServiceProductCartDetail();
|
||||
if ($selectedRoomServiceProduct = $objCartBookingData->getRoomRowByIdProductIdRoomInDateRange(
|
||||
$idCart,
|
||||
@@ -1324,9 +1343,14 @@ class AdminCartsControllerCore extends AdminController
|
||||
$idHotelCartBooking = Tools::getValue('id_hotel_cart_booking');
|
||||
// valiadate services being added
|
||||
if (Validate::isLoadedObject($objHtlCartBooking = new HotelCartBookingData($idHotelCartBooking))) {
|
||||
$objCart = new Cart($objHtlCartBooking->id_cart);
|
||||
$name = trim(Tools::getValue('new_service_name'));
|
||||
$price = Tools::getValue('new_service_price');
|
||||
$priceCalcMethod = Tools::getValue('new_service_price_calc_method');
|
||||
if (Tools::getValue('price_calculation_type') == Product::PRICE_CALCULATION_METHOD_ONCE_FOR_BOOKING) {
|
||||
$priceCalcMethod = Product::PRICE_CALCULATION_METHOD_ONCE_FOR_BOOKING;
|
||||
} elseif (is_array(Tools::getValue('new_service_price_calc_method'))) {
|
||||
$priceCalcMethod = array_sum(array_map('intval', Tools::getValue('new_service_price_calc_method')));
|
||||
}
|
||||
$priceAdditionType = Tools::getValue('new_service_price_addition_type');
|
||||
$productQty = Tools::getValue('new_service_qty');
|
||||
$idTaxRuleGroup = Tools::getValue('new_service_price_tax_rule_group');
|
||||
@@ -1358,6 +1382,15 @@ class AdminCartsControllerCore extends AdminController
|
||||
$response['hasError'] = true;
|
||||
$response['errors'][] = Tools::displayError('Invalid service name');
|
||||
}
|
||||
|
||||
if (empty($priceCalcMethod)) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'][] = Tools::displayError('Please select at least one day to apply the price calculation method.');
|
||||
} elseif (
|
||||
!Validate::isUnsignedInt($priceCalcMethod)) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'][] = Tools::displayError('Invalid price calculation method.');
|
||||
}
|
||||
|
||||
if (!isset($price)) {
|
||||
$response['hasError'] = true;
|
||||
@@ -1370,6 +1403,12 @@ class AdminCartsControllerCore extends AdminController
|
||||
// if no validation errors then add service
|
||||
if (!$response['hasError']) {
|
||||
// ======= START: Create Service product =========
|
||||
if ($objCart->id_currency != (int)Configuration::get('PS_CURRENCY_DEFAULT')) {
|
||||
$currency = Currency::getCurrencyInstance($objCart->id_currency);
|
||||
$price = Tools::ps_round($price/$currency->conversion_rate, 6);
|
||||
$this->context->currency = new Currency((int) $objCart->id_currency);
|
||||
}
|
||||
|
||||
$objServiceProduct = new Product();
|
||||
$objServiceProduct->price_calculation_method = $priceCalcMethod;
|
||||
$objServiceProduct->selling_preference_type = Product::SELLING_PREFERENCE_WITH_ROOM_TYPE;
|
||||
@@ -1409,7 +1448,6 @@ class AdminCartsControllerCore extends AdminController
|
||||
RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE
|
||||
);
|
||||
// If service product is create successfully the start adding the product in cart and order
|
||||
$objCart = new Cart($objHtlCartBooking->id_cart);
|
||||
$objServiceProduct = new Product($objServiceProduct->id, false, $objCart->id_lang);
|
||||
|
||||
$objServiceProductCartDetail = new ServiceProductCartDetail();
|
||||
@@ -1476,19 +1514,46 @@ class AdminCartsControllerCore extends AdminController
|
||||
if (Configuration::get('PS_ALLOW_ADD_ALL_SERVICES_IN_BOOKING')) {
|
||||
// get all services
|
||||
$objProduct = new Product();
|
||||
$hotelServiceProducts = $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE);
|
||||
$roomTypeServiceProducts = $objProduct->getServiceProducts(true, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE);
|
||||
$serviceProducts = array_merge($roomTypeServiceProducts, $hotelServiceProducts);
|
||||
$serviceProducts = array_values(array_filter(
|
||||
$objProduct->getServiceProducts(true),
|
||||
function ($serviceProduct) {
|
||||
return Product::isSellableWithRoomType($serviceProduct['id_product']);
|
||||
}
|
||||
));
|
||||
if ($serviceProducts) {
|
||||
foreach ($serviceProducts as $key => $servProduct) {
|
||||
|
||||
if (!Product::isAvailableWhenOutOfStock(StockAvailable::outOfStock((int)$servProduct['id_product']))
|
||||
&& Product::getQuantity((int)$servProduct['id_product']) <= 0
|
||||
) {
|
||||
unset($serviceProducts[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$numDays = Product::getServicePriceBillableDays(
|
||||
$servProduct['price_calculation_method'],
|
||||
$objCartBookingData->date_from,
|
||||
$objCartBookingData->date_to
|
||||
);
|
||||
|
||||
$serviceProducts[$key]['price_tax_exc'] = Product::getServiceProductPrice(
|
||||
$servProduct['id_product'],
|
||||
0,
|
||||
0,
|
||||
$objCartBookingData->id_product,
|
||||
false,
|
||||
1,
|
||||
$objCartBookingData->date_from,
|
||||
$objCartBookingData->date_to,
|
||||
$objCartBookingData->id_cart
|
||||
)/ max($numDays, 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
|
||||
$serviceProducts = $objRoomTypeServiceProduct->getServiceProductsData($objCartBookingData->id_product, 1, 0, false, 2, null);
|
||||
}
|
||||
|
||||
if ($serviceProducts) {
|
||||
foreach ($serviceProducts as $key => $servProduct) {
|
||||
$serviceProducts[$key]['price_tax_exc'] = $servProduct['price'];
|
||||
}
|
||||
}
|
||||
|
||||
$objServiceProductCartDetail = new ServiceProductCartDetail();
|
||||
if ($selectedRoomServiceProduct = $objCartBookingData->getRoomRowByIdProductIdRoomInDateRange(
|
||||
@@ -1575,6 +1640,39 @@ class AdminCartsControllerCore extends AdminController
|
||||
$response['hasError'] = true;
|
||||
$response['errors'][] = Tools::displayError('Invalid unit price for service').': '.$objProduct->name;
|
||||
}
|
||||
|
||||
if ($selected && $objProduct->allow_multiple_quantity
|
||||
&& isset($serviceQuantities[$idServiceProduct])
|
||||
&& Validate::isUnsignedInt($serviceQuantities[$idServiceProduct])
|
||||
) {
|
||||
$cartTotalQty = Cart::getProductQtyInCart($objCart->id, $idServiceProduct);
|
||||
|
||||
$qty = (int)$serviceQuantities[$idServiceProduct];
|
||||
$numDays = Product::getServicePriceBillableDays(
|
||||
$objProduct->price_calculation_method,
|
||||
$objHotelCartBookingData->date_from,
|
||||
$objHotelCartBookingData->date_to
|
||||
);
|
||||
|
||||
$existingQty = 0;
|
||||
$objSpCartDetail = new ServiceProductCartDetail();
|
||||
if ($idExistingDetail = $objSpCartDetail->alreadyExists(
|
||||
$objCart->id,
|
||||
$idServiceProduct,
|
||||
$idCartBooking
|
||||
)) {
|
||||
$existingQty = (int)(new ServiceProductCartDetail($idExistingDetail))->quantity * $numDays;
|
||||
}
|
||||
|
||||
$finalQty = (int)$cartTotalQty - $existingQty + ($qty * $numDays);
|
||||
if ($objProduct->max_quantity && $finalQty > $objProduct->max_quantity) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'][] = Tools::displayError(sprintf('Cannot add more than %d quantity.', $objProduct->max_quantity)).': '.$objProduct->name;
|
||||
} elseif (!Product::isAvailableWhenOutOfStock(StockAvailable::outOfStock((int)$idServiceProduct)) && !$objProduct->checkQty($finalQty)) {
|
||||
$response['hasError'] = true;
|
||||
$response['errors'][] = Tools::displayError('There isn\'t enough product in stock.').': '.$objProduct->name;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$response['errors'][] = Tools::displayError('Some services not found. please try after refreshing the page');
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ class AdminDashboardControllerCore extends AdminController
|
||||
|
||||
$objHotelInfo = new HotelBranchInformation();
|
||||
$idsHotel = $objHotelInfo->getProfileAccessedHotels($this->context->employee->id_profile, 1, 1);
|
||||
$hotelOptions = array(array('id_hotel' => false, 'hotel_name' => $this->l('All Hotels')));
|
||||
$hotelOptions = array(array('id_hotel' => false, 'hotel_name' => $this->l('All Properties')));
|
||||
foreach ($idsHotel as $idHotel) {
|
||||
$objHotelBranchInfo = new HotelBranchInformation($idHotel, $this->context->language->id);
|
||||
$hotelAddressInfo = HotelBranchInformation::getAddress($idHotel);
|
||||
|
||||
@@ -86,7 +86,7 @@ class AdminImagesControllerCore extends AdminController
|
||||
'orderby' => false
|
||||
),
|
||||
'hotels' => array(
|
||||
'title' => $this->l('Hotels'),
|
||||
'title' => $this->l('Properties'),
|
||||
'align' => 'center',
|
||||
'type' => 'bool',
|
||||
'active' => 'hotels',
|
||||
@@ -301,7 +301,7 @@ class AdminImagesControllerCore extends AdminController
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Hotels'),
|
||||
'label' => $this->l('Properties'),
|
||||
'name' => 'hotels',
|
||||
'required' => false,
|
||||
'is_bool' => true,
|
||||
@@ -503,7 +503,7 @@ class AdminImagesControllerCore extends AdminController
|
||||
$types = array(
|
||||
'categories' => $this->l('Categories'),
|
||||
'products' => $this->l('Room Types/Products'),
|
||||
'hotels' => $this->l('Hotels'),
|
||||
'hotels' => $this->l('Properties'),
|
||||
// 'manufacturers' => $this->l('Manufacturers'),
|
||||
// 'suppliers' => $this->l('Suppliers'),
|
||||
// 'scenes' => $this->l('Scenes'),
|
||||
|
||||
@@ -78,7 +78,7 @@ class AdminImportControllerCore extends AdminController
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->entities = array(
|
||||
$this->l('Hotels'),
|
||||
$this->l('Properties'),
|
||||
$this->l('Room Types'),
|
||||
$this->l('Rooms'),
|
||||
$this->l('Categories'),
|
||||
@@ -108,7 +108,7 @@ class AdminImportControllerCore extends AdminController
|
||||
'parent' => Configuration::get('PS_HOME_CATEGORY'),
|
||||
);
|
||||
break;
|
||||
case $this->entities[$this->l('Hotels')]:
|
||||
case $this->entities[$this->l('Properties')]:
|
||||
$this->required_fields = array(
|
||||
'hotel_name',
|
||||
'phone',
|
||||
@@ -132,7 +132,7 @@ class AdminImportControllerCore extends AdminController
|
||||
'no' => array('label' => $this->l('Ignore this column')),
|
||||
'id' => array('label' => $this->l('ID')),
|
||||
'active' => array('label' => $this->l('Active (0/1)')),
|
||||
'hotel_name' => array('label' => $this->l('Hotel Name *')),
|
||||
'hotel_name' => array('label' => $this->l('Property Name *')),
|
||||
'short_description' => array('label' => $this->l('Short Description')),
|
||||
'description' => array('label' => $this->l('Description')),
|
||||
'phone' => array('label' => $this->l('Mobile phone *')),
|
||||
@@ -146,7 +146,7 @@ class AdminImportControllerCore extends AdminController
|
||||
'city' => array('label' => $this->l('City *')),
|
||||
'postcode' => array('label' => $this->l('Zip Code *')),
|
||||
'fax' => array('label' => $this->l('Fax')),
|
||||
'policies' => array('label' => $this->l('Hotel Policies')),
|
||||
'policies' => array('label' => $this->l('Property Policies')),
|
||||
'active_refund' => array('label' => $this->l('Allow Refund (0 = No, 1 = Yes)')),
|
||||
'refund_ids' => array('label' => $this->l('Refund IDs (x,y,z...)')),
|
||||
'max_checkout_offset' => array('label' => $this->l('Maximum checkout offset')),
|
||||
@@ -168,7 +168,7 @@ class AdminImportControllerCore extends AdminController
|
||||
'id' => array('label' => $this->l('ID')),
|
||||
'active' => array('label' => $this->l('Active (0/1)')),
|
||||
'name' => array('label' => $this->l('Name *')),
|
||||
'id_hotel' => array('label' => $this->l('Hotel ID *')),
|
||||
'id_hotel' => array('label' => $this->l('Property ID *')),
|
||||
'price' => array('label' => $this->l('Pre-tax retail price')),
|
||||
'wholesale_price' => array('label' => $this->l('Pre-tax operating cost')),
|
||||
'id_tax_rules_group' => array('label' => $this->l('Tax rule ID')),
|
||||
@@ -1472,8 +1472,8 @@ class AdminImportControllerCore extends AdminController
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->warnings[] = $this->l('Hotel creation for the ').$objCountry->name.
|
||||
$this->l(' is currently unavailable. Kindly activate the country for hotel creation.');
|
||||
$this->warnings[] = $this->l('Property creation for the ').$objCountry->name.
|
||||
$this->l(' is currently unavailable. Kindly activate the country for property creation.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1882,7 +1882,7 @@ class AdminImportControllerCore extends AdminController
|
||||
}
|
||||
|
||||
$objServiceProduct = new Product($idServiceProduct);
|
||||
if (Product::SELLING_PREFERENCE_WITH_ROOM_TYPE == $objServiceProduct->selling_preference_type) {
|
||||
if (Product::isSellableWithRoomType($objServiceProduct->id)) {
|
||||
$objRoomTypeServiceProduct->addRoomProductLink(
|
||||
$objServiceProduct->id,
|
||||
$product->id,
|
||||
@@ -2310,12 +2310,12 @@ class AdminImportControllerCore extends AdminController
|
||||
$info['shop'] = explode($this->multiple_value_separator, $info['shop']);
|
||||
|
||||
RoomTypeServiceProduct::deleteRoomProductLink($product->id);
|
||||
if (Product::SELLING_PREFERENCE_WITH_ROOM_TYPE == $product->selling_preference_type) {
|
||||
if (Product::isSellableWithRoomType($product->id)) {
|
||||
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
|
||||
if (isset($info['id_room_types']) && $info['id_room_types']) {
|
||||
$objRoomTypeServiceProduct->addRoomProductLink(
|
||||
$product->id,
|
||||
$product->id_room_types,
|
||||
$info['id_room_types'],
|
||||
RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE
|
||||
);
|
||||
}
|
||||
@@ -3273,7 +3273,7 @@ class AdminImportControllerCore extends AdminController
|
||||
}
|
||||
}
|
||||
break;
|
||||
case $this->entities[$this->l('Hotels')]:
|
||||
case $this->entities[$this->l('Properties')]:
|
||||
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'htl_branch_info_lang`');
|
||||
Db::getInstance()->execute('DELETE c, cl FROM `'._DB_PREFIX_.'category` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.id_category = cl.id_category
|
||||
@@ -3462,7 +3462,7 @@ class AdminImportControllerCore extends AdminController
|
||||
$import_type = false;
|
||||
Db::getInstance()->disableCache();
|
||||
switch ((int)Tools::getValue('entity')) {
|
||||
case $this->entities[$import_type = $this->l('Hotels')]:
|
||||
case $this->entities[$import_type = $this->l('Properties')]:
|
||||
$this->hotelImport();
|
||||
$this->clearSmartyCache();
|
||||
break;
|
||||
|
||||
@@ -200,8 +200,14 @@ class AdminNormalProductsControllerCore extends AdminController
|
||||
Product::PRICE_ADDITION_TYPE_INDEPENDENT => $this->l('Convenience Fee')
|
||||
);
|
||||
$priceCalculationMethod = array(
|
||||
Product::PRICE_CALCULATION_METHOD_PER_BOOKING => $this->l('Add price once for the booking range'),
|
||||
Product::PRICE_CALCULATION_METHOD_PER_DAY => $this->l('Add price for each day of booking')
|
||||
Product::PRICE_CALCULATION_METHOD_ON_CHECKIN_DAY => $this->l('Check-in day'),
|
||||
Product::PRICE_CALCULATION_METHOD_ON_CHECKOUT_DAY => $this->l('Check-out day'),
|
||||
Product::PRICE_CALCULATION_METHOD_ON_DURING_STAY => $this->l('During-stay days'),
|
||||
Product::PRICE_CALCULATION_METHOD_CHECKIN_DAY_AND_CHECKOUT_DAY => $this->l('Check-in day | Check-out days'),
|
||||
Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_DURING_STAY => $this->l('Check-in day | During-stay days'),
|
||||
Product::PRICE_CALCULATION_METHOD_CHECKOUT_AND_DURING_STAY => $this->l('Check-out day | During-stay days'),
|
||||
Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY => $this->l('Check-in day | During-stay days | Check-out day'),
|
||||
Product::PRICE_CALCULATION_METHOD_ONCE_FOR_BOOKING => $this->l('Once per booking'),
|
||||
);
|
||||
|
||||
$this->_join .= '
|
||||
@@ -222,7 +228,7 @@ class AdminNormalProductsControllerCore extends AdminController
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (rsp.`id_element` = hrt.`id_product` AND rsp.`element_type` = '.(int)RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE.')
|
||||
'.HotelBranchInformation::addHotelRestriction(false, 'hrt');
|
||||
|
||||
$this->_select .= ' IF(a.`auto_add_to_cart`, "'.$this->l('Yes').'", "'.$this->l('No').'") as auto_added, IF(a.`auto_add_to_cart`, 1, 0) as badge_success, IF(a.`show_at_front`, "'.$this->l('Yes').'", "'.$this->l('No').'") as show_at_front_txt, IF(a.`price_calculation_method` = '.(int)Product::PRICE_CALCULATION_METHOD_PER_DAY.', "'.$this->l('Per Day').'", "'.$this->l('Per Booking').'") as price_calculation_method_txt, (SELECT COUNT(hri.`id`) FROM `'._DB_PREFIX_.'htl_room_information` hri WHERE hri.`id_product` = a.`id_product`) as num_rooms, ';
|
||||
$this->_select .= ' IF(a.`auto_add_to_cart`, "'.$this->l('Yes').'", "'.$this->l('No').'") as auto_added, IF(a.`auto_add_to_cart`, 1, 0) as badge_success, IF(a.`show_at_front`, "'.$this->l('Yes').'", "'.$this->l('No').'") as show_at_front_txt, (SELECT COUNT(hri.`id`) FROM `'._DB_PREFIX_.'htl_room_information` hri WHERE hri.`id_product` = a.`id_product`) as num_rooms, ';
|
||||
$this->_select .= ' COUNT(hrt.`id_product`) as products_associated, ';
|
||||
$this->_select .= 'shop.`name` AS `shopname`, a.`id_shop_default`, ';
|
||||
$this->_select .= $alias_image.'.`id_image` AS `id_image`, cl.`name` AS `name_category`, '.$alias.'.`price`, 0 AS `price_final`, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` AS `sav_quantity`, '.$alias.'.`active`, IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`';
|
||||
@@ -297,13 +303,14 @@ class AdminNormalProductsControllerCore extends AdminController
|
||||
'callback' => 'getPriceDisplayPreference',
|
||||
'list' => $priceAdditionType,
|
||||
);
|
||||
$this->fields_list['price_calculation_method_txt'] = array(
|
||||
$this->fields_list['price_calculation_method'] = array(
|
||||
'title' => $this->l('Price calculation method'),
|
||||
'filter_key' => 'a!price_calculation_method',
|
||||
'type' => 'select',
|
||||
'list' => $priceCalculationMethod,
|
||||
'visible_default' => true,
|
||||
'optional' => true,
|
||||
'callback' => 'getPriceCalculationMethod',
|
||||
);
|
||||
$this->servicesCategory = array();
|
||||
$idServiceCategory = Configuration::get('PS_SERVICE_CATEGORY');
|
||||
@@ -325,9 +332,12 @@ class AdminNormalProductsControllerCore extends AdminController
|
||||
// Code For Standard product working
|
||||
// $sellingPreferenceTypes = array(
|
||||
// Product::SELLING_PREFERENCE_WITH_ROOM_TYPE => $this->l('With room type'),
|
||||
// Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE => $this->l('With hotel|room type'),
|
||||
// Product::SELLING_PREFERENCE_STANDALONE => $this->l('Standalone'),
|
||||
// Product::SELLING_PREFERENCE_HOTEL_STANDALONE => $this->l('With hotel'),
|
||||
// Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE => $this->l('With hotel | With room type'),
|
||||
// Product::SELLING_PREFERENCE_WITH_STANDALONE => $this->l('With Standalone'),
|
||||
// Product::SELLING_PREFERENCE_WITH_HOTEL => $this->l('With hotel'),
|
||||
// Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_STANDALONE => $this->l('With hotel | With standalone'),
|
||||
// Product::SELLING_PREFERENCE_WITH_STANDALONE_AND_WITH_ROOM_TYPE => $this->l('With room type | With standalone'),
|
||||
// Product::SELLING_PREFERENCE_WITH_HOTEL_AND_WITH_ROOM_TYPE_AND_WITH_STANDALONE => $this->l('With hotel | With room type | With standalone'),
|
||||
// );
|
||||
// $this->fields_list['selling_preference_type'] = array(
|
||||
// 'type' => 'select',
|
||||
@@ -424,17 +434,28 @@ class AdminNormalProductsControllerCore extends AdminController
|
||||
|
||||
public function getBuyingOption($selling_preference_type, $row)
|
||||
{
|
||||
if ($selling_preference_type == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE) {
|
||||
return $this->l('With room type');
|
||||
} else if ($selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE) {
|
||||
return $this->l('With hotel|room type');
|
||||
} else if ($selling_preference_type == Product::SELLING_PREFERENCE_STANDALONE) {
|
||||
return $this->l('Standalone');
|
||||
} else if ($selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE) {
|
||||
return $this->l('With hotel');
|
||||
$list = $this->fields_list['selling_preference_type']['list'];
|
||||
|
||||
if (empty($list[$selling_preference_type])) {
|
||||
return '--';
|
||||
}
|
||||
|
||||
return '--';
|
||||
$options = array_map('trim', explode('|', $list[$selling_preference_type]));
|
||||
|
||||
return implode(', ', $options);
|
||||
}
|
||||
|
||||
public function getPriceCalculationMethod($price_calculation_method, $row)
|
||||
{
|
||||
$list = $this->fields_list['price_calculation_method']['list'];
|
||||
|
||||
if (empty($list[$price_calculation_method])) {
|
||||
return '--';
|
||||
}
|
||||
|
||||
$options = array_map('trim', explode('|', $list[$price_calculation_method]));
|
||||
|
||||
return implode(', ', $options);
|
||||
}
|
||||
|
||||
public function getHotelName($hotelName, $row)
|
||||
@@ -499,6 +520,11 @@ class AdminNormalProductsControllerCore extends AdminController
|
||||
*/
|
||||
protected function copyFromPost(&$object, $table)
|
||||
{
|
||||
if (Tools::getValue('price_calculation_type') == Product::PRICE_CALCULATION_METHOD_ONCE_FOR_BOOKING) {
|
||||
$_POST['price_calculation_method'] = Product::PRICE_CALCULATION_METHOD_ONCE_FOR_BOOKING;
|
||||
} elseif (is_array(Tools::getValue('price_calculation_method'))) {
|
||||
$_POST['price_calculation_method'] = array_sum(array_map('intval', Tools::getValue('price_calculation_method')));
|
||||
}
|
||||
parent::copyFromPost($object, $table);
|
||||
if (get_class($object) != 'Product') {
|
||||
return;
|
||||
@@ -1552,6 +1578,8 @@ class AdminNormalProductsControllerCore extends AdminController
|
||||
_PS_JS_DIR_.'jquery/plugins/timepicker/jquery-ui-timepicker-addon.css',
|
||||
_PS_CSS_DIR_.'ps-hotel-reservation.css',
|
||||
));
|
||||
}else {
|
||||
$this->addJqueryUI('ui.tooltip', 'base', true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2226,6 +2254,17 @@ class AdminNormalProductsControllerCore extends AdminController
|
||||
*/
|
||||
public function checkProduct()
|
||||
{
|
||||
if (Tools::getValue('price_calculation_type') == Product::PRICE_CALCULATION_METHOD_ONCE_FOR_BOOKING) {
|
||||
$_POST['price_calculation_method'] = Product::PRICE_CALCULATION_METHOD_ONCE_FOR_BOOKING;
|
||||
} elseif (is_array(Tools::getValue('price_calculation_method'))) {
|
||||
$_POST['price_calculation_method'] = array_sum(array_map('intval', Tools::getValue('price_calculation_method')));
|
||||
}
|
||||
|
||||
// Code For Standard product working
|
||||
// if (is_array(Tools::getValue('selling_preference_type'))) {
|
||||
// $_POST['selling_preference_type'] = array_sum(array_map('intval', Tools::getValue('selling_preference_type')));
|
||||
// }
|
||||
|
||||
$className = 'Product';
|
||||
// @todo : the call_user_func seems to contains only statics values (className = 'Product')
|
||||
$rules = call_user_func(array($this->className, 'getValidationRules'), $this->className);
|
||||
@@ -2377,6 +2416,15 @@ class AdminNormalProductsControllerCore extends AdminController
|
||||
$this->errors[] = $this->l('This product must be in the default category.');
|
||||
}
|
||||
|
||||
// code for standard product working
|
||||
// if (!Tools::getValue('selling_preference_type')) {
|
||||
// $this->errors[] = $this->l('Please select at least one buying option.');
|
||||
// }
|
||||
|
||||
if (Tools::getValue('id_product') && !Tools::getValue('price_calculation_method')) {
|
||||
$this->errors[] = $this->l('Please select at least one day to apply the price calculation method on.');
|
||||
}
|
||||
|
||||
// Tags
|
||||
foreach ($languages as $language) {
|
||||
if ($value = Tools::getValue('tags_'.$language['id_lang'])) {
|
||||
@@ -3012,7 +3060,8 @@ class AdminNormalProductsControllerCore extends AdminController
|
||||
if (Validate::isLoadedObject($product)) {
|
||||
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
|
||||
$allAssociations = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType($product->id);
|
||||
if (Product::SELLING_PREFERENCE_WITH_ROOM_TYPE == $product->selling_preference_type) {
|
||||
|
||||
if (Product::isSellableWithRoomType($product->id)) {
|
||||
$associatedRoomTypes = $allAssociations['room_type'];
|
||||
$selectedRoomTypes = Tools::getValue('RT_tree_room_type_box', array());
|
||||
|
||||
@@ -3049,89 +3098,14 @@ class AdminNormalProductsControllerCore extends AdminController
|
||||
RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE
|
||||
);
|
||||
}
|
||||
RoomTypeServiceProduct::deleteRoomProductLink(
|
||||
$product->id,
|
||||
RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL
|
||||
);
|
||||
} elseif (Product::SELLING_PREFERENCE_HOTEL_STANDALONE == $product->selling_preference_type) {
|
||||
$associatedHotels = $allAssociations['hotel'];
|
||||
$selectedHotel = Tools::getValue('hotel_box', array());
|
||||
// Generate list of new associations
|
||||
$newHotels = array();
|
||||
foreach ($selectedHotel as $selectedRoomType) {
|
||||
if (!in_array($selectedRoomType, $associatedHotels)) {
|
||||
$newHotels[] = $selectedRoomType;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate list of associations to remove
|
||||
$removedHotels = array();
|
||||
foreach ($associatedHotels as $associatedRoomType) {
|
||||
if (!in_array($associatedRoomType, $selectedHotel)) {
|
||||
$removedHotels[] = $associatedRoomType;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove associations
|
||||
foreach ($removedHotels as $removedHotel) {
|
||||
RoomTypeServiceProduct::deleteRoomProductLink(
|
||||
$product->id,
|
||||
RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL,
|
||||
$removedHotel
|
||||
);
|
||||
}
|
||||
|
||||
// Save new associations
|
||||
if ($newHotels) {
|
||||
$objRoomTypeServiceProduct->addRoomProductLink(
|
||||
$product->id,
|
||||
$newHotels,
|
||||
RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL
|
||||
);
|
||||
}
|
||||
} else {
|
||||
RoomTypeServiceProduct::deleteRoomProductLink(
|
||||
$product->id,
|
||||
RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE
|
||||
);
|
||||
} elseif (Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE == $product->selling_preference_type) {
|
||||
// Add room types linking
|
||||
$associatedRoomTypes = $allAssociations['room_type'];
|
||||
$selectedRoomTypes = Tools::getValue('RT_tree_room_type_box', array());
|
||||
// Generate list of new associations
|
||||
$newRoomTypes = array();
|
||||
foreach ($selectedRoomTypes as $selectedRoomType) {
|
||||
if (!in_array($selectedRoomType, $associatedRoomTypes)) {
|
||||
$newRoomTypes[] = $selectedRoomType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate list of associations to remove
|
||||
$removedRoomTypes = array();
|
||||
foreach ($associatedRoomTypes as $associatedRoomType) {
|
||||
if (!in_array($associatedRoomType, $selectedRoomTypes)) {
|
||||
$removedRoomTypes[] = $associatedRoomType;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove old associations
|
||||
foreach ($removedRoomTypes as $removedRoomType) {
|
||||
RoomTypeServiceProduct::deleteRoomProductLink(
|
||||
$product->id,
|
||||
RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE,
|
||||
$removedRoomType
|
||||
);
|
||||
}
|
||||
|
||||
// Save new associations
|
||||
if ($newRoomTypes) {
|
||||
$objRoomTypeServiceProduct->addRoomProductLink(
|
||||
$product->id,
|
||||
$newRoomTypes,
|
||||
RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE
|
||||
);
|
||||
}
|
||||
|
||||
// Add hotels linking
|
||||
if (Product::isSellableWithHotel($product->id)) {
|
||||
$associatedHotels = $allAssociations['hotel'];
|
||||
$selectedHotel = Tools::getValue('hotel_box', array());
|
||||
// Generate list of new associations
|
||||
@@ -3150,7 +3124,7 @@ class AdminNormalProductsControllerCore extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
// Remove old associations
|
||||
// Remove associations
|
||||
foreach ($removedHotels as $removedHotel) {
|
||||
RoomTypeServiceProduct::deleteRoomProductLink(
|
||||
$product->id,
|
||||
@@ -3168,11 +3142,17 @@ class AdminNormalProductsControllerCore extends AdminController
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Remove associations
|
||||
RoomTypeServiceProduct::deleteRoomProductLink(
|
||||
$product->id
|
||||
$product->id,
|
||||
RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL
|
||||
);
|
||||
}
|
||||
|
||||
if (!Product::isSellableWithRoomType($product->id)
|
||||
&& !Product::isSellableWithHotel($product->id)
|
||||
) {
|
||||
RoomTypeServiceProduct::deleteRoomProductLink($product->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@ class AdminOrderPreferencesControllerCore extends AdminController
|
||||
),
|
||||
array(
|
||||
'value' => Product::STANDARD_PRODUCT_ADDRESS_PREFERENCE_HOTEL,
|
||||
'name' => $this->l('Hotel Address')
|
||||
'name' => $this->l('Property Address')
|
||||
),
|
||||
array(
|
||||
'value' => Product::STANDARD_PRODUCT_ADDRESS_PREFERENCE_CUSTOM,
|
||||
@@ -374,8 +374,8 @@ class AdminOrderPreferencesControllerCore extends AdminController
|
||||
'identifier' => 'value',
|
||||
'js' => "changeStandardProductAddressType()",
|
||||
'hint' => $this->l('Select address for standard product tax calculation, this will be used to calculate the tax for the standard product price.'),
|
||||
'desc' => $this->l('The selected address will be used to calculate tax for standard products. To change the hotel address, update the "Primary Hotel" in the').
|
||||
'<a href="'.$this->context->link->getAdminLink('AdminHotelGeneralSettings').'"> '.$this->l('Hotel General Configuration.').'</a>'
|
||||
'desc' => $this->l('The selected address will be used to calculate tax for standard products. To change the property address, update the "Primary Property" in the').
|
||||
'<a href="'.$this->context->link->getAdminLink('AdminHotelGeneralSettings').'"> '.$this->l('Property General Configuration.').'</a>'
|
||||
),
|
||||
'PS_STANDARD_PRODUCT_ORDER_ADDRESS' => array(
|
||||
'title' => $this->l('Custom address for tax calculation'),
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -179,7 +179,7 @@ class AdminPPreferencesControllerCore extends AdminController
|
||||
),
|
||||
'PS_BACKOFFICE_ROOM_BOOKING_TYPE' => array(
|
||||
'title' => $this->l('In back-office, add rooms to cart with'),
|
||||
'hint' => $this->l('In Room occupancy, while adding rooms in cart customer has to select per room occupancy and in room quantity customer only has to select number of rooms.'),
|
||||
'hint' => $this->l('In Room occupancy, while adding room in cart customer has to select per room occupancy and in rooms quantity customer only has to select number of rooms.'),
|
||||
'cast' => 'intval',
|
||||
'type' => 'select',
|
||||
'list' => array(
|
||||
@@ -437,14 +437,6 @@ class AdminPPreferencesControllerCore extends AdminController
|
||||
Db::getInstance()->execute($sql);
|
||||
}
|
||||
|
||||
if (Tools::getValue('PS_FRONT_SEARCH_TYPE') == HotelBookingDetail::SEARCH_TYPE_OWS) {
|
||||
$_POST['PS_FRONT_ROOM_UNIT_SELECTION_TYPE'] = HotelBookingDetail::PS_ROOM_UNIT_SELECTION_TYPE_OCCUPANCY;
|
||||
}
|
||||
|
||||
if (Tools::getValue('PS_BACKOFFICE_SEARCH_TYPE') == HotelBookingDetail::SEARCH_TYPE_OWS) {
|
||||
$_POST['PS_BACKOFFICE_ROOM_BOOKING_TYPE'] = HotelBookingDetail::PS_ROOM_UNIT_SELECTION_TYPE_OCCUPANCY;
|
||||
}
|
||||
|
||||
if (Tools::getIsset('PS_CATALOG_MODE')) {
|
||||
Tools::clearSmartyCache();
|
||||
Media::clearCache();
|
||||
|
||||
@@ -289,7 +289,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
}
|
||||
|
||||
$this->fields_list['hotel_name'] = array(
|
||||
'title' => $this->l('Hotel'),
|
||||
'title' => $this->l('Property'),
|
||||
'type' => 'select',
|
||||
'multiple' => true,
|
||||
'operator' => 'or',
|
||||
@@ -414,9 +414,12 @@ class AdminProductsControllerCore extends AdminController
|
||||
);
|
||||
|
||||
$objProduct = new Product();
|
||||
$hotelServiceProducts = $objProduct->getServiceProducts(null, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE);
|
||||
$roomTypeServiceProducts = $objProduct->getServiceProducts(null, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE);
|
||||
$allServiceProducts = array_merge($roomTypeServiceProducts, $hotelServiceProducts);
|
||||
$allServiceProducts = array_values(array_filter(
|
||||
$objProduct->getServiceProducts(null),
|
||||
function ($serviceProduct) {
|
||||
return Product::isSellableWithRoomType($serviceProduct['id_product']);
|
||||
}
|
||||
));
|
||||
$serviceProducts = array();
|
||||
foreach ($allServiceProducts as $serviceProduct) {
|
||||
$serviceProducts[$serviceProduct['id_product']] = $serviceProduct['name'];
|
||||
@@ -2201,6 +2204,8 @@ class AdminProductsControllerCore extends AdminController
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assignRoomType($object);
|
||||
|
||||
// update position in category
|
||||
$object->setPositionInCategory(Tools::getValue('category_position'));
|
||||
|
||||
@@ -2365,6 +2370,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
$saveShort = Tools::getValue('description_short');
|
||||
$_POST['description_short'] = strip_tags(Tools::getValue('description_short'));
|
||||
}
|
||||
$_POST['id_selling_object'] = Tools::getValue('id_selling_object') ?? 0;
|
||||
|
||||
// Check description short size without html
|
||||
$limit = (int)Configuration::get('PS_SHORT_DESC_LIMIT');
|
||||
@@ -3131,8 +3137,12 @@ class AdminProductsControllerCore extends AdminController
|
||||
if (Validate::isLoadedObject($product)) {
|
||||
if ($id_hotel = Tools::getValue('id_hotel')) {
|
||||
$objRoomType = new HotelRoomType();
|
||||
if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($product->id)) {
|
||||
$objRoomType = new HotelRoomType((int)$roomTypeInfo['id']);
|
||||
}
|
||||
$objRoomType->id_product = $product->id;
|
||||
$objRoomType->id_hotel = $id_hotel;
|
||||
$objRoomType->id_selling_object = (int)$product->id_selling_object;
|
||||
$objRoomType->save();
|
||||
}
|
||||
}
|
||||
@@ -3243,9 +3253,12 @@ class AdminProductsControllerCore extends AdminController
|
||||
|
||||
$objRoomType = new HotelRoomType();
|
||||
if ($hotelRoomType = $objRoomType->getRoomTypeInfoByIdProduct($obj->id)) {
|
||||
$hotelServiceProducts = $obj->getServiceProducts(null, Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE);
|
||||
$roomTypeServiceProducts = $obj->getServiceProducts(null, Product::SELLING_PREFERENCE_WITH_ROOM_TYPE);
|
||||
$allServiceProducts = array_merge($roomTypeServiceProducts, $hotelServiceProducts);
|
||||
$allServiceProducts = array_values(array_filter(
|
||||
$obj->getServiceProducts(null),
|
||||
function ($serviceProduct) {
|
||||
return Product::isSellableWithRoomType($serviceProduct['id_product']);
|
||||
}
|
||||
));
|
||||
|
||||
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
|
||||
$objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice();
|
||||
@@ -4507,6 +4520,12 @@ class AdminProductsControllerCore extends AdminController
|
||||
$data->assign('htl_full_info', $hotelFullInfo);
|
||||
}
|
||||
|
||||
$roomTypeSellingObjects = RoomTypeSellingObject::getRoomTypeSellingObjects($this->context->language->id);
|
||||
$data->assign('selling_object_info', $roomTypeSellingObjects);
|
||||
if (!empty($product->id_selling_object)) {
|
||||
$data->assign('selected_room_type_selling_object', $product->id_selling_object);
|
||||
}
|
||||
|
||||
$this->tpl_form_vars['product'] = $product;
|
||||
$this->tpl_form_vars['custom_form'] = $data->fetch();
|
||||
}
|
||||
@@ -5511,15 +5530,15 @@ class AdminProductsControllerCore extends AdminController
|
||||
if (!empty($roomNumber = trim(Tools::getValue('num')))
|
||||
&& !Validate::isUnsignedInt($roomNumber)
|
||||
) {
|
||||
$this->errors[] = Tools::displayError('Invalid Starting Room No.');
|
||||
$this->errors[] = sprintf(Tools::displayError('Invalid Starting %s No.') , $roomTypeInfo['selling_object_name']);
|
||||
}
|
||||
|
||||
if (!($roomQuantity = Tools::getValue('qty'))) {
|
||||
$this->errors[] = Tools::displayError('Number of rooms is required.');
|
||||
$this->errors[] = sprintf(Tools::displayError('Number of %s is required.') ,$roomTypeInfo['selling_object_name']);
|
||||
} else if (!Validate::isUnsignedInt($roomQuantity) || $roomQuantity < 1) {
|
||||
$this->errors[] = Tools::displayError('Invalid value for number of rooms.');
|
||||
$this->errors[] = sprintf(Tools::displayError('Invalid value for number of %s.') ,$roomTypeInfo['selling_object_name']);
|
||||
} else if ($roomQuantity > 50) {
|
||||
$this->errors[] = Tools::displayError('You cannot create more than 50 rooms at a time.');
|
||||
$this->errors[] = sprintf(Tools::displayError('You cannot create more than 50 %s at a time.'), $roomTypeInfo['selling_object_name']);
|
||||
}
|
||||
|
||||
if (trim($comment = Tools::getValue('room_comment'))) {
|
||||
@@ -5532,7 +5551,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
$disableDates = Tools::getValue('disable_dates');
|
||||
$roomsInfo['disable_dates_json'] = json_encode($disableDates);
|
||||
if (!$disableDates) {
|
||||
$this->errors[] = Tools::displayError('Please add at least one date range for updating the rooms status to temporary inactive.');
|
||||
$this->errors[] = sprintf(Tools::displayError('Please add at least one date range for updating the %s status to temporary inactive.') , $roomTypeInfo['selling_object_name']);
|
||||
} else {
|
||||
$hasMissingRowError = false;
|
||||
foreach ($disableDates as $key => $dateRange) {
|
||||
|
||||
230
controllers/admin/AdminRoomTypeSellingObjectsController.php
Normal file
230
controllers/admin/AdminRoomTypeSellingObjectsController.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/license/osl-3-0-php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to support@qloapps.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to a newer
|
||||
* versions in the future. If you wish to customize this module for your needs
|
||||
* please refer to https://store.webkul.com/customisation-guidelines for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright Since 2010 Webkul
|
||||
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
|
||||
*/
|
||||
|
||||
class AdminRoomTypeSellingObjectsController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->table = 'room_type_selling_object';
|
||||
$this->className = 'RoomTypeSellingObject';
|
||||
$this->identifier = 'id_room_type_selling_object';
|
||||
$this->lang = true;
|
||||
$this->context = Context::getContext();
|
||||
$this->toolbar_title = $this->l('Room Type Selling Objects');
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->fields_list = array(
|
||||
'id_room_type_selling_object' => array(
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'class' => 'fixed-width-xs',
|
||||
),
|
||||
'name' => array(
|
||||
'title' => $this->l('Name'),
|
||||
'align' => 'left',
|
||||
),
|
||||
'plural_name' => array(
|
||||
'title' => $this->l('Plural Name'),
|
||||
'align' => 'left',
|
||||
),
|
||||
'active' => array(
|
||||
'title' => $this->l('Status'),
|
||||
'align' => 'center',
|
||||
'active' => 'status',
|
||||
'type' => 'bool',
|
||||
'orderby' => false,
|
||||
),
|
||||
);
|
||||
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('delete');
|
||||
$this->bulk_actions = array(
|
||||
'delete' => array(
|
||||
'text' => $this->l('Delete selected'),
|
||||
'confirm' => $this->l('Delete selected items?'),
|
||||
'icon' => 'icon-trash',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function initPageHeaderToolbar()
|
||||
{
|
||||
if (!$this->display || $this->display == 'list') {
|
||||
$this->page_header_toolbar_btn['new_room_selling_type'] = array(
|
||||
'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token,
|
||||
'desc' => $this->l('Add new Selling Object', null, null, false),
|
||||
'icon' => 'process-icon-new',
|
||||
);
|
||||
}
|
||||
|
||||
parent::initPageHeaderToolbar();
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
if (!$this->loadObject(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Room Type Selling Object'),
|
||||
'icon' => 'icon-tags',
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Name'),
|
||||
'name' => 'name',
|
||||
'lang' => true,
|
||||
'required' => true,
|
||||
'hint' => $this->l('Displayed name for this room type selling object.'),
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Plural Name'),
|
||||
'name' => 'plural_name',
|
||||
'lang' => true,
|
||||
'required' => true,
|
||||
'hint' => $this->l('Displayed name when more than one is booked.'),
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Enabled'),
|
||||
'name' => 'active',
|
||||
'is_bool' => true,
|
||||
'default_value' => 1,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled'),
|
||||
),
|
||||
array(
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
),
|
||||
'buttons' => array(
|
||||
'save-and-stay' => array(
|
||||
'title' => $this->l('Save and stay'),
|
||||
'name' => 'submitAdd'.$this->table.'AndStay',
|
||||
'type' => 'submit',
|
||||
'class' => 'btn btn-default pull-right',
|
||||
'icon' => 'process-icon-save',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return parent::renderForm();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::isSubmit('submitAdd'.$this->table) || Tools::isSubmit('submitAdd'.$this->table.'AndStay')) {
|
||||
$languages = Language::getLanguages(false);
|
||||
$defaultLangId = Configuration::get('PS_LANG_DEFAULT');
|
||||
$objDefaultLanguage = Language::getLanguage((int) $defaultLangId);
|
||||
$idSellingObject = Tools::getValue($this->identifier);
|
||||
|
||||
if (!trim(Tools::getValue('name_'.$defaultLangId))) {
|
||||
$this->errors[] = $this->l('Name is required at least in ').$objDefaultLanguage['name'];
|
||||
} else {
|
||||
foreach ($languages as $lang) {
|
||||
if (trim(Tools::getValue('name_'.$lang['id_lang']))) {
|
||||
if (!Validate::isGenericName(Tools::getValue('name_'.$lang['id_lang']))) {
|
||||
$this->errors[] = $this->l('Invalid Name in ').$lang['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!trim(Tools::getValue('plural_name_'.$defaultLangId))) {
|
||||
$this->errors[] = $this->l('Plural Name is required at least in ').$objDefaultLanguage['name'];
|
||||
} else {
|
||||
foreach ($languages as $lang) {
|
||||
if (trim(Tools::getValue('plural_name_'.$lang['id_lang']))) {
|
||||
if (!Validate::isGenericName(Tools::getValue('plural_name_'.$lang['id_lang']))) {
|
||||
$this->errors[] = $this->l('Invalid Plural Name in ').$lang['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->display = $idSellingObject ? 'edit' : 'add';
|
||||
|
||||
if (!$this->errors) {
|
||||
parent::postProcess();
|
||||
}
|
||||
} else {
|
||||
parent::postProcess();
|
||||
}
|
||||
}
|
||||
|
||||
public function processDelete()
|
||||
{
|
||||
$object = $this->loadObject();
|
||||
if (!$this->checkDeletion($object)) {
|
||||
return false;
|
||||
}
|
||||
return parent::processDelete();
|
||||
}
|
||||
|
||||
protected function processBulkDelete()
|
||||
{
|
||||
if (is_array($this->boxes) && !empty($this->boxes)) {
|
||||
foreach ($this->boxes as $idSellingObject) {
|
||||
$object = new RoomTypeSellingObject((int) $idSellingObject);
|
||||
if (!$this->checkDeletion($object)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent::processBulkDelete();
|
||||
}
|
||||
|
||||
protected function checkDeletion($object)
|
||||
{
|
||||
if (Validate::isLoadedObject($object)) {
|
||||
if ($object->isUsed()) {
|
||||
$this->errors[] = $this->l('You cannot delete this room type selling object because it is currently assigned to one or more room types.');
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('An error occurred while deleting the object.').'
|
||||
<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1118,7 +1118,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
date('Y-m-d'),
|
||||
date('Y-m-d', strtotime('+1 day')),
|
||||
$idHotels,
|
||||
HotelBookingDetail::STATUS_ALLOTED
|
||||
HotelBookingDetail::STATUS_ASSIGNED
|
||||
);
|
||||
|
||||
break;
|
||||
@@ -1279,7 +1279,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
$totalArrivals = Db::getInstance()->getValue(
|
||||
'SELECT COUNT(hbd.`id_room`)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0
|
||||
AND hbd.`date_from` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"'.
|
||||
HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
);
|
||||
@@ -1287,7 +1287,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
$arrived = Db::getInstance()->getValue(
|
||||
'SELECT COUNT(hbd.`id_room`)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0
|
||||
AND hbd.`date_from` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"
|
||||
AND hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN.
|
||||
HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
@@ -1301,7 +1301,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
$totalDepartures = Db::getInstance()->getValue(
|
||||
'SELECT COUNT(hbd.`id_room`)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`is_refunded` = 0
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND ((hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN.') OR
|
||||
(hbd.`check_in` != "0000:00:00 00:00:00" AND hbd.`check_out` != "0000:00:00 00:00:00"))
|
||||
AND hbd.`date_to` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"'.
|
||||
@@ -1311,7 +1311,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
$departed = Db::getInstance()->getValue(
|
||||
'SELECT COUNT(hbd.`id_room`)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`is_refunded` = 0
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_to` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"
|
||||
AND hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.'
|
||||
AND hbd.`check_in` != "0000:00:00 00:00:00"'.
|
||||
@@ -1336,7 +1336,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
return Db::getInstance()->getValue(
|
||||
'SELECT COUNT(hbd.`id_room`)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0
|
||||
AND hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN.'
|
||||
AND hbd.`date_to` > "'.pSQL($date).' 00:00:00"'.
|
||||
HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
@@ -1364,21 +1364,22 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
return Db::getInstance()->getRow(
|
||||
'SELECT SUM(hbd.`adults`) AS `adults`, SUM(hbd.`children`) AS `children`
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0
|
||||
AND hbd.`date_from` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"'.
|
||||
HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
);
|
||||
}
|
||||
|
||||
public static function getTotalRooms($idHotel = null, $active = null)
|
||||
public static function getTotalRooms($idHotel = null, $active = null, $idProduct = null)
|
||||
{
|
||||
$sql = 'SELECT COUNT(hri.`id`)
|
||||
FROM `'._DB_PREFIX_.'htl_room_information` hri
|
||||
INNER JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE p.`booking_product` = 1 '.
|
||||
(!is_null($active) ? ' AND p.`active` ='.(int) $active : ' ').
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hri') : '');
|
||||
(!is_null($active) ? ' AND p.`active` = '.(int) $active : '').
|
||||
(!is_null($idProduct) ? ' AND hri.`id_product` = '.(int) $idProduct : '').
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hri') : '');
|
||||
|
||||
return Db::getInstance()->getValue($sql);
|
||||
}
|
||||
@@ -1426,7 +1427,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE p.`active` = 1
|
||||
AND p.`booking_product` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_from` < "'.pSQL($dateTo).'"
|
||||
AND IF(hbd.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_OUT.',
|
||||
DATE_FORMAT(hbd.`check_out`, "%Y-%m-%d"),
|
||||
@@ -1475,7 +1476,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
WHERE hri.`id_status` = '.(int)HotelRoomInformation::STATUS_INACTIVE.'
|
||||
AND p.`active` = 1
|
||||
AND p.`booking_product` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_from` < "'.pSQL($dateTo).'"
|
||||
AND IF(hbd.`id_status` = '.(int)HotelBookingDetail::STATUS_CHECKED_OUT.',
|
||||
DATE_FORMAT(hbd.`check_out`, "%Y-%m-%d"),
|
||||
@@ -1539,7 +1540,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
WHERE hri.`id_status` = '.(int)HotelRoomInformation::STATUS_TEMPORARY_INACTIVE.'
|
||||
AND p.`active` = 1
|
||||
AND p.`booking_product` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hrdd.`date_from` < "'.pSQL($dateTo).'"
|
||||
AND hrdd.`date_to` > "'.pSQL($dateFrom).'"
|
||||
AND hbd.`date_from` < "'.pSQL($dateTo).'"
|
||||
@@ -1636,7 +1637,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
|
||||
$cancelledBookings = Db::getInstance()->getValue(
|
||||
'SELECT COUNT(hbd.`id`) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`is_refunded` = 1 AND hbd.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"'.
|
||||
WHERE hbd.`id` IN ('.OrderReturn::getRefundedBookingIdsSubquery(OrderReturn::EVENT_TYPE_CANCELLATION).') AND hbd.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"'.
|
||||
HotelBranchInformation::addHotelRestriction($idHotel, 'hbd')
|
||||
);
|
||||
|
||||
@@ -1675,7 +1676,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
IF (hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.', IF("'.$dateFrom.'" < check_in, check_in, "'.$dateFrom.'"), IF("'.$dateFrom.'" < date_from, date_from, "'.$dateFrom.'"))
|
||||
)), 0)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0 AND
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0 AND
|
||||
(IF (hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.',
|
||||
(hbd.`check_in` < \''.pSQL($dateTo).'\' AND hbd.`check_out` >= \''.pSQL($dateFrom).'\'),
|
||||
(hbd.`date_from` < \''.pSQL($dateTo).'\' AND hbd.`date_to` >= \''.pSQL($dateFrom).'\')
|
||||
@@ -1708,7 +1709,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = hbd.`id_customer`)
|
||||
WHERE hbd.`is_refunded` = 0 AND hbd.`date_from` = "'.pSQL($date).' 00:00:00"
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_from` = "'.pSQL($date).' 00:00:00"
|
||||
AND hbd.`id_status` != '.(int) HotelBookingDetail::STATUS_CHECKED_IN.'
|
||||
AND hbd.`id_status` != '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
|
||||
@@ -1725,7 +1726,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = hbd.`id_customer`)
|
||||
WHERE hbd.`is_refunded` = 0 AND hbd.`date_to` = "'.pSQL($date).' 00:00:00"
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`date_to` = "'.pSQL($date).' 00:00:00"
|
||||
AND hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
@@ -1741,7 +1742,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = hbd.`id_customer`)
|
||||
WHERE hbd.`is_refunded` = 0
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND (hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN.'
|
||||
OR (hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_OUT.' AND hbd.`check_out` > "'.pSQL(date('Y-m-d')).' 00:00:00"))
|
||||
AND hbd.`date_to` != "'.pSQL(date('Y-m-d')).' 00:00:00"'.
|
||||
@@ -1772,7 +1773,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getCancellationsInfoByDate($date, $idHotel = null)
|
||||
public static function getCancellationsInfoByDate($date, $idHotel = null, $eventType = null)
|
||||
{
|
||||
$sql = 'SELECT orr.`id_order_return`, orr.`id_customer`, hbd.`room_num`, hbd.`id_product`, hbd.`room_type_name`,
|
||||
o.`with_occupancy`, CONCAT(c.`firstname`, " ", c.`lastname`) AS customer_name, hbd.`id_hotel`,
|
||||
@@ -1785,6 +1786,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = orr.`id_customer`)
|
||||
WHERE orr.`date_add` BETWEEN "'.pSQL($date).' 00:00:00" AND "'.pSQL($date).' 23:59:59"
|
||||
AND orr.`state` = '.(int) OrderReturnState::ORDER_RETRUN_FIRST_STATUS.
|
||||
(!is_null($eventType) ? ' AND orr.`event_type` = '.(int) $eventType : '').
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').'
|
||||
GROUP BY ord.`id_htl_booking`
|
||||
ORDER BY orr.`date_add` DESC';
|
||||
@@ -1802,8 +1804,8 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE p.`active` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`is_cancelled` = 0 '.
|
||||
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`id_status` != '.HotelBookingDetail::STATUS_CANCELLED.' '.
|
||||
(($dateFrom && $dateTo) ? ' AND hbd.`date_from` <= "'.pSQL($dateTo).' 00:00:00" AND hbd.`date_to` > "'.pSQL($dateFrom).' 00:00:00" ': ' ').
|
||||
(!is_null($roomBookingStatus) ? ' AND hbd.`id_status` = '.(int) $roomBookingStatus : ' ').
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
|
||||
@@ -1817,7 +1819,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
{
|
||||
$sql = 'SELECT COUNT(hbd.`id_room`)
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`is_refunded` = 0
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_from` <= "'.pSQL($dateTo).' 00:00:00" AND hbd.`date_to` > "'.pSQL($dateFrom).' 00:00:00"'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
|
||||
|
||||
@@ -1854,7 +1856,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE p.`active` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
|
||||
|
||||
@@ -1895,7 +1897,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`)
|
||||
WHERE p.`active` = 1
|
||||
AND o.`valid` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
|
||||
|
||||
@@ -1938,7 +1940,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`)
|
||||
WHERE p.`active` = 1
|
||||
AND o.`valid` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
|
||||
|
||||
@@ -2007,7 +2009,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE p.`active` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').'
|
||||
) AS num_booked,
|
||||
@@ -2087,7 +2089,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
ON (p.`id_product` = hri.`id_product`)
|
||||
WHERE p.`active` = 1'.
|
||||
(!is_null($showAtFront) ? ' AND p.`show_at_front` = '.(int) $showAtFront : '').'
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').'
|
||||
) AS num_booked,
|
||||
@@ -2391,7 +2393,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (od.`id_order` = o.`id_order`)
|
||||
WHERE p.`active` = 1
|
||||
AND o.`valid` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
|
||||
|
||||
@@ -2404,9 +2406,9 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
IFNULL(SUM(
|
||||
CASE
|
||||
WHEN od.`purchase_supplier_price` <> "0.000000"
|
||||
THEN (od.`purchase_supplier_price` / (IF (od.`product_price_calculation_method` = '.Product::PRICE_CALCULATION_METHOD_PER_BOOKING.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1)))
|
||||
THEN (od.`purchase_supplier_price` / (IF (od.`product_price_calculation_method` = '.Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1)))
|
||||
WHEN od.`purchase_supplier_price` = "0.000000"
|
||||
THEN ((od.`original_product_price` / o.`conversion_rate`) * '.(int)Configuration::get('CONF_AVERAGE_PRODUCT_MARGIN').' / 100) / (IF (od.`product_price_calculation_method` = '.Product::PRICE_CALCULATION_METHOD_PER_BOOKING.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1))
|
||||
THEN ((od.`original_product_price` / o.`conversion_rate`) * '.(int)Configuration::get('CONF_AVERAGE_PRODUCT_MARGIN').' / 100) / (IF (od.`product_price_calculation_method` = '.Product::PRICE_CALCULATION_METHOD_CHECKIN_AND_CHECKOUT_AND_DURING_STAY.', DATEDIFF(hbd.`date_to`, hbd.`date_from`), 1))
|
||||
END
|
||||
), 0)
|
||||
FROM `'._DB_PREFIX_.'service_product_order_detail` rtspod
|
||||
@@ -2417,7 +2419,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (od.`id_order` = o.`id_order`)
|
||||
WHERE p.`active` = 1
|
||||
AND o.`valid` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_from` < "'.pSQL($discreteDate['date_to']).' 00:00:00" AND hbd.`date_to` > "'.pSQL($discreteDate['date_from']).' 00:00:00"'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
|
||||
|
||||
@@ -2547,7 +2549,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
FROM (
|
||||
SELECT IF(DATEDIFF(hbd.`date_from`, \''.pSQL($dateFrom).'\') < 0, \''.pSQL($dateFrom).'\', hbd.`date_from`) AS date_from_final, IF(DATEDIFF(\''.pSQL($dateTo).'\', hbd.`date_to`) < 0, \''.pSQL($dateToNext).'\', hbd.`date_to`) AS date_to_final
|
||||
FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`is_refunded` = 0
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_from` <= \''.pSQL($dateTo).'\' AND hbd.`date_to` > \''.pSQL($dateFrom).'\''.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').'
|
||||
) AS t
|
||||
@@ -2626,7 +2628,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hbd.`id_product`)
|
||||
WHERE p.`active` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_from` <= "'.pSQL($dateTo).' 00:00:00" AND hbd.`date_to` > "'.pSQL($dateFrom).' 00:00:00"'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '');
|
||||
|
||||
@@ -2639,7 +2641,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (p.`id_product` = hbd.`id_product`)
|
||||
WHERE p.`active` = 1
|
||||
AND hbd.`is_refunded` = 0
|
||||
AND hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().')
|
||||
AND hbd.`date_from` <= "'.pSQL($dateTo).' 00:00:00" AND hbd.`date_to` > "'.pSQL($dateFrom).' 00:00:00"'.
|
||||
(!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : '').'
|
||||
) AS t
|
||||
@@ -2739,7 +2741,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
public static function getAverageLeadTime($dateFrom = '', $dateTo = '', $idHotel = false)
|
||||
{
|
||||
$sql = 'SELECT (SUM(DATEDIFF(hbd.`date_from`, hbd.`date_add`)) / COUNT(hbd.`id`)) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0'
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0'
|
||||
.(($dateFrom && $dateTo) ? ' AND hbd.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"' : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd');
|
||||
|
||||
@@ -2757,7 +2759,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
public static function getAverageGuestsPerBooking($dateFrom = '', $dateTo = '', $idHotel = false)
|
||||
{
|
||||
$sql = 'SELECT (SUM(hbd.`adults`) / COUNT(hbd.`id`)) as avg_adults, (SUM(hbd.`children`) / COUNT(hbd.`id`)) as avg_children FROM `'._DB_PREFIX_.'htl_booking_detail` hbd
|
||||
WHERE hbd.`is_refunded` = 0 AND hbd.`is_back_order` = 0'
|
||||
WHERE hbd.`id` NOT IN ('.OrderReturn::getRefundedBookingIdsSubquery().') AND hbd.`is_back_order` = 0'
|
||||
.(($dateFrom && $dateTo) ? ' AND hbd.`date_add` BETWEEN "'.pSQL($dateFrom).' 00:00:00" AND "'.pSQL($dateTo).' 23:59:59"' : '')
|
||||
.HotelBranchInformation::addHotelRestriction($idHotel, 'hbd');
|
||||
|
||||
|
||||
@@ -104,6 +104,7 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor
|
||||
$action .= ($module ? '&module='.Tools::safeOutput($module) : '');
|
||||
$action .= (($id_product = Tools::getValue('id_product')) ? '&id_product='.Tools::safeOutput($id_product) : '');
|
||||
$action .= (($id_hotel = Tools::getValue('id_hotel')) ? '&id_hotel='.Tools::safeOutput($id_hotel) : '');
|
||||
$action .= (($tab = Tools::getValue('tab')) ? '&tab='.Tools::safeOutput($tab) : '');
|
||||
$tpl->assign(array(
|
||||
'current' => self::$currentIndex,
|
||||
'token' => $token,
|
||||
@@ -150,34 +151,74 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor
|
||||
$tpl = $this->createTemplate('menu.tpl');
|
||||
|
||||
$modules = $this->getModules();
|
||||
$module_instance = array();
|
||||
foreach ($modules as $m => $module) {
|
||||
if ($module_instance[$module['name']] = Module::getInstanceByName($module['name'])) {
|
||||
$modules[$m]['displayName'] = $module_instance[$module['name']]->displayName;
|
||||
} else {
|
||||
unset($module_instance[$module['name']]);
|
||||
unset($modules[$m]);
|
||||
|
||||
$statsTabs = array();
|
||||
foreach ($modules as $module) {
|
||||
if ($moduleObj = Module::getInstanceByName($module['name'])) {
|
||||
$statsTabs[$module['name']] = array(
|
||||
'display_name' => $moduleObj->displayName,
|
||||
'position' => property_exists($moduleObj, 'stats_position') ? (int)$moduleObj->stats_position : null,
|
||||
);
|
||||
if (method_exists($moduleObj, 'getStatsTabs')) {
|
||||
$statsTabs[$module['name']]['tabs'] = $moduleObj->getStatsTabs();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uasort($modules, array($this, 'checkModulesNames'));
|
||||
$positionedModules = array_filter($statsTabs, fn($d) => $d['position'] !== null);
|
||||
$defaultModules = array_filter($statsTabs, fn($d) => $d['position'] === null);
|
||||
|
||||
$modulesBySlot = [];
|
||||
foreach ($positionedModules as $name => $data) {
|
||||
$modulesBySlot[$data['position']][$name] = $data;
|
||||
}
|
||||
ksort($modulesBySlot);
|
||||
|
||||
$defaultKeys = array_keys($defaultModules);
|
||||
$defaultCount = count($defaultKeys);
|
||||
$statsTabs = [];
|
||||
$defaultModulesIndex = 0;
|
||||
$positionedModulesCount = 0;
|
||||
|
||||
foreach ($modulesBySlot as $slot => $group) {
|
||||
$defaultsBefore = max(0, $slot - 1 - $positionedModulesCount);
|
||||
while ($defaultModulesIndex < $defaultsBefore && $defaultModulesIndex < $defaultCount) {
|
||||
$key = $defaultKeys[$defaultModulesIndex++];
|
||||
$statsTabs[$key] = $defaultModules[$key];
|
||||
}
|
||||
foreach ($group as $name => $data) {
|
||||
$statsTabs[$name] = $data;
|
||||
$positionedModulesCount++;
|
||||
}
|
||||
}
|
||||
|
||||
while ($defaultModulesIndex < $defaultCount) {
|
||||
$key = $defaultKeys[$defaultModulesIndex++];
|
||||
$statsTabs[$key] = $defaultModules[$key];
|
||||
}
|
||||
|
||||
Hook::exec('actionStatsTabsModifier', array(
|
||||
'stats_tabs' => &$statsTabs
|
||||
));
|
||||
|
||||
$currentModuleName = Tools::getValue('module') ?: array_key_first($statsTabs);
|
||||
$currentTab = Tools::getValue('tab', '');
|
||||
if (!$currentTab && isset($statsTabs[$currentModuleName]['tabs'])) {
|
||||
$firstTab = reset($statsTabs[$currentModuleName]['tabs']);
|
||||
$currentTab = $firstTab['key'];
|
||||
}
|
||||
|
||||
$tpl->assign(array(
|
||||
'current' => self::$currentIndex,
|
||||
'current_module_name' => Tools::getValue('module', 'statsforecast'),
|
||||
'current_module_name' => $currentModuleName,
|
||||
'current_tab' => $currentTab,
|
||||
'token' => $this->token,
|
||||
'modules' => $modules,
|
||||
'module_instance' => $module_instance
|
||||
'module_tabs' => $statsTabs,
|
||||
));
|
||||
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
public function checkModulesNames($a, $b)
|
||||
{
|
||||
return ($a['displayName'] > $b['displayName']) ? 1 : 0;
|
||||
}
|
||||
|
||||
protected function getModules()
|
||||
{
|
||||
$sql = 'SELECT h.`name` AS hook, m.`name`
|
||||
@@ -191,12 +232,30 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
protected function getDefaultModuleName()
|
||||
{
|
||||
$modules = $this->getModules();
|
||||
if (empty($modules)) {
|
||||
return '';
|
||||
}
|
||||
$sorted = [];
|
||||
foreach ($modules as $mod) {
|
||||
$instance = Module::getInstanceByName($mod['name']);
|
||||
$pos = ($instance && property_exists($instance, 'stats_position'))
|
||||
? (int) $instance->stats_position
|
||||
: PHP_INT_MAX;
|
||||
$sorted[] = ['name' => $mod['name'], 'pos' => $pos];
|
||||
}
|
||||
usort($sorted, fn($a, $b) => $a['pos'] <=> $b['pos']);
|
||||
return $sorted[0]['name'];
|
||||
}
|
||||
|
||||
public function displayStats()
|
||||
{
|
||||
$tpl = $this->createTemplate('stats.tpl');
|
||||
|
||||
if ((!($module_name = Tools::getValue('module')) || !Validate::isModuleName($module_name)) && ($module_instance = Module::getInstanceByName('statsforecast')) && $module_instance->active) {
|
||||
$module_name = 'statsforecast';
|
||||
if (!($module_name = Tools::getValue('module')) || !Validate::isModuleName($module_name)) {
|
||||
$module_name = $this->getDefaultModuleName();
|
||||
}
|
||||
|
||||
if ($module_name) {
|
||||
@@ -311,4 +370,4 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor
|
||||
$day = isset($this->context->cookie->stats_day) ? sprintf('%02d', $this->context->cookie->stats_day) : '%';
|
||||
return $year.'-'.$month.'-'.$day;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user