// Added KPIs in products and categories

This commit is contained in:
Damien Metzger
2013-09-18 13:49:42 +02:00
parent c48f4f5e1b
commit 8a4b24f45e
3 changed files with 113 additions and 0 deletions
@@ -335,6 +335,40 @@ class AdminCategoriesControllerCore extends AdminController
$this->action = 'select_delete';
}
public function renderKpis()
{
$time = time();
$kpis = array();
/* The data generation is located in AdminStatsControllerCore */
$helper = new HelperKpi();
$helper->id = 'box-disabled-categories';
$helper->icon = 'icon-off';
$helper->color = 'color1';
$helper->title = $this->l('Disabled Categories');
if (Configuration::get('PS_KPI_DISABLED_CATS') !== false)
$helper->value = Configuration::get('PS_KPI_DISABLED_CATS');
if (Configuration::get('PS_KPI_DISABLED_CATS_EXPIRE') < $time)
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=disabled_categories';
$kpis[] = $helper->generate();
$helper = new HelperKpi();
$helper->id = 'box-empty-categories';
$helper->icon = 'icon-bookmark-empty';
$helper->color = 'color2';
$helper->title = $this->l('Empty Categories');
if (Configuration::get('PS_KPI_EMPTY_CATS') !== false)
$helper->value = Configuration::get('PS_KPI_EMPTY_CATS');
if (Configuration::get('PS_KPI_EMPTY_CATS_EXPIRE') < $time)
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=empty_categories';
$kpis[] = $helper->generate();
$helper = new HelperKpiRow();
$helper->kpis = $kpis;
return $helper->generate();
}
public function renderForm()
{
$this->initToolbar();
@@ -2287,6 +2287,40 @@ class AdminProductsControllerCore extends AdminController
parent::initContent();
}
public function renderKpis()
{
$time = time();
$kpis = array();
/* The data generation is located in AdminStatsControllerCore */
$helper = new HelperKpi();
$helper->id = 'box-products-stock';
$helper->icon = 'icon-archive';
$helper->color = 'color1';
$helper->title = $this->l('Products in Stock');
if (Configuration::get('PS_KPI_PRODUCTS_STOCK') !== false)
$helper->value = Configuration::get('PS_KPI_PRODUCTS_STOCK');
if (Configuration::get('PS_KPI_PRODUCTS_STOCK_EXPIRE') < $time)
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=products_stock';
$kpis[] = $helper->generate();
$helper = new HelperKpi();
$helper->id = 'box-avg-gross-margin';
$helper->icon = 'icon-tags';
$helper->color = 'color2';
$helper->title = $this->l('Average Gross Margin');
if (Configuration::get('PS_KPI_AVG_GROSS_MARGIN') !== false)
$helper->value = Configuration::get('PS_KPI_AVG_GROSS_MARGIN');
if (Configuration::get('PS_KPI_AVG_GROSS_MARGIN_EXPIRE') < $time)
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=avg_gross_margin';
$kpis[] = $helper->generate();
$helper = new HelperKpiRow();
$helper->kpis = $kpis;
return $helper->generate();
}
public function renderList()
{
$this->addRowAction('edit');
@@ -96,6 +96,51 @@ class AdminStatsControllerCore extends AdminStatsTabController
Configuration::updateValue('PS_KPI_ABANDONED_CARTS_EXPIRE', strtotime('+10 min'));
break;
case 'products_stock':
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT SUM(IF(IFNULL(stock.quantity, 0) > 0, 1, 0)) as stock, COUNT(*) as total
FROM `'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p').'
'.Product::sqlStock('p'));
$value = round($row['total'] ? $row['stock'] / $row['total'] : 0, 2).'%';
Configuration::updateValue('PS_KPI_PRODUCTS_STOCK', $value);
Configuration::updateValue('PS_KPI_PRODUCTS_STOCK_EXPIRE', strtotime('+10 min'));
break;
case 'avg_gross_margin':
$value = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT AVG((product_shop.price - product_shop.wholesale_price) / product_shop.price)
FROM `'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p'));
$value = round(100 * $value, 2).'%';
Configuration::updateValue('PS_KPI_AVG_GROSS_MARGIN', $value);
Configuration::updateValue('PS_KPI_AVG_GROSS_MARGIN_EXPIRE', strtotime('+6 hour'));
break;
case 'disabled_categories':
$value = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'category` c
'.Shop::addSqlAssociation('category', 'c').'
WHERE c.active = 0');
Configuration::updateValue('PS_KPI_DISABLED_CATS', $value);
Configuration::updateValue('PS_KPI_DISABLED_CATS_EXPIRE', strtotime('+2 hour'));
break;
case 'empty_categories':
$total = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'category` c
'.Shop::addSqlAssociation('category', 'c'));
$used = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(DISTINCT cp.id_category)
FROM `'._DB_PREFIX_.'category_product` cp
'.Shop::addSqlAssociation('category', 'cp'));
$value = intval($total - $used);
Configuration::updateValue('PS_KPI_EMPTY_CATS', $value);
Configuration::updateValue('PS_KPI_EMPTY_CATS_EXPIRE', strtotime('+2 hour'));
break;
case 'average_order_value':
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT