From e299b4bd41a036f36e4fa19b6c611fec19e06217 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 14 May 2024 15:10:40 +0530 Subject: [PATCH 1/9] Fixed: The incorrect information on the KPIs in the AdminProductController --- controllers/admin/AdminProductsController.php | 12 ++++---- controllers/admin/AdminStatsController.php | 29 +++++++++++++++---- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 7123dbbf4..089d56c9c 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -2458,7 +2458,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(); @@ -2468,7 +2468,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(); @@ -2478,7 +2478,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 unoccupied.', null, null, false); $kpis[] = $helper; $helper = new HelperKpi(); @@ -2488,7 +2488,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(); @@ -2498,7 +2498,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(); @@ -2508,7 +2508,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 2de11a362..1d3e4a721 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -850,15 +850,16 @@ class AdminStatsControllerCore extends AdminStatsTabController break; case 'occupied_rooms': - $value = AdminStatsController::getOccupiedRooms(0); + $value = AdminStatsController::getCurrentlyOccupiedRooms(0); 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::getCurrentlyOccupiedRooms(0); + $value = $totalRooms - ($totalUnAvailRooms + $totalOccupiedRooms); break; @@ -1810,6 +1811,24 @@ class AdminStatsControllerCore extends AdminStatsTabController return $result; } + public static function getCurrentlyOccupiedRooms($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 ("'.pSQL(date('Y-m-d')).'" BETWEEN hbd.`date_from` AND hbd.`date_to`) + AND hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN. + (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); + + return Db::getInstance()->getValue($sql); + } + /** * Returns the number of rooms that have been booked but not checked-in yet. */ From 677a3d7492d65123d63dd25a8eb73f88a2def2a0 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 21 May 2024 12:51:50 +0530 Subject: [PATCH 2/9] Removed non required function and updated getOccupupiedRooms function --- controllers/admin/AdminStatsController.php | 25 ++++------------------ 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index 1d3e4a721..5530ea491 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -850,7 +850,7 @@ class AdminStatsControllerCore extends AdminStatsTabController break; case 'occupied_rooms': - $value = AdminStatsController::getCurrentlyOccupiedRooms(0); + $value = AdminStatsController::getOccupiedRooms(0, date('Y-m-d')); break; @@ -858,7 +858,7 @@ class AdminStatsControllerCore extends AdminStatsTabController $totalUnAvailRooms = AdminStatsController::getDisabledRoomsForDiscreteDates(date('Y-m-d'), null, 0); $totalUnAvailRooms = $totalUnAvailRooms[strtotime(date('Y-m-d'))]; $totalRooms = AdminStatsController::getTotalRooms(0); - $totalOccupiedRooms = AdminStatsController::getCurrentlyOccupiedRooms(0); + $totalOccupiedRooms = AdminStatsController::getOccupiedRooms(0, date('Y-m-d')); $value = $totalRooms - ($totalUnAvailRooms + $totalOccupiedRooms); break; @@ -1793,7 +1793,7 @@ class AdminStatsControllerCore extends AdminStatsTabController /** * Returns the number of rooms that have been checked-in. */ - public static function getOccupiedRooms($idHotel = null) + public static function getOccupiedRooms($idHotel = null, $date = false) { $sql = 'SELECT COUNT(DISTINCT hbd.`id_room`) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd @@ -1805,30 +1805,13 @@ class AdminStatsControllerCore extends AdminStatsTabController AND hbd.`is_refunded` = 0 AND hbd.`is_cancelled` = 0 AND hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN. + (($date) ? ' AND ("'.pSQL($date).'" BETWEEN hbd.`date_from` AND hbd.`date_to`) ' : ''); (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); $result = Db::getInstance()->getValue($sql); return $result; } - public static function getCurrentlyOccupiedRooms($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 ("'.pSQL(date('Y-m-d')).'" BETWEEN hbd.`date_from` AND hbd.`date_to`) - AND hbd.`id_status` = '.(int) HotelBookingDetail::STATUS_CHECKED_IN. - (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hbd') : ''); - - return Db::getInstance()->getValue($sql); - } - /** * Returns the number of rooms that have been booked but not checked-in yet. */ From 906ed2b693fcbb6a1819e7d71c98ad7ce6c9bffb Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 22 May 2024 10:16:55 +0530 Subject: [PATCH 3/9] Updated: the tooltip for the booked rooms KPI --- controllers/admin/AdminProductsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index ee8a33dfb..2ede2a539 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -2478,7 +2478,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 total number of rooms that are currently booked and unoccupied.', 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(); From 9454e1ae76bac93293822e47bbbfa8dedd56139c Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 28 May 2024 15:16:05 +0530 Subject: [PATCH 4/9] Updated: centeralized the function to get the count of the rooms with their booiking statuses --- controllers/admin/AdminStatsController.php | 100 +++++++++------------ 1 file changed, 43 insertions(+), 57 deletions(-) diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index 5530ea491..be7129d0d 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -850,7 +850,12 @@ class AdminStatsControllerCore extends AdminStatsTabController break; case 'occupied_rooms': - $value = AdminStatsController::getOccupiedRooms(0, date('Y-m-d')); + $value = AdminStatsController::getDistinctRoomBookingsCount( + date('Y-m-d', strtotime('-1 day')), + date('Y-m-d'), + 0, + HotelBookingDetail::STATUS_CHECKED_IN + ); break; @@ -858,13 +863,23 @@ class AdminStatsControllerCore extends AdminStatsTabController $totalUnAvailRooms = AdminStatsController::getDisabledRoomsForDiscreteDates(date('Y-m-d'), null, 0); $totalUnAvailRooms = $totalUnAvailRooms[strtotime(date('Y-m-d'))]; $totalRooms = AdminStatsController::getTotalRooms(0); - $totalOccupiedRooms = AdminStatsController::getOccupiedRooms(0, date('Y-m-d')); + $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; @@ -1098,13 +1113,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); @@ -1118,16 +1134,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 @@ -1412,7 +1419,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 @@ -1790,47 +1817,6 @@ class AdminStatsControllerCore extends AdminStatsTabController return $result; } - /** - * Returns the number of rooms that have been checked-in. - */ - public static function getOccupiedRooms($idHotel = null, $date = false) - { - $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. - (($date) ? ' AND ("'.pSQL($date).'" BETWEEN hbd.`date_from` AND hbd.`date_to`) ' : ''); - (!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`) @@ -1972,7 +1958,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; } From 601e51b514c42848b0c7562cd7f9307982fe72fd Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 14 Jun 2024 12:39:42 +0530 Subject: [PATCH 5/9] Fixed the new customer KPI --- .../admin/AdminCustomersController.php | 20 +++++++++++++++++++ controllers/admin/AdminStatsController.php | 8 +++++++- modules/dashactivity/views/js/dashactivity.js | 6 ++++-- .../templates/hook/dashboard_zone_one.tpl | 2 +- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 6c763f10c..526c59dbb 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -230,6 +230,23 @@ class AdminCustomersControllerCore extends AdminController )); } + $prefix = $this->getCookieFilterPrefix(); + if (Tools::getValue('filterOnlyNewCustomer')) { + if (($dateFrom = Tools::getValue('date_from')) + && ($dateTo = Tools::getValue('date_to')) + && strtotime($dateTo) >= strtotime($dateFrom) + ) { + $this->processResetFilters(); + $this->context->cookie->{'submitFilter'.$this->table} = true; + //Updating the date format of the filter dates to the desired format. + $dateFrom = date('Y-m-d', strtotime($dateFrom)); + $dateTo = date('Y-m-d', strtotime($dateTo)); + $this->context->cookie->{$prefix.$this->table.'Filter_date_add'} = json_encode(array($dateFrom, $dateTo)); + } + + $this->redirect_after = $this->context->link->getAdminLink('AdminCustomers'); + } + if (!$this->can_add_customer && !$this->display) { $this->informations[] = $this->l('You have to select a shop if you want to create a customer.'); } @@ -739,6 +756,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').'&filterOnlyNewCustomer=1&date_from='.$date_from.'&date_to='.$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/AdminStatsController.php b/controllers/admin/AdminStatsController.php index f647411b1..abd0d9be7 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -981,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'); @@ -1879,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'; diff --git a/modules/dashactivity/views/js/dashactivity.js b/modules/dashactivity/views/js/dashactivity.js index a84820e02..1aa71314a 100644 --- a/modules/dashactivity/views/js/dashactivity.js +++ b/modules/dashactivity/views/js/dashactivity.js @@ -58,7 +58,8 @@ $(document).ready(function() { $('#date-start').change(function() { start = Date.parseDate($('#date-start').val(), 'Y-m-d'); end = Date.parseDate($('#date-end').val(), 'Y-m-d'); - + var url = $('#dash_filter_new_customers').data('href') + '&date_from='+start.format('Y-m-d')+ '&date_to='+ end.format('Y-m-d'); + $('#dash_filter_new_customers').attr('href', url); $('#customers-newsletters-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format))); $('#traffic-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format))); }); @@ -66,7 +67,8 @@ $(document).ready(function() { $('#date-end').change(function() { start = Date.parseDate($('#date-start').val(), 'Y-m-d'); end = Date.parseDate($('#date-end').val(), 'Y-m-d'); - + var url = $('#dash_filter_new_customers').data('href') + '&date_from='+start.format('Y-m-d')+ '&date_to='+ end.format('Y-m-d'); + $('#dash_filter_new_customers').attr('href', url); $('#customers-newsletters-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format))); $('#traffic-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format))); }); diff --git a/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl b/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl index 95cee2cd3..a649805a3 100644 --- a/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl +++ b/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl @@ -121,7 +121,7 @@
  • - + {l s="New Customers" mod='dashactivity'} From 578bce5a1ede7af9b20c7c011e9ee68305e91456 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 25 Jun 2024 18:35:45 +0530 Subject: [PATCH 6/9] Updated: The best selling KPI will now show rooms on the basis of the booked rooms instead of total revenue --- controllers/admin/AdminStatsController.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index abd0d9be7..ce7df4d7d 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -573,20 +573,19 @@ 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` + ORDER BY total_booked DESC'; return Db::getInstance()->getValue($sql); } From 115adba9d84985d61fd9e2b05524e396d075c778 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Thu, 4 Jul 2024 17:22:48 +0530 Subject: [PATCH 7/9] improved the new customer KPI filter and bestselling KPIs --- .../admin/AdminCustomersController.php | 19 +------------------ controllers/admin/AdminStatsController.php | 1 + 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 1746db3a7..be5ad06ff 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -230,23 +230,6 @@ class AdminCustomersControllerCore extends AdminController )); } - $prefix = $this->getCookieFilterPrefix(); - if (Tools::getValue('filterOnlyNewCustomer')) { - if (($dateFrom = Tools::getValue('date_from')) - && ($dateTo = Tools::getValue('date_to')) - && strtotime($dateTo) >= strtotime($dateFrom) - ) { - $this->processResetFilters(); - $this->context->cookie->{'submitFilter'.$this->table} = true; - //Updating the date format of the filter dates to the desired format. - $dateFrom = date('Y-m-d', strtotime($dateFrom)); - $dateTo = date('Y-m-d', strtotime($dateTo)); - $this->context->cookie->{$prefix.$this->table.'Filter_date_add'} = json_encode(array($dateFrom, $dateTo)); - } - - $this->redirect_after = $this->context->link->getAdminLink('AdminCustomers'); - } - if (!$this->can_add_customer && !$this->display) { $this->informations[] = $this->l('You have to select a shop if you want to create a customer.'); } @@ -758,7 +741,7 @@ class AdminCustomersControllerCore extends AdminController $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').'&filterOnlyNewCustomer=1&date_from='.$date_from.'&date_to='.$date_to; + $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/AdminStatsController.php b/controllers/admin/AdminStatsController.php index ce7df4d7d..b2ef1e69b 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -585,6 +585,7 @@ class AdminStatsControllerCore extends AdminStatsTabController WHERE p.`active` = 1 AND p.`booking_product` = 1 '. (!is_null($idHotel) ? HotelBranchInformation::addHotelRestriction($idHotel, 'hrt') : '').' GROUP By p.`id_product` + HAVING total_booked > 0 ORDER BY total_booked DESC'; return Db::getInstance()->getValue($sql); From ee5307c168ef93c091a1c585fda40a6cacf591e9 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 8 Jul 2024 19:25:25 +0530 Subject: [PATCH 8/9] Fixed new customer filter for dashactivity on dashboard --- modules/dashactivity/dashactivity.php | 5 ++++- modules/dashactivity/views/js/dashactivity.js | 4 ---- .../dashactivity/views/templates/hook/dashboard_zone_one.tpl | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) 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/js/dashactivity.js b/modules/dashactivity/views/js/dashactivity.js index 1aa71314a..8da481eec 100644 --- a/modules/dashactivity/views/js/dashactivity.js +++ b/modules/dashactivity/views/js/dashactivity.js @@ -58,8 +58,6 @@ $(document).ready(function() { $('#date-start').change(function() { start = Date.parseDate($('#date-start').val(), 'Y-m-d'); end = Date.parseDate($('#date-end').val(), 'Y-m-d'); - var url = $('#dash_filter_new_customers').data('href') + '&date_from='+start.format('Y-m-d')+ '&date_to='+ end.format('Y-m-d'); - $('#dash_filter_new_customers').attr('href', url); $('#customers-newsletters-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format))); $('#traffic-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format))); }); @@ -67,8 +65,6 @@ $(document).ready(function() { $('#date-end').change(function() { start = Date.parseDate($('#date-start').val(), 'Y-m-d'); end = Date.parseDate($('#date-end').val(), 'Y-m-d'); - var url = $('#dash_filter_new_customers').data('href') + '&date_from='+start.format('Y-m-d')+ '&date_to='+ end.format('Y-m-d'); - $('#dash_filter_new_customers').attr('href', url); $('#customers-newsletters-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format))); $('#traffic-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format))); }); diff --git a/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl b/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl index 3ee74b577..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 @@
    • - + {l s="New Customers" mod='dashactivity'} From 3cdb7ba268480f50981e4b2ebb42e6a2a83e748f Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 10 Jul 2024 10:01:50 +0530 Subject: [PATCH 9/9] revert the non required changes from dashactivity.js --- modules/dashactivity/views/js/dashactivity.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/dashactivity/views/js/dashactivity.js b/modules/dashactivity/views/js/dashactivity.js index 8da481eec..a84820e02 100644 --- a/modules/dashactivity/views/js/dashactivity.js +++ b/modules/dashactivity/views/js/dashactivity.js @@ -58,6 +58,7 @@ $(document).ready(function() { $('#date-start').change(function() { start = Date.parseDate($('#date-start').val(), 'Y-m-d'); end = Date.parseDate($('#date-end').val(), 'Y-m-d'); + $('#customers-newsletters-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format))); $('#traffic-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format))); }); @@ -65,6 +66,7 @@ $(document).ready(function() { $('#date-end').change(function() { start = Date.parseDate($('#date-start').val(), 'Y-m-d'); end = Date.parseDate($('#date-end').val(), 'Y-m-d'); + $('#customers-newsletters-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format))); $('#traffic-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format))); });