From ea5006c50965003e60bfa72a1bb6bfcdf5c072f2 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 20 Oct 2023 17:10:25 +0530 Subject: [PATCH] added new module for services overview --- modules/statsserviceproducts/CHANGELOG.txt | 0 modules/statsserviceproducts/index.php | 29 +++ modules/statsserviceproducts/logo.gif | Bin 0 -> 641 bytes modules/statsserviceproducts/logo.png | Bin 0 -> 904 bytes .../statsserviceproducts.php | 190 ++++++++++++++++++ modules/statsserviceproducts/views/index.php | 29 +++ .../views/templates/hook/index.php | 29 +++ .../templates/hook/services_content_block.tpl | 24 +++ .../views/templates/index.php | 29 +++ 9 files changed, 330 insertions(+) create mode 100644 modules/statsserviceproducts/CHANGELOG.txt create mode 100644 modules/statsserviceproducts/index.php create mode 100644 modules/statsserviceproducts/logo.gif create mode 100644 modules/statsserviceproducts/logo.png create mode 100644 modules/statsserviceproducts/statsserviceproducts.php create mode 100644 modules/statsserviceproducts/views/index.php create mode 100644 modules/statsserviceproducts/views/templates/hook/index.php create mode 100644 modules/statsserviceproducts/views/templates/hook/services_content_block.tpl create mode 100644 modules/statsserviceproducts/views/templates/index.php diff --git a/modules/statsserviceproducts/CHANGELOG.txt b/modules/statsserviceproducts/CHANGELOG.txt new file mode 100644 index 000000000..e69de29bb diff --git a/modules/statsserviceproducts/index.php b/modules/statsserviceproducts/index.php new file mode 100644 index 000000000..7a7f9721e --- /dev/null +++ b/modules/statsserviceproducts/index.php @@ -0,0 +1,29 @@ +W=215y}4!=PhViQzKob6 zDm^JtBWDj)c(U-6#XIkkeoc;{h#{iZJuE6j)m|RR`#4;(3*aMW5JZL`U8!n!uM>6v zGQ*4DBYDQiX9@&~cnNq31c~IcMT#~~@ZtXsf{%0c_4l(^^Pee&bqeNCHJX~`mmcQr zCnfke_g}!XV;?qJ@nf?%b$gt#Qy3W%Z8I4fjBkJ8VEsY!@_Dy0T$A*>5SNckV=Qpu zVcD{iXskp0i%E)!gCqe7G*_!N@mwljv6UTvU=pevy<4{20WAIjX=CDgO3}_wOj8Oc zZ0^+cLNBD_!gl}eH0Mfl5DMzB-x$zrI#&` z$rNdCey7!7X#^mS`R3}qnz}8>7BGvL^qin1xe206`1D6^WEW2V9G~OIZ?Oe&$to bfco(d?EI=iCbwn$00000NkvXXu0mjfNkJU) literal 0 HcmV?d00001 diff --git a/modules/statsserviceproducts/logo.png b/modules/statsserviceproducts/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..def4ee9b43892f1d8884ea4d2bd8291e3fab8dd3 GIT binary patch literal 904 zcmV;319$w1P)hCyUH-!|v6?c4J`9!({rqBAe@zz5ELzvuaWo}JC(nGS$%KG7`}3YCbbok+xr}S^r792YWgB6;7>D+2 z2^cWz;Wp{fPwvmcG_l7T)+#;H%M4~Q^S9+qMbQ{=7%^C}4TIJl7?y-io>|rl6n8i$H z(?QqtAr`wXt?g|rPJs2?3V88Q}G4;MFOhZ5pj4Pi58~YuUqI z$zT>U?W%*WhJu)i$-jZI)GKf)c7zK~nJN^}WiMFQBkpkJzoD>NFbJDMgkD%BELENd)FC25NVqCrtef{^ e;g`{WKfn(;h3name = 'statsserviceproducts'; + $this->tab = 'analytics_stats'; + $this->version = '1.0.0'; + $this->author = 'Webkul'; + $this->need_instance = 0; + + parent::__construct(); + + $this->default_sort_column = 'totalPriceSold'; + $this->default_sort_direction = 'DESC'; + $this->paging_message = sprintf($this->l('Displaying %1$s of %2$s'), '{0} - {1}', '{2}'); + + $this->columns = array( + array( + 'id' => 'name', + 'header' => $this->l('Name'), + 'dataIndex' => 'name', + 'align' => 'left' + ), + array( + 'id' => 'auto_add_to_cart', + 'header' => $this->l('Auto add to cart'), + 'dataIndex' => 'auto_add_to_cart', + 'align' => 'center' + ), + array( + 'id' => 'totalQuantitySold', + 'header' => $this->l('Quantity sold'), + 'dataIndex' => 'totalQuantitySold', + 'align' => 'center' + ), + array( + 'id' => 'avgPriceSold', + 'header' => $this->l('Average Price'), + 'dataIndex' => 'avgPriceSold', + 'align' => 'center' + ), + array( + 'id' => 'totalPriceSold', + 'header' => $this->l('Sales'), + 'dataIndex' => 'totalPriceSold', + 'align' => 'center' + ), + array( + 'id' => 'averageQuantitySold', + 'header' => $this->l('Quantity sold in a day'), + 'dataIndex' => 'averageQuantitySold', + 'align' => 'center' + ), + array( + 'id' => 'active', + 'header' => $this->l('Active'), + 'dataIndex' => 'active', + 'align' => 'center' + ) + ); + + $this->displayName = $this->l('Extra services overview'); + $this->description = $this->l('Show extra services overview based on sales.'); + $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); + } + + public function install() + { + return (parent::install() && $this->registerHook('AdminStatsModules')); + } + + public function hookAdminStatsModules($params) + { + $engine_params = array( + 'id' => 'id_product', + 'title' => $this->displayName, + 'columns' => $this->columns, + 'defaultSortColumn' => $this->default_sort_column, + 'defaultSortDirection' => $this->default_sort_direction, + 'pagingMessage' => $this->paging_message + ); + + if (Tools::getValue('export')) { + $this->csvExport($engine_params); + } + + $this->context->smarty->assign(array( + 'module_name' => $this->displayName, + 'grid_table' => $this->engine($engine_params), + 'export_link' => Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1', + )); + + return $this->display(__FILE__, 'services_content_block.tpl'); + } + + public function getData() + { + $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); + $date_between = $this->getDate(); + $array_date_between = explode(' AND ', $date_between); + + $this->query = 'SELECT SQL_CALC_FOUND_ROWS p.`id_product`, pl.`name`, p.`active`, p.`auto_add_to_cart`, + IFNULL(odd.`avgPriceSold`, 0) as avgPriceSold, + IFNULL(odd.`totalQuantitySold`, 0) as totalQuantitySold, + IFNULL(odd.`averageQuantitySold`, 0) as averageQuantitySold, + IFNULL(odd.`totalPriceSold`, 0) as totalPriceSold + FROM '._DB_PREFIX_.'product p + '.Shop::addSqlAssociation('product', 'p').' + LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$this->getLang().' '.Shop::addSqlRestrictionOnLang('pl').') + LEFT JOIN ( + SELECT p.`id_product` as id_product, + ROUND(AVG(od.`product_price` / o.`conversion_rate`), 2) as avgPriceSold, + IFNULL(SUM(od.`product_quantity`), 0) AS totalQuantitySold, + ROUND(IFNULL(IFNULL(SUM(od.`product_quantity`), 0) / (1 + LEAST(TO_DAYS('.$array_date_between[1].'), TO_DAYS(NOW())) - GREATEST(TO_DAYS('.$array_date_between[0].'), TO_DAYS(product_shop.date_add))), 0), 2) as averageQuantitySold, + ROUND(IFNULL(SUM((od.product_price * od.product_quantity) / o.conversion_rate), 0), 2) AS totalPriceSold + FROM '._DB_PREFIX_.'order_detail od + INNER JOIN '._DB_PREFIX_.'product p ON (p.`id_product` = od.`product_id`) + '.Shop::addSqlAssociation('product', 'p').' + LEFT JOIN '._DB_PREFIX_.'orders o ON (od.id_order = o.id_order) + WHERE o.valid = 1 AND o.invoice_date BETWEEN '.$date_between.' + GROUP BY od.`product_id` + ) odd ON (odd.`id_product` = p.`id_product`) + WHERE p.`booking_product` = 0 AND p.`active` = 1 + GROUP BY p.id_product'; + + if (Validate::IsName($this->_sort)) + { + $this->query .= ' ORDER BY `'.bqSQL($this->_sort).'`'; + if (isset($this->_direction) && Validate::isSortDirection($this->_direction)) + $this->query .= ' '.$this->_direction; + } + $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue( + 'SELECT COUNT(p.`id_product`) FROM '._DB_PREFIX_.'product p WHERE p.`booking_product` = 0 AND p.`active` = 1' + ); + + if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) + $this->query .= ' LIMIT '.(int)$this->_start.', '.(int)$this->_limit; + + $values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query); + foreach ($values as &$value) + { + if (!Tools::getValue('export')) { + if ($value['active']) { + $value['active'] = ''.$this->l('Yes').''; + } else { + $value['active'] = ''.$this->l('No').''; + } + if ($value['auto_add_to_cart']) { + $value['auto_add_to_cart'] = ''.$this->l('Yes').''; + } else { + $value['auto_add_to_cart'] = ''.$this->l('No').''; + } + } + $value['avgPriceSold'] = Tools::displayPrice($value['avgPriceSold'], $currency); + $value['totalPriceSold'] = Tools::displayPrice($value['totalPriceSold'], $currency); + } + unset($value); + + $this->_values = $values; + } +} diff --git a/modules/statsserviceproducts/views/index.php b/modules/statsserviceproducts/views/index.php new file mode 100644 index 000000000..7a7f9721e --- /dev/null +++ b/modules/statsserviceproducts/views/index.php @@ -0,0 +1,29 @@ +{$module_name} +{$grid_table} + + {l s='CSV Export' mod='statsserviceproducts'} + \ No newline at end of file diff --git a/modules/statsserviceproducts/views/templates/index.php b/modules/statsserviceproducts/views/templates/index.php new file mode 100644 index 000000000..7a7f9721e --- /dev/null +++ b/modules/statsserviceproducts/views/templates/index.php @@ -0,0 +1,29 @@ +