diff --git a/admin-dev/themes/default/css/admin-theme.css b/admin-dev/themes/default/css/admin-theme.css index 107f0458e..90d3b31e0 100644 --- a/admin-dev/themes/default/css/admin-theme.css +++ b/admin-dev/themes/default/css/admin-theme.css @@ -10317,7 +10317,10 @@ li.sortable-placeholder { /* line 158, admin-theme/_admin-dashboard.sass */ #dashboard #dashtrends svg { height: 350px; } -/* line 163, admin-theme/_admin-dashboard.sass */ +/* line 162, admin-theme/_admin-dashboard.sass */ +#dashboard #dashgoals svg { + height: 250px; } +/* line 167, admin-theme/_admin-dashboard.sass */ #dashboard #dashaddons { background-color: white; border: 1px dashed #dfdfdf; @@ -10327,33 +10330,33 @@ li.sortable-placeholder { -o-border-radius: 3px; border-radius: 3px; padding: 10px 20px; } -/* line 167, admin-theme/_admin-dashboard.sass */ +/* line 171, admin-theme/_admin-dashboard.sass */ #dashboard #dashaddons a { display: block; } -/* line 169, admin-theme/_admin-dashboard.sass */ +/* line 173, admin-theme/_admin-dashboard.sass */ #dashboard #dashaddons a:hover { text-decoration: none; } -/* line 174, admin-theme/_admin-dashboard.sass */ +/* line 178, admin-theme/_admin-dashboard.sass */ #dashboard #dashactivity svg { height: 150px; } -/* line 181, admin-theme/_admin-dashboard.sass */ +/* line 185, admin-theme/_admin-dashboard.sass */ #dashboard .loading .data_value { min-width: 30px; text-align: center; } -/* line 184, admin-theme/_admin-dashboard.sass */ +/* line 188, admin-theme/_admin-dashboard.sass */ #dashboard .loading .data_value:before { font-size: 0.7em; font-family: FontAwesome; content: "\f021"; color: #cccccc; } -/* line 190, admin-theme/_admin-dashboard.sass */ +/* line 194, admin-theme/_admin-dashboard.sass */ #dashboard .loading .data_value span, #dashboard .loading .data_value small { display: none; } -/* line 192, admin-theme/_admin-dashboard.sass */ +/* line 196, admin-theme/_admin-dashboard.sass */ #dashboard .loading .data_trend { display: none; } -/* line 217, admin-theme/_admin-dashboard.sass */ +/* line 221, admin-theme/_admin-dashboard.sass */ .data_loading, #dashboard .data_value span, #dashboard .data_value .dash_trend { opacity: 1; -webkit-animation-name: bounceG; @@ -10367,7 +10370,7 @@ li.sortable-placeholder { transform: scale(0.7); } @-webkit-keyframes bounceG { - /* line 225, admin-theme/_admin-dashboard.sass */ + /* line 229, admin-theme/_admin-dashboard.sass */ 0% { opacity: 0; filter: alpha(opacity=0); @@ -10375,7 +10378,7 @@ li.sortable-placeholder { -ms-transform: scale(0.1); transform: scale(0.1); } - /* line 228, admin-theme/_admin-dashboard.sass */ + /* line 232, admin-theme/_admin-dashboard.sass */ 100% { opacity: 1; filter: alpha(opacity=100); @@ -10384,7 +10387,7 @@ li.sortable-placeholder { transform: scale(1); } } @-moz-keyframes bounceG { - /* line 225, admin-theme/_admin-dashboard.sass */ + /* line 229, admin-theme/_admin-dashboard.sass */ 0% { opacity: 0; filter: alpha(opacity=0); @@ -10392,7 +10395,7 @@ li.sortable-placeholder { -ms-transform: scale(0.1); transform: scale(0.1); } - /* line 228, admin-theme/_admin-dashboard.sass */ + /* line 232, admin-theme/_admin-dashboard.sass */ 100% { opacity: 1; filter: alpha(opacity=100); @@ -10401,7 +10404,7 @@ li.sortable-placeholder { transform: scale(1); } } @-ms-keyframes bounceG { - /* line 225, admin-theme/_admin-dashboard.sass */ + /* line 229, admin-theme/_admin-dashboard.sass */ 0% { opacity: 0; filter: alpha(opacity=0); @@ -10409,7 +10412,7 @@ li.sortable-placeholder { -ms-transform: scale(0.1); transform: scale(0.1); } - /* line 228, admin-theme/_admin-dashboard.sass */ + /* line 232, admin-theme/_admin-dashboard.sass */ 100% { opacity: 1; filter: alpha(opacity=100); @@ -10418,7 +10421,7 @@ li.sortable-placeholder { transform: scale(1); } } @-o-keyframes bounceG { - /* line 225, admin-theme/_admin-dashboard.sass */ + /* line 229, admin-theme/_admin-dashboard.sass */ 0% { opacity: 0; filter: alpha(opacity=0); @@ -10426,7 +10429,7 @@ li.sortable-placeholder { -ms-transform: scale(0.1); transform: scale(0.1); } - /* line 228, admin-theme/_admin-dashboard.sass */ + /* line 232, admin-theme/_admin-dashboard.sass */ 100% { opacity: 1; filter: alpha(opacity=100); @@ -10435,7 +10438,7 @@ li.sortable-placeholder { transform: scale(1); } } @keyframes bounceG { - /* line 225, admin-theme/_admin-dashboard.sass */ + /* line 229, admin-theme/_admin-dashboard.sass */ 0% { opacity: 0; filter: alpha(opacity=0); @@ -10443,7 +10446,7 @@ li.sortable-placeholder { -ms-transform: scale(0.1); transform: scale(0.1); } - /* line 228, admin-theme/_admin-dashboard.sass */ + /* line 232, admin-theme/_admin-dashboard.sass */ 100% { opacity: 1; filter: alpha(opacity=100); @@ -10451,11 +10454,11 @@ li.sortable-placeholder { -ms-transform: scale(1); transform: scale(1); } } -/* line 232, admin-theme/_admin-dashboard.sass */ +/* line 236, admin-theme/_admin-dashboard.sass */ #dash_version { padding: 0 !important; overflow: hidden; } -/* line 236, admin-theme/_admin-dashboard.sass */ +/* line 240, admin-theme/_admin-dashboard.sass */ #dash_version iframe { height: 80px; width: 100%; } diff --git a/admin-dev/themes/default/css/admin-theme/_admin-dashboard.sass b/admin-dev/themes/default/css/admin-theme/_admin-dashboard.sass index ab12f442d..f9538ca27 100644 --- a/admin-dev/themes/default/css/admin-theme/_admin-dashboard.sass +++ b/admin-dev/themes/default/css/admin-theme/_admin-dashboard.sass @@ -157,6 +157,10 @@ font: 300 1.1em/120% $headings-font-family svg height: 350px + + #dashgoals + svg + height: 250px #dashproducts diff --git a/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl b/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl index 558b1f23f..9258bedb1 100644 --- a/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl +++ b/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl @@ -86,7 +86,7 @@
{$hookDashboardZoneTwo} -
+
{l s='Add more graph and data'} @@ -139,4 +139,4 @@ $('#date-end').focus(); }); }); - \ No newline at end of file + diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index ab7692a6c..810e06dfd 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -28,16 +28,22 @@ class AdminStatsControllerCore extends AdminStatsTabController { public static function getVisits($unique = false, $date_from, $date_to, $granularity = false) { - $visits = array(); + $visits = ($granularity == false) ? 0 : array(); $gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false; if (Validate::isLoadedObject($gapi) && $gapi->isConfigured()) { $metric = $unique ? 'visitors' : 'visits'; - if ($result = $gapi->requestReportData($granularity ? 'ga:date' : '', 'ga:'.$metric, $date_from, $date_to, null, null, 1, 30)) + if ($result = $gapi->requestReportData($granularity ? 'ga:date' : '', 'ga:'.$metric, $date_from, $date_to, null, null, 1, 5000)) foreach ($result as $row) if ($granularity == 'day') $visits[strtotime(preg_replace('/^([0-9]{4})([0-9]{2})([0-9]{2})$/', '$1-$2-$3', $row['dimensions']['date']))] = $row['metrics'][$metric]; - elseif ($granularity == false) + elseif ($granularity == 'month') + { + if (!isset($visits[strtotime(preg_replace('/^([0-9]{4})([0-9]{2})([0-9]{2})$/', '$1-$2-01', $row['dimensions']['date']))])) + $visits[strtotime(preg_replace('/^([0-9]{4})([0-9]{2})([0-9]{2})$/', '$1-$2-01', $row['dimensions']['date']))] = 0; + $visits[strtotime(preg_replace('/^([0-9]{4})([0-9]{2})([0-9]{2})$/', '$1-$2-01', $row['dimensions']['date']))] += $row['metrics'][$metric]; + } + else $visits = $row['metrics'][$metric]; } else @@ -53,6 +59,17 @@ class AdminStatsControllerCore extends AdminStatsTabController foreach ($result as $row) $visits[strtotime($row['date'])] = $row['visits']; } + elseif ($granularity == 'month') + { + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' + SELECT LEFT(`date_add`, 7) as date, COUNT('.($unique ? 'DISTINCT id_guest' : '*').') as visits + FROM `'._DB_PREFIX_.'connections` + WHERE `date_add` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" + '.Shop::addSqlRestriction().' + GROUP BY LEFT(`date_add`, 7)'); + foreach ($result as $row) + $visits[strtotime($row['date'].'-01')] = $row['visits']; + } else $visits = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT COUNT('.($unique ? 'DISTINCT id_guest' : '*').') as visits @@ -160,6 +177,19 @@ class AdminStatsControllerCore extends AdminStatsTabController $sales[strtotime($row['date'])] = $row['sales']; return $sales; } + elseif ($granularity == 'month') + { + $sales = array(); + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' + SELECT LEFT(`invoice_date`, 7) as date, SUM(total_paid_tax_excl / o.conversion_rate) as sales + FROM `'._DB_PREFIX_.'orders` o + WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" + '.Shop::addSqlRestriction(false, 'o').' + GROUP BY LEFT(`invoice_date`, 7)'); + foreach ($result as $row) + $sales[strtotime($row['date'].'-01')] = $row['sales']; + return $sales; + } else return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT SUM(total_paid_tax_excl / o.conversion_rate) @@ -220,6 +250,19 @@ class AdminStatsControllerCore extends AdminStatsTabController $orders[strtotime($row['date'])] = $row['orders']; return $orders; } + elseif ($granularity == 'month') + { + $orders = array(); + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' + SELECT LEFT(`invoice_date`, 7) as date, COUNT(*) as orders + FROM `'._DB_PREFIX_.'orders` + WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" + '.Shop::addSqlRestriction(false).' + GROUP BY LEFT(`invoice_date`, 7)'); + foreach ($result as $row) + $orders[strtotime($row['date'].'-01')] = $row['orders']; + return $orders; + } else $orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT COUNT(*) as orders diff --git a/install-dev/models/install.php b/install-dev/models/install.php index 189189485..784b30f04 100644 --- a/install-dev/models/install.php +++ b/install-dev/models/install.php @@ -540,6 +540,7 @@ class InstallModelInstall extends InstallAbstractModel 'cheque', 'dashactivity', 'dashtrends', + 'dashgoals', 'dashproducts', 'favoriteproducts', 'graphartichow', diff --git a/install-dev/upgrade/sql/1.6.0.1.sql b/install-dev/upgrade/sql/1.6.0.1.sql index ba5833bd6..0b1c17791 100644 --- a/install-dev/upgrade/sql/1.6.0.1.sql +++ b/install-dev/upgrade/sql/1.6.0.1.sql @@ -35,14 +35,14 @@ UPDATE `PREFIX_configuration` SET `value`='-' WHERE `name` = 'PS_ATTRIBUTE_ANCHO UPDATE `PREFIX_tab` SET class_name = 'AdminDashboard', id_parent = 0, active = 1, module = "" WHERE class_name = 'AdminHome'; INSERT INTO `PREFIX_module` (`name`, `active`, `version`) -VALUES ('dashactivity', '1', '0.1'), ('dashtrends', '1', '0.1'), ('dashproducts', '1', '0.1'); +VALUES ('dashactivity', '1', '0.1'),('dashtrends', '1', '0.1'),('dashgoals', '1', '0.1'),('dashproducts', '1', '0.1'); INSERT INTO `PREFIX_module_access` (`id_profile`, `id_module`, `view`, `configure`) ( - SELECT p.id_profile, m.id_module, 1, 1 FROM `PREFIX_module` m, `PREFIX_profile` p WHERE m.name IN ('dashactivity', 'dashtrends', 'dashproducts') + SELECT p.id_profile, m.id_module, 1, 1 FROM `PREFIX_module` m, `PREFIX_profile` p WHERE m.name IN ('dashactivity', 'dashtrends', 'dashgoals', 'dashproducts') ); INSERT INTO `PREFIX_module_shop` (`id_module`, `id_shop`) ( - SELECT m.id_module, s.id_shop FROM `PREFIX_module` m, `PREFIX_shop` s WHERE m.name IN ('dashactivity', 'dashtrends', 'dashproducts') + SELECT m.id_module, s.id_shop FROM `PREFIX_module` m, `PREFIX_shop` s WHERE m.name IN ('dashactivity', 'dashtrends', 'dashgoals', 'dashproducts') ); INSERT INTO `PREFIX_hook` (`name`, `title`, `position`, `live_edit`) VALUES @@ -60,7 +60,10 @@ INSERT INTO `PREFIX_hook_module` (`id_module`, `id_shop`, `id_hook`, `position`) SELECT m.id_module, s.id_shop, h.id_hook, 1 FROM `PREFIX_module` m, `PREFIX_shop` s, `PREFIX_hook` h WHERE m.name IN ('dashtrends') AND h.name IN ('dashboardZoneTwo') ); INSERT INTO `PREFIX_hook_module` (`id_module`, `id_shop`, `id_hook`, `position`) ( - SELECT m.id_module, s.id_shop, h.id_hook, 2 FROM `PREFIX_module` m, `PREFIX_shop` s, `PREFIX_hook` h WHERE m.name IN ('dashproducts') AND h.name IN ('dashboardZoneTwo') + SELECT m.id_module, s.id_shop, h.id_hook, 2 FROM `PREFIX_module` m, `PREFIX_shop` s, `PREFIX_hook` h WHERE m.name IN ('dashgoals') AND h.name IN ('dashboardZoneTwo') +); +INSERT INTO `PREFIX_hook_module` (`id_module`, `id_shop`, `id_hook`, `position`) ( + SELECT m.id_module, s.id_shop, h.id_hook, 3 FROM `PREFIX_module` m, `PREFIX_shop` s, `PREFIX_hook` h WHERE m.name IN ('dashproducts') AND h.name IN ('dashboardZoneTwo') ); /* PHP:update_order_messages(); */; diff --git a/modules/dashgoals/dashgoals.php b/modules/dashgoals/dashgoals.php index 1c5eb26d9..9d6d57c9b 100644 --- a/modules/dashgoals/dashgoals.php +++ b/modules/dashgoals/dashgoals.php @@ -29,6 +29,9 @@ if (!defined('_PS_VERSION_')) class Dashgoals extends Module { + protected static $month_labels = array(); + protected static $types = array('traffic', 'conversion', 'avg_cart_value'); + public function __construct() { $this->name = 'dashgoals'; @@ -38,6 +41,21 @@ class Dashgoals extends Module $this->author = 'PrestaShop'; parent::__construct(); + + Dashgoals::$month_labels = array( + '01' => $this->l('January'), + '02' => $this->l('February'), + '03' => $this->l('March'), + '04' => $this->l('April'), + '05' => $this->l('May'), + '06' => $this->l('June'), + '07' => $this->l('July'), + '08' => $this->l('August'), + '09' => $this->l('September'), + '10' => $this->l('October'), + '11' => $this->l('November'), + '12' => $this->l('December') + ); } public function install() @@ -59,37 +77,62 @@ class Dashgoals extends Module public function hookDashboardZoneTwo($params) { $year = date('Y'); - $this->context->smarty->assign('goals_months', array( - '01_'.$year => sprintf($this->l('January, %s'), $year), - '02_'.$year => sprintf($this->l('February, %s'), $year), - '03_'.$year => sprintf($this->l('March, %s'), $year), - '04_'.$year => sprintf($this->l('April, %s'), $year), - '05_'.$year => sprintf($this->l('May, %s'), $year), - '06_'.$year => sprintf($this->l('June, %s'), $year), - '07_'.$year => sprintf($this->l('July, %s'), $year), - '08_'.$year => sprintf($this->l('August, %s'), $year), - '09_'.$year => sprintf($this->l('September, %s'), $year), - '10_'.$year => sprintf($this->l('October, %s'), $year), - '11_'.$year => sprintf($this->l('November, %s'), $year), - '12_'.$year => sprintf($this->l('December, %s'), $year), - )); + $months = array(); + for ($i = '01'; $i <= 12; $i = sprintf('%02d', $i + 1)) + $months[$i.'_'.$year] = array('label' => Dashgoals::$month_labels[$i], 'values' => array()); + + foreach (Dashgoals::$types as $type) + foreach ($months as $month => &$month_row) + { + $key = 'dashgoals_'.$type.'_'.$month; + if (Tools::isSubmit('submitDashGoals')) + ConfigurationKPI::updateValue(strtoupper($key), (float)Tools::getValue($key)); + $month_row['values'][$type] = ConfigurationKPI::get(strtoupper($key)); + } + + $this->context->smarty->assign('currency_code', $this->context->currency->iso_code); + $this->context->smarty->assign('goals_year', $year); + $this->context->smarty->assign('goals_months', $months); return $this->display(__FILE__, 'dashboard_zone_two.tpl'); } public function hookDashboardData($params) { - return array(); - // 'data_chart' => array('dash_goals_chart1' => $this->getChartData()), - // ); + return array('data_chart' => array('dash_goals_chart1' => $this->getChartData())); } public function getChartData() { - return array(); - } + $year = date('Y'); - public function renderConfigForm() - { + $visits = AdminStatsController::getVisits(false, date('Y-01-01'), date('Y-12-31'), 'month'); + $orders = AdminStatsController::getOrders(date('Y-01-01'), date('Y-12-31'), 'month'); + $sales = AdminStatsController::getTotalSales(date('Y-01-01'), date('Y-12-31'), 'month'); + $stream1 = array('key' => $this->l('Traffic'), 'values' => array()); + $stream2 = array('key' => $this->l('Conversion Rate'), 'values' => array()); + $stream3 = array('key' => $this->l('Average Cart Value'), 'values' => array()); + + for ($i = '01'; $i <= 12; $i = sprintf('%02d', $i + 1)) + { + $timestamp = strtotime($year.'-'.$i.'-01'); + + $goal = ConfigurationKPI::get(strtoupper('dashgoals_traffic_'.$i.'_'.$year)); + $stream1['values'][] = array('x' => Dashgoals::$month_labels[$i], 'y' => ($goal ? $visits[$timestamp] / $goal : 0)); + + $goal = ConfigurationKPI::get(strtoupper('dashgoals_conversion_'.$i.'_'.$year)); + $value = 0; + if ($goal && isset($visits[$timestamp]) && $visits[$timestamp] && isset($orders[$timestamp]) && $orders[$timestamp]) + $value = (100 * $orders[$timestamp] / $visits[$timestamp]) / $goal; + $stream2['values'][] = array('x' => Dashgoals::$month_labels[$i], 'y' => $value); + + $goal = ConfigurationKPI::get(strtoupper('dashgoals_avg_cart_value_'.$i.'_'.$year)); + $value = 0; + if ($goal && isset($orders[$timestamp]) && $orders[$timestamp] && isset($sales[$timestamp]) && $sales[$timestamp]) + $value = ($sales[$timestamp] / $orders[$timestamp]) / $goal; + $stream3['values'][] = array('x' => Dashgoals::$month_labels[$i], 'y' => $value); + } + + return array('chart_type' => 'bar_chart_goals', 'data' => array($stream1, $stream2, $stream3)); } } \ No newline at end of file diff --git a/modules/dashgoals/views/js/dashgoals.js b/modules/dashgoals/views/js/dashgoals.js index 7b19c060e..6bd077007 100644 --- a/modules/dashgoals/views/js/dashgoals.js +++ b/modules/dashgoals/views/js/dashgoals.js @@ -1,38 +1,36 @@ -function line_chart_goals(widget_name, chart_details) +function bar_chart_goals(widget_name, chart_details) { - nv.addGraph(function() { - var chart = nv.models.lineChart() - .useInteractiveGuideline(true) - .x(function(d) { return d[0] }) - .y(function(d) { return d[1]/100 }) - .color(d3.scale.category10().range()); - - chart.xAxis - .tickFormat(function(d) { - return d3.time.format('%m/%d/%y')(new Date(d)) - }); - - chart.yAxis - .tickFormat(d3.format(',.1%')); + nv.addGraph(function() { + var chart = nv.models.multiBarChart(); + + chart.yAxis.tickFormat(d3.format('%')); d3.select('#dash_goals_chart1 svg') .datum(chart_details.data) + .transition() .call(chart); + nv.utils.windowResize(chart.update); return chart; }); } +function dashgoals_calc_sales() +{ + $('.dashgoals_sales').each(function() { + var key = $(this).attr('id').substr(16); + var sales = parseFloat($('#dashgoals_traffic_' + key).val()) * parseFloat($('#dashgoals_avg_cart_value_' + key).val()) * parseFloat($('#dashgoals_conversion_' + key).val()) / 100; + if (isNaN(sales)) + $(this).text('0'); + else + $(this).text(parseInt(sales)); + }); +} + $(document).ready(function() { $('.dashgoals_config_input').keyup(function() { - $('.dashgoals_sales').each(function() { - var key = $(this).attr('id').substr(16); - var sales = parseFloat($('#dashgoals_traffic_' + key).val()) * parseFloat($('#dashgoals_average_cart_value_' + key).val()) * parseFloat($('#dashgoals_conversion_rate_' + key).val()) / 100; - if (isNaN(sales)) - $(this).text('0'); - else - $(this).text(parseInt(sales)); - }); + dashgoals_calc_sales(); }); -}); \ No newline at end of file + dashgoals_calc_sales(); +}); diff --git a/modules/dashgoals/views/templates/hook/dashboard_zone_two.tpl b/modules/dashgoals/views/templates/hook/dashboard_zone_two.tpl index 1e361cd00..de339dcea 100644 --- a/modules/dashgoals/views/templates/hook/dashboard_zone_two.tpl +++ b/modules/dashgoals/views/templates/hook/dashboard_zone_two.tpl @@ -35,32 +35,53 @@ -
+
{l s='Configuration' mod='dashgoals'}
- - - - - - - - - - - - {foreach $goals_months as $month} - - - - - - - - {/foreach} - -
-{l s='Traffic' mod='dashgoals'}{l s='Conversion Rate' mod='dashgoals'}{l s='Average Cart Value' mod='dashgoals'}{l s='Sales' mod='dashgoals'}
{$month}0
+
+ + + + + + + + + + + + {foreach $goals_months as $month} + + + + + + + + {/foreach} + +
{$goals_year}{l s='Traffic' mod='dashgoals'}{l s='Conversion Rate' mod='dashgoals'}{l s='Average Cart Value' mod='dashgoals'}{l s='Sales' mod='dashgoals'}
+ {$month.label} + + + +
+ + % +
+
+
+ {$currency_code|escape} + +
+
+
+ +
-
+