From 04b7abc59868474f2c189714c26bc305c7b1e2ed Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 21 Feb 2024 17:44:41 +0530 Subject: [PATCH] Fix values issues --- .../default/template/helpers/kpi/row.tpl | 2 +- classes/helper/HelperKpiRow.php | 4 +++ controllers/admin/AdminProductsController.php | 8 +++-- controllers/admin/AdminStatsController.php | 35 ++++++++++++------- js/admin.js | 7 ++++ 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/admin/themes/default/template/helpers/kpi/row.tpl b/admin/themes/default/template/helpers/kpi/row.tpl index bbf952336..50090b691 100644 --- a/admin/themes/default/template/helpers/kpi/row.tpl +++ b/admin/themes/default/template/helpers/kpi/row.tpl @@ -48,7 +48,7 @@ {foreach from=$kpis item=kpi}
  • diff --git a/classes/helper/HelperKpiRow.php b/classes/helper/HelperKpiRow.php index b6daea61a..f47022bf7 100644 --- a/classes/helper/HelperKpiRow.php +++ b/classes/helper/HelperKpiRow.php @@ -37,6 +37,7 @@ class HelperKpiRowCore extends Helper $this->tpl = $this->createTemplate($this->base_tpl); // set visiblity for each KPI + $countVisible = 0; $cookieKeyPrefix = 'kpi_visibility_'.$this->context->controller->className.'_'; foreach ($this->kpis as &$kpi) { $cookieKey = $cookieKeyPrefix.$kpi->id; @@ -45,6 +46,8 @@ class HelperKpiRowCore extends Helper } else { $kpi->visible = true; } + + $countVisible = $kpi->visible ? ++$countVisible : $countVisible; } $cookieKeyView = 'kpi_wrapping_'.$this->context->controller->className; @@ -52,6 +55,7 @@ class HelperKpiRowCore extends Helper $this->tpl->assign('kpis', $this->kpis); $this->tpl->assign('refresh', $this->refresh); $this->tpl->assign('no_wrapping', (int) $this->context->cookie->$cookieKeyView); + $this->tpl->assign('count_visible', $countVisible); return $this->tpl->fetch(); } diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 5ddd8cb31..8f7b2c759 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -2330,6 +2330,7 @@ class AdminProductsControllerCore extends AdminController $helper->icon = 'icon-bed'; $helper->color = 'color3'; $helper->title = $this->l('Total Rooms', null, null, false); + $helper->subtitle = $this->l('Today', null, null, false); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_rooms'; $helper->tooltip = $this->l('The total number of rooms in all hotels.', null, null, false); $kpis[] = $helper; @@ -2339,8 +2340,9 @@ class AdminProductsControllerCore extends AdminController $helper->icon = 'icon-globe'; $helper->color = 'color4'; $helper->title = $this->l('Total Online Bookable Rooms', null, null, false); + $helper->subtitle = $this->l('Today', null, null, false); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_online_bookable_rooms'; - $helper->tooltip = $this->l('The total number of rooms that can be booked using website.', null, null, false); + $helper->tooltip = $this->l('The total number of rooms that can be booked only using website.', null, null, false); $kpis[] = $helper; $helper = new HelperKpi(); @@ -2348,8 +2350,9 @@ class AdminProductsControllerCore extends AdminController $helper->icon = 'icon-building'; $helper->color = 'color1'; $helper->title = $this->l('Total Offline Bookable Rooms', null, null, false); + $helper->subtitle = $this->l('Today', null, null, false); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_offline_bookable_rooms'; - $helper->tooltip = $this->l('The number of rooms that can be booked through offline channels (e.g., phone or in-person).', null, null, false); + $helper->tooltip = $this->l('The number of rooms that can be booked either through website or offline channels (e.g., phone or in-person).', null, null, false); $kpis[] = $helper; $helper = new HelperKpi(); @@ -2387,6 +2390,7 @@ class AdminProductsControllerCore extends AdminController $helper->icon = 'icon-ban'; $helper->color = 'color2'; $helper->title = $this->l('Total Disabled Rooms', null, null, false); + $helper->subtitle = $this->l('Today', null, null, false); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_disabled_rooms'; $helper->tooltip = $this->l('The number of rooms that are currently disabled.', null, null, false); $kpis[] = $helper; diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index d47812a4f..183562589 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -662,11 +662,7 @@ class AdminStatsControllerCore extends AdminStatsTabController break; case 'disabled_room_types': - if (AdminStatsController::getTotalRoomTypes()) { - $value = round(100 * AdminStatsController::getDisabledRoomTypes(0) / AdminStatsController::getTotalRoomTypes(0), 2).'%'; - } else { - $value = '0%'; - } + $value = AdminStatsController::getDisabledRoomTypes(0); ConfigurationKPI::updateValue('DISABLED_ROOM_TYPES', $value); ConfigurationKPI::updateValue('DISABLED_ROOM_TYPES_EXPIRE', strtotime('+2 hour')); break; @@ -833,12 +829,14 @@ class AdminStatsControllerCore extends AdminStatsTabController break; case 'total_online_bookable_rooms': - $value = AdminStatsController::getTotalRooms(0, 1); + $value = AdminStatsController::getAvailableRoomsForDiscreteDates(date('Y-m-d'), null, 0, 1); + $value = $value[strtotime(date('Y-m-d'))]; break; case 'total_offline_bookable_rooms': - $value = AdminStatsController::getTotalRooms(0, 0); + $value = AdminStatsController::getAvailableRoomsForDiscreteDates(date('Y-m-d')); + $value = $value[strtotime(date('Y-m-d'))]; break; @@ -1035,14 +1033,13 @@ class AdminStatsControllerCore extends AdminStatsTabController ); } - public static function getTotalRooms($idHotel = null, $showAtFront = null) + public static function getTotalRooms($idHotel = 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($showAtFront) ? ' AND p.`show_at_front` = '.(int) $showAtFront : ''). (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hri') : ''); return Db::getInstance()->getValue($sql); @@ -1579,7 +1576,7 @@ class AdminStatsControllerCore extends AdminStatsTabController /** * total available (unoccupied) for each date */ - public static function getAvailableRoomsForDiscreteDates($dateFrom, $dateTo = null, $idHotel = null, $useCache = true) + public static function getAvailableRoomsForDiscreteDates($dateFrom, $dateTo = null, $idHotel = null, $showAtFront = null, $useCache = true) { $dateTo = !$dateTo ? date('Y-m-d', strtotime('+1 day', strtotime($dateFrom))) : $dateTo; $discreteDates = array(); @@ -1597,7 +1594,7 @@ class AdminStatsControllerCore extends AdminStatsTabController $result = array(); foreach ($discreteDates as $discreteDate) { $cacheKey = 'AdminStats::getAvailableRoomsForDiscreteDates'.'_'.(int) $discreteDate['timestamp_from'].'_'. - (!is_array($idHotel) ? (int) $idHotel : implode('_', $idHotel)); + (is_null($showAtFront) ? 'null_' : (int) $showAtFront).(!is_array($idHotel) ? (int) $idHotel : implode('_', $idHotel)); if (!Cache::isStored($cacheKey) || !$useCache) { $sql = 'SELECT (num_total - num_booked - num_inactive - num_temporarily_inactive) AS num_available FROM ( @@ -1607,6 +1604,7 @@ class AdminStatsControllerCore extends AdminStatsTabController LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hri.`id_product`) WHERE p.`active` = 1'. + (!is_null($showAtFront) ? ' AND p.`show_at_front` = '.(int) $showAtFront : ''). (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hri') : '').' ) AS num_total, ( @@ -1616,7 +1614,8 @@ class AdminStatsControllerCore extends AdminStatsTabController ON (hri.`id` = hbd.`id_room`) LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = hri.`id_product`) - WHERE p.`active` = 1 + WHERE p.`active` = 1'. + (!is_null($showAtFront) ? ' AND p.`show_at_front` = '.(int) $showAtFront : '').' AND hbd.`is_refunded` = 0 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') : '').' @@ -1628,6 +1627,7 @@ class AdminStatsControllerCore extends AdminStatsTabController ON (p.`id_product` = hri.`id_product`) WHERE hri.`id_status` = '.(int) HotelRoomInformation::STATUS_INACTIVE.' AND p.`active` = 1'. + (!is_null($showAtFront) ? ' AND p.`show_at_front` = '.(int) $showAtFront : ''). (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hri') : '').' ) AS num_inactive, ( @@ -1640,6 +1640,7 @@ class AdminStatsControllerCore extends AdminStatsTabController WHERE hri.`id_status` = '.(int) HotelRoomInformation::STATUS_TEMPORARY_INACTIVE.' AND ("'.pSQL($discreteDate['date_from']).'" >= hrdd.`date_from` AND "'.pSQL($discreteDate['date_from']).'" < hrdd.`date_to`) AND p.`active` = 1'. + (!is_null($showAtFront) ? ' AND p.`show_at_front` = '.(int) $showAtFront : ''). (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hri') : '').' ) AS num_temporarily_inactive ) AS t'; @@ -1674,9 +1675,17 @@ class AdminStatsControllerCore extends AdminStatsTabController $cacheKey = 'AdminStats::getDisabledRoomsForDiscreteDates'.'_'.(int) $discreteDate['timestamp_from'].'_'. (!is_array($idHotel) ? (int) $idHotel : implode('_', $idHotel)); if (!Cache::isStored($cacheKey) || !$useCache) { - $sql = 'SELECT (num_inactive + num_temporarily_inactive) AS num_disabled + $sql = 'SELECT (num_room_type_disabled + num_inactive + num_temporarily_inactive) AS num_disabled FROM ( SELECT ( + SELECT IFNULL(COUNT(hri.`id`), 0) + FROM `'._DB_PREFIX_.'htl_room_information` hri + LEFT JOIN `'._DB_PREFIX_.'product` p + ON (p.`id_product` = hri.`id_product`) + WHERE p.`active` = 0'. + (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hri') : '').' + ) AS num_room_type_disabled, + ( SELECT IFNULL(COUNT(hri.`id`), 0) FROM `'._DB_PREFIX_.'htl_room_information` hri LEFT JOIN `'._DB_PREFIX_.'product` p diff --git a/js/admin.js b/js/admin.js index 0baafed50..8b2f8f047 100644 --- a/js/admin.js +++ b/js/admin.js @@ -1573,6 +1573,13 @@ $(document).on('change', '.kpi-container .kpi-display-toggle', function (e) { is_visible: isVisible, } }); + + // at least one KPI must be displayed + if ($(kpiCheckbox).closest('.actions-wrap').find('.kpi-display-toggle:checked').length == 1) { + $(kpiCheckbox).closest('.actions-wrap').find('.kpi-display-toggle:checked').attr('disabled', true); + } else { + $(kpiCheckbox).closest('.actions-wrap').find('.kpi-display-toggle').attr('disabled', false); + } }); // prevent dropdown from closing on clicking its body