From 2a71b6b7bd2f2ca59e0dfe339638e83db94627a3 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 26 Oct 2023 09:44:08 +0530 Subject: [PATCH] update hotel wise access in stats modules --- .../statsbestcategories.php | 3 + .../statsbestproducts/statsbestproducts.php | 5 +- modules/statscatalog/statscatalog.php | 24 +- modules/statscheckup/statscheckup.php | 7 + modules/statsforecast/statsforecast.php | 20 +- modules/statsproduct/statsproduct.php | 213 +++++++++--------- modules/statssales/statssales.php | 24 +- 7 files changed, 181 insertions(+), 115 deletions(-) diff --git a/modules/statsbestcategories/statsbestcategories.php b/modules/statsbestcategories/statsbestcategories.php index 1b6feb710..c7780e47d 100644 --- a/modules/statsbestcategories/statsbestcategories.php +++ b/modules/statsbestcategories/statsbestcategories.php @@ -221,8 +221,11 @@ class StatsBestCategories extends ModuleGrid AND hbd.`date_to` > "'.pSQL($date_from).'" AND hbd.`date_from` < "'.pSQL($date_to).'" ) AS totalOperatingCost FROM `'._DB_PREFIX_.'htl_branch_info` hbi + INNER JOIN `'._DB_PREFIX_.'htl_access` ha + ON (hbi.`id` = ha.`id_hotel`) LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil ON (hbil.`id` = hbi.`id` AND hbil.`id_lang` = '.(int)$id_lang .') + WHERE ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1 GROUP BY (hbi.`id`)'; if (Validate::IsName($this->_sort)) { diff --git a/modules/statsbestproducts/statsbestproducts.php b/modules/statsbestproducts/statsbestproducts.php index fbfff36f1..6bf768d97 100644 --- a/modules/statsbestproducts/statsbestproducts.php +++ b/modules/statsbestproducts/statsbestproducts.php @@ -209,7 +209,10 @@ class StatsBestProducts extends ModuleGrid ON (hrt.`id_product` = p.`id_product`) LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil ON (hbil.`id` = hrt.`id_hotel` AND hbil.`id_lang` = '.(int) $id_lang .') - WHERE p.`booking_product` = 1'; + INNER JOIN `'._DB_PREFIX_.'htl_access` ha + ON (hbil.`id` = ha.`id_hotel`) + WHERE p.`booking_product` = 1 + AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1'; if (Validate::IsName($this->_sort)) { $this->query .= ' ORDER BY `'.bqSQL($this->_sort).'`'; diff --git a/modules/statscatalog/statscatalog.php b/modules/statscatalog/statscatalog.php index e18ea364d..b54a87493 100644 --- a/modules/statscatalog/statscatalog.php +++ b/modules/statscatalog/statscatalog.php @@ -62,8 +62,10 @@ class StatsCatalog extends Module IFNULL(SUM(p.`price`) / COUNT(p.`price`), 0) AS average_price FROM `'._DB_PREFIX_.'product` p INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (hrt.`id_product` = p.`id_product`) + INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hrt.`id_hotel` = ha.`id_hotel`) '.$this->join.' WHERE p.`active` = 1 + AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1 '.$this->where; if ($this->id_hotel) { $sql .= ' AND hrt.`id_hotel` = '.(int)$this->id_hotel; @@ -80,8 +82,10 @@ class StatsCatalog extends Module LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON (pt.`id_page_type` = p.`id_page_type`) LEFT JOIN `'._DB_PREFIX_.'category` cl ON (cl.`id_category` = p.`id_object`) LEFT JOIN `'._DB_PREFIX_.'htl_branch_info` hbi ON (hbi.`id_category` = cl.`id_category`) + INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbi.`id` = ha.`id_hotel`) '.$this->join.' WHERE pt.`name` = "'.pSQL('category').'" + AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1 '.$this->where; if ($this->id_hotel) { @@ -101,8 +105,10 @@ class StatsCatalog extends Module LEFT JOIN `'._DB_PREFIX_.'page` pa ON p.`id_product` = pa.`id_object` LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON (pt.`id_page_type` = pa.`id_page_type` AND pt.`name` IN ("product.php", "product")) LEFT JOIN `'._DB_PREFIX_.'page_viewed` pv ON pv.`id_page` = pa.`id_page` + INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hrt.`id_hotel` = ha.`id_hotel`) '.$this->join.' WHERE product_shop.`active` = 1 + AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1 '.$this->where; if ($this->id_hotel) { @@ -120,9 +126,11 @@ class StatsCatalog extends Module LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = pa.`id_page_type` LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = pa.`id_object` INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product`) + INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hrt.`id_hotel` = ha.`id_hotel`) '.Shop::addSqlAssociation('product', 'p').' '.$this->join.' WHERE pt.`name` IN ("product.php", "product") + AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1 AND product_shop.`active` = 1 '.$this->where; @@ -154,6 +162,9 @@ class StatsCatalog extends Module WHERE hrt.`id_hotel` = hbi.`id` ) AS room_type_images FROM `'._DB_PREFIX_.'htl_branch_info` hbi + INNER JOIN `'._DB_PREFIX_.'htl_access` ha + ON (hbi.`id` = ha.`id_hotel`) + WHERE ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1 ) AS t '.($this->id_hotel ? ' WHERE t.`id` = '.(int) $this->id_hotel : '') ); @@ -164,7 +175,9 @@ class StatsCatalog extends Module return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue( 'SELECT IFNULL(SUM(DATEDIFF(hbd.`date_to`, hbd.`date_from`)), 0) FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - '.($this->id_hotel ? ' WHERE hbd.`id_hotel` = '.(int) $this->id_hotel : '') + INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbd.`id_hotel` = ha.`id_hotel`) + WHERE ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1 + '.($this->id_hotel ? ' AND hbd.`id_hotel` = '.(int) $this->id_hotel : '') ); } @@ -175,9 +188,11 @@ class StatsCatalog extends Module LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.`id_order` = od.`id_order` LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = od.`product_id` INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product`) + INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hrt.`id_hotel` = ha.`id_hotel`) '.Shop::addSqlAssociation('product', 'p').' '.$this->join.' WHERE o.valid = 1 + AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1 '.$this->where.' AND product_shop.`active` = 1'; if ($this->id_hotel) { @@ -195,10 +210,12 @@ class StatsCatalog extends Module FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product`) + INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hrt.`id_hotel` = ha.`id_hotel`) LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.id_lang = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').') '.$this->join.' WHERE product_shop.`active` = 1 + AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1 '.(count($precalc2) ? 'AND p.`id_product` NOT IN ('.implode(',', $precalc2).')' : '').' '.$this->where; if ($this->id_hotel) { @@ -212,7 +229,7 @@ class StatsCatalog extends Module public function hookAdminStatsModules($params) { $objBranchInfo = new HotelBranchInformation(); - $hotels = $objBranchInfo->hotelBranchesInfo((int)$this->context->language->id); + $hotels = $objBranchInfo->getProfileAccessedHotels($this->context->employee->id_profile, 1); $product_token = Tools::getAdminToken('AdminProducts'.(int)Tab::getIdFromClassName('AdminProducts').(int)$this->context->employee->id); $irow = 0; @@ -223,6 +240,7 @@ class StatsCatalog extends Module $result1 = $this->getQuery1(); $total = $result1['total']; + $average_price = $result1['average_price']; $available_images = $this->getAvailableImages(); @@ -257,7 +275,7 @@ class StatsCatalog extends Module '; foreach ($hotels as $hotel) { - $this->html .= ''; + $this->html .= ''; } $this->html .= ' diff --git a/modules/statssales/statssales.php b/modules/statssales/statssales.php index c56931ab6..d16f7053e 100644 --- a/modules/statssales/statssales.php +++ b/modules/statssales/statssales.php @@ -82,7 +82,8 @@ class StatsSales extends ModuleGraph } $objHotelBranchInformation = new HotelBranchInformation(); - $hotelsInfo = $objHotelBranchInformation->hotelsNameAndId(); + $hotelsInfo = $objHotelBranchInformation->getProfileAccessedHotels($this->context->employee->id_profile, 1); + $this->html = '
'.$this->displayName.' @@ -109,7 +110,7 @@ class StatsSales extends ModuleGraph
'; @@ -192,19 +193,17 @@ class StatsSales extends ModuleGraph { $sql = 'SELECT COUNT(id_order) AS orderCount, ROUND(SUM(total_paid_real), 2) AS orderSum FROM ( - SELECT o.`id_order`, (o.`total_paid_real` / o.`conversion_rate`) AS total_paid_real, - ( - SELECT hbd.`id_hotel` - FROM `'._DB_PREFIX_.'htl_booking_detail` hbd - WHERE hbd.`id_order` = o.`id_order` - LIMIT 1 - ) AS id_hotel + SELECT o.`id_order`, (o.`total_paid_real` / o.`conversion_rate`) AS total_paid_real, hbd.`id_hotel` FROM `'._DB_PREFIX_.'orders` o + INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`) + INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbd.`id_hotel` = ha.`id_hotel`) '.((int)Tools::getValue('id_country') ? 'LEFT JOIN `'._DB_PREFIX_.'address` a ON o.`id_address_delivery` = a.`id_address`' : '').' WHERE o.`valid` = 1 + AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1 '.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o').' '.((int)Tools::getValue('id_country') ? ' AND a.`id_country` = '.(int)Tools::getValue('id_country') : '').' AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().' + GROUP BY o.`id_order` ) AS t '.((int)Tools::getValue('id_hotel') ? ' WHERE id_hotel = '.(int)Tools::getValue('id_hotel') : ''); @@ -242,8 +241,11 @@ class StatsSales extends ModuleGraph LIMIT 1 ) AS id_hotel FROM `'._DB_PREFIX_.'orders` o + INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`) + INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbd.`id_hotel` = ha.`id_hotel`) '.((int)$this->id_country ? 'LEFT JOIN `'._DB_PREFIX_.'address` a ON o.`id_address_delivery` = a.`id_address`' : '').' WHERE o.`valid` = 1 + AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1 '.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o').' '.((int)$this->id_country ? ' AND a.`id_country` = '.(int)$this->id_country : '').' AND o.`invoice_date` BETWEEN'; @@ -319,6 +321,8 @@ class StatsSales extends ModuleGraph LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$this->getLang().') LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON os.`id_order_state` = oh.`id_order_state` LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = oh.`id_order` + INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`) + INNER JOIN `'._DB_PREFIX_.'htl_access` ha ON (hbd.`id_hotel` = ha.`id_hotel`) '.((int)$this->id_country ? 'LEFT JOIN `'._DB_PREFIX_.'address` a ON o.id_address_delivery = a.id_address' : '').' WHERE oh.`id_order_history` = ( SELECT ios.`id_order_history` @@ -327,8 +331,10 @@ class StatsSales extends ModuleGraph ORDER BY ios.`date_add` DESC, oh.`id_order_history` DESC LIMIT 1 ) + AND ha.`id_profile` = '.(int)$this->context->employee->id_profile.' AND ha.`access` = 1 '.((int)$this->id_country ? 'AND a.id_country = '.(int)$this->id_country : '').' AND o.`date_add` BETWEEN '.ModuleGraph::getDateBetween().' + GROUP BY o.`id_order` ) AS t '.(((int) $this->id_hotel) ? ' WHERE id_hotel = '.(int) $this->id_hotel : '').' GROUP BY t.`id_order_state`';