diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 008ef64c6..48df5d7df 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -739,6 +739,9 @@ class AdminCustomersControllerCore extends AdminController $helper->color = 'color4'; $helper->title = $this->l('New Customers', null, null, false); $nbDaysNewCustomers = Validate::isUnsignedInt(Configuration::get('PS_KPI_NEW_CUSTOMERS_NB_DAYS')) ? Configuration::get('PS_KPI_NEW_CUSTOMERS_NB_DAYS') : 30; + $date_from = date('Y-m-d', strtotime('-'.$nbDaysNewCustomers.' day')); + $date_to = date('Y-m-d'); + $helper->href = $this->context->link->getAdminLink('AdminCustomers').'&customerFilter_date_add[]='.$date_from.'&customerFilter_date_add[]='.$date_to; $helper->subtitle = sprintf($this->l('%d Days', null, null, false), (int) $nbDaysNewCustomers); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_new_customers'; $helper->tooltip = $this->l('The total number of new customers who registered in given period of time.', null, null, false); diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 7cec3f256..e29f52a5e 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -2463,7 +2463,7 @@ class AdminProductsControllerCore extends AdminController $helper->title = $this->l('Occupied Rooms', null, null, false); $helper->subtitle = $this->l('Today', null, null, false); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=occupied_rooms'; - $helper->tooltip = $this->l('The current count of rooms that are currently occupied by guests.', null, null, false); + $helper->tooltip = $this->l('The count of rooms that are currently occupied by guests.', null, null, false); $kpis[] = $helper; $helper = new HelperKpi(); @@ -2473,7 +2473,7 @@ class AdminProductsControllerCore extends AdminController $helper->title = $this->l('Vacant Rooms', null, null, false); $helper->subtitle = $this->l('Today', null, null, false); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=vacant_rooms'; - $helper->tooltip = $this->l('The count of rooms that are currently unoccupied and available for booking.', null, null, false); + $helper->tooltip = $this->l('The count of rooms that are either booked but currently unoccupied or available for booking', null, null, false); $kpis[] = $helper; $helper = new HelperKpi(); @@ -2483,7 +2483,7 @@ class AdminProductsControllerCore extends AdminController $helper->title = $this->l('Booked Rooms', null, null, false); $helper->subtitle = $this->l('Today', null, null, false); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=booked_rooms'; - $helper->tooltip = $this->l('The number of rooms that are currently booked but not yet occupied.', null, null, false); + $helper->tooltip = $this->l('The total number of rooms that are currently booked and and awaiting guest check-in', null, null, false); $kpis[] = $helper; $helper = new HelperKpi(); @@ -2493,7 +2493,7 @@ class AdminProductsControllerCore extends AdminController $helper->title = $this->l('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=disabled_rooms'; - $helper->tooltip = $this->l('The number of rooms that are currently disabled.', null, null, false); + $helper->tooltip = $this->l('The total number of rooms that are currently disabled.', null, null, false); $kpis[] = $helper; $helper = new HelperKpi(); @@ -2503,7 +2503,7 @@ class AdminProductsControllerCore extends AdminController $helper->title = $this->l('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=online_bookable_rooms'; - $helper->tooltip = $this->l('The total number of rooms that can be booked only using website.', null, null, false); + $helper->tooltip = $this->l('The total number of rooms that can be booked directly from the front office.', null, null, false); $kpis[] = $helper; $helper = new HelperKpi(); @@ -2513,7 +2513,7 @@ class AdminProductsControllerCore extends AdminController $helper->title = $this->l('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=offline_bookable_rooms'; - $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); + $helper->tooltip = $this->l('The total number of rooms available for booking through the back office.', null, null, false); $kpis[] = $helper; $helper = new HelperKpi(); diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index 782f989f8..b2ef1e69b 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -573,20 +573,20 @@ class AdminStatsControllerCore extends AdminStatsTabController { $sql = 'SELECT p.`id_product`, ( - SELECT IFNULL(SUM(ROUND((DATEDIFF(LEAST(hbd.`date_to`, "'.pSQL($dateTo).'"), GREATEST(hbd.`date_from`, "'.pSQL($dateFrom).'")) / DATEDIFF(hbd.`date_to`, hbd.`date_from`)) * hbd.`total_price_tax_excl`, 2)), 0) + SELECT count(hbd.`id_product`) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = hbd.`id_order`) WHERE hbd.`id_product` = p.`id_product` AND o.`valid` = 1 AND hbd.`date_to` > "'.pSQL($dateFrom).'" AND hbd.`date_from` < "'.pSQL($dateTo).'" - ) AS totalRevenue - FROM `'._DB_PREFIX_.'product` p + ) as total_booked FROM `'._DB_PREFIX_.'product` p INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (hrt.`id_product` = p.`id_product`) - WHERE p.`active` = 1 AND p.`booking_product` = 1'. + WHERE p.`active` = 1 AND p.`booking_product` = 1 '. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hrt') : '').' - HAVING totalRevenue > 0 - ORDER BY totalRevenue DESC'; + GROUP By p.`id_product` + HAVING total_booked > 0 + ORDER BY total_booked DESC'; return Db::getInstance()->getValue($sql); } @@ -856,20 +856,36 @@ class AdminStatsControllerCore extends AdminStatsTabController break; case 'occupied_rooms': - $value = AdminStatsController::getOccupiedRooms(0); + $value = AdminStatsController::getDistinctRoomBookingsCount( + date('Y-m-d', strtotime('-1 day')), + date('Y-m-d'), + 0, + HotelBookingDetail::STATUS_CHECKED_IN + ); break; case 'vacant_rooms': - $totalAvailableRooms = AdminStatsController::getAvailableRoomsForDiscreteDates(date('Y-m-d'), null, 0); - $totalAvailableRooms = $totalAvailableRooms[strtotime(date('Y-m-d'))]; - $totalOccupiedRooms = AdminStatsController::getOccupiedRooms(0); - $value = $totalAvailableRooms - $totalOccupiedRooms; + $totalUnAvailRooms = AdminStatsController::getDisabledRoomsForDiscreteDates(date('Y-m-d'), null, 0); + $totalUnAvailRooms = $totalUnAvailRooms[strtotime(date('Y-m-d'))]; + $totalRooms = AdminStatsController::getTotalRooms(0); + $totalOccupiedRooms = AdminStatsController::getDistinctRoomBookingsCount( + date('Y-m-d', strtotime('-1 day')), + date('Y-m-d'), + 0, + HotelBookingDetail::STATUS_CHECKED_IN + ); + $value = $totalRooms - ($totalUnAvailRooms + $totalOccupiedRooms); break; case 'booked_rooms': - $value = AdminStatsController::getBookedRooms(0); + $value = AdminStatsController::getDistinctRoomBookingsCount( + date('Y-m-d'), + date('Y-m-d', strtotime('+1 day')), + 0, + HotelBookingDetail::STATUS_ALLOTED + ); break; @@ -965,6 +981,12 @@ class AdminStatsControllerCore extends AdminStatsTabController case 'average_lead_time': $dateToday = date('Y-m-d'); $value = Tools::ps_round(AdminStatsController::getAverageLeadTime(), 2); + if ($value && $value <= 1) { + $value .= ' '.$this->l('day'); + } else { + $value .= ' '.$this->l('days'); + } + break; case 'average_guest_in_booking': $dateToday = date('Y-m-d'); @@ -1103,13 +1125,14 @@ class AdminStatsControllerCore extends AdminStatsTabController ); } - public static function getTotalRooms($idHotel = null) + public static function getTotalRooms($idHotel = null, $active = 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') : ''); return Db::getInstance()->getValue($sql); @@ -1123,16 +1146,7 @@ class AdminStatsControllerCore extends AdminStatsTabController $occupancyData = array('count_total' => 0, 'count_occupied' => 0, 'count_available' => 0, 'count_unavailable' => 0); - $countTotal = Db::getInstance()->getValue( - 'SELECT COUNT(hri.`id`) - FROM `'._DB_PREFIX_.'htl_room_information` hri - INNER JOIN `'._DB_PREFIX_.'htl_branch_info` hbi - ON (hbi.`id` = hri.`id_hotel`) - LEFT JOIN `'._DB_PREFIX_.'product` p - ON (p.`id_product` = hri.`id_product`) - WHERE p.`active` = 1'. - HotelBranchInformation::addHotelRestriction($idsHotel, 'hri') - ); + $countTotal = self::getTotalRooms($idsHotel, true); $occupancyData['count_total'] = $countTotal; // Occupied rooms are booked rooms that are not refunded in the date range @@ -1417,7 +1431,27 @@ class AdminStatsControllerCore extends AdminStatsTabController return $result; } - public static function getTotalOccupiedRooms($dateFrom, $dateTo, $idHotel = null) + public static function getDistinctRoomBookingsCount($dateFrom = false, $dateTo = false, $idHotel = null, $roomBookingStatus = null) + { + $sql = 'SELECT COUNT(DISTINCT hbd.`id_room`) + FROM `'._DB_PREFIX_.'htl_booking_detail` hbd + LEFT JOIN `'._DB_PREFIX_.'htl_room_information` hri + ON (hri.`id` = hbd.`id_room`) + 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 '. + (($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') : ''); + $result = Db::getInstance()->getValue($sql); + + return $result ? $result : 0; + + } + + public static function getTotalBookedRooms($dateFrom, $dateTo, $idHotel = null) { $sql = 'SELECT COUNT(hbd.`id_room`) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd @@ -1795,46 +1829,6 @@ class AdminStatsControllerCore extends AdminStatsTabController return $result; } - /** - * Returns the number of rooms that have been checked-in. - */ - public static function getOccupiedRooms($idHotel = null) - { - $sql = 'SELECT COUNT(DISTINCT hbd.`id_room`) - FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - LEFT JOIN `'._DB_PREFIX_.'htl_room_information` hri - ON (hri.`id` = hbd.`id_room`) - 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_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN. - (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); - $result = Db::getInstance()->getValue($sql); - - return $result; - } - - /** - * Returns the number of rooms that have been booked but not checked-in yet. - */ - public static function getBookedRooms($idHotel = null) - { - $dateToday = date('Y-m-d'); - - $sql = 'SELECT COUNT(DISTINCT hbd.`id_room`) - FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`is_refunded` = 0 - AND hbd.`is_cancelled` = 0 - AND hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_ALLOTED.' - AND hbd.`date_from` = "'.pSQL($dateToday).' 00:00:00"'. - (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); - $result = Db::getInstance()->getValue($sql); - - return $result; - } - public static function getTotalFrequentCustomers($nbOrders = 5, $idHotel = null) { $sql = 'SELECT COUNT(t.`id_customer`) @@ -1891,7 +1885,7 @@ class AdminStatsControllerCore extends AdminStatsTabController public static function getTotalNewCustomers($nbDaysNewCustomers) { - $maxDateAdd = date('Y-m-d H:i:s', strtotime('-'.$nbDaysNewCustomers.' day')); + $maxDateAdd = date('Y-m-d', strtotime('-'.$nbDaysNewCustomers.' day')); $sql = 'SELECT COUNT(c.`id_customer`) FROM `'._DB_PREFIX_.'customer` c WHERE c.`date_add` >= "'.pSQL($maxDateAdd).'" AND c.`deleted` = 0'; @@ -1976,7 +1970,7 @@ class AdminStatsControllerCore extends AdminStatsTabController $nightsBookedByDate = self::getRoomNightsData($dateFrom, $dateTo, $idHotel); $totalNightsBooked = array_sum($nightsBookedByDate); - $totalOccupiedRoom = self::getTotalOccupiedRooms($dateFrom, $dateTo, $idHotel); + $totalOccupiedRoom = self::getTotalBookedRooms($dateFrom, $dateTo, $idHotel); return $totalOccupiedRoom ? ($totalNightsBooked / $totalOccupiedRoom) : 0; } diff --git a/modules/dashactivity/dashactivity.php b/modules/dashactivity/dashactivity.php index 46fc8c72f..4f30c3beb 100644 --- a/modules/dashactivity/dashactivity.php +++ b/modules/dashactivity/dashactivity.php @@ -87,10 +87,13 @@ class Dashactivity extends Module public function hookDashboardZoneOne($params) { $this->context->smarty->assign($this->getConfigFieldsValues()); + $date_from = $this->context->employee->stats_date_from; + $date_to = $this->context->employee->stats_date_to; $this->context->smarty->assign( array( 'dashactivity_config_form' => $this->renderConfigForm(), - 'link' => $this->context->link + 'link' => $this->context->link, + 'new_customer_filter_link' => $this->context->link->getAdminLink('AdminCustomers').'&customerFilter_date_add[]='.$date_from.'&customerFilter_date_add[]='.$date_to ) ); diff --git a/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl b/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl index 900c3f64f..5ed29c94c 100644 --- a/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl +++ b/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl @@ -122,7 +122,7 @@