update stat BO
This commit is contained in:
parent
648fe3a508
commit
d5670d941a
@ -48,39 +48,114 @@ class AdminHome extends AdminTab
|
||||
|
||||
echo '<div>
|
||||
<h1>'.$this->l('Dashboard').'</h1>
|
||||
<hr style="background-color: #812143;color: #812143;" />
|
||||
<br />';
|
||||
<hr style="background-color: #812143;color: #812143;" />';
|
||||
echo '</div>';
|
||||
echo '
|
||||
<div id="column_left">
|
||||
<ul class="F_list clearfix">
|
||||
<li id="first_block">
|
||||
<h4><a href="index.php?tab=AdminCatalog&addcategory&token='.Tools::getAdminTokenLite('AdminCatalog').'">'.$this->l('New category').'</a></h4>
|
||||
<p>'.$this->l('Create a new category and organize your products.').'</p>
|
||||
</li>
|
||||
<li id="second_block">
|
||||
<h4><a href="index.php?tab=AdminCatalog&id_category=1&addproduct&token='.Tools::getAdminTokenLite('AdminCatalog').'">'.$this->l('New product').'</a></h4>
|
||||
<p>'.$this->l('Fill up your catalog with new articles and attributes.').'</p>
|
||||
</li>
|
||||
<li id="third_block">
|
||||
<h4><a href="index.php?tab=AdminStats&token='.Tools::getAdminTokenLite('AdminStats').'">'.$this->l('Statistics').'</a></h4>
|
||||
<p>'.$this->l('Manage your activity with a thorough analysis of your e-shop.').'</p>
|
||||
</li>
|
||||
<li id="fourth_block">
|
||||
<h4><a href="index.php?tab=AdminEmployees&addemployee&token='.Tools::getAdminTokenLite('AdminEmployees').'">'.$this->l('New employee').'</a></h4>
|
||||
<p>'.$this->l('Add a new employee account and discharge a part of your duties of shop owner.').'</p>
|
||||
</li>
|
||||
</ul>
|
||||
';
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT SUM(o.`total_paid_real` / o.conversion_rate) as total_sales, COUNT(*) as total_orders
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
WHERE o.valid = 1
|
||||
AND o.`invoice_date` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\' ');
|
||||
// echo '
|
||||
// <div id="column_left">
|
||||
// <ul class="F_list clearfix">
|
||||
// <li id="first_block">
|
||||
// <h4><a href="index.php?tab=AdminCatalog&addcategory&token='.Tools::getAdminTokenLite('AdminCatalog').'">'.$this->l('New category').'</a></h4>
|
||||
// <p>'.$this->l('Create a new category and organize your products.').'</p>
|
||||
// </li>
|
||||
// <li id="second_block">
|
||||
// <h4><a href="index.php?tab=AdminCatalog&id_category=1&addproduct&token='.Tools::getAdminTokenLite('AdminCatalog').'">'.$this->l('New product').'</a></h4>
|
||||
// <p>'.$this->l('Fill up your catalog with new articles and attributes.').'</p>
|
||||
// </li>
|
||||
// <li id="third_block">
|
||||
// <h4><a href="index.php?tab=AdminStats&token='.Tools::getAdminTokenLite('AdminStats').'">'.$this->l('Statistics').'</a></h4>
|
||||
// <p>'.$this->l('Manage your activity with a thorough analysis of your e-shop.').'</p>
|
||||
// </li>
|
||||
// <li id="fourth_block">
|
||||
// <h4><a href="index.php?tab=AdminEmployees&addemployee&token='.Tools::getAdminTokenLite('AdminEmployees').'">'.$this->l('New employee').'</a></h4>
|
||||
// <p>'.$this->l('Add a new employee account and discharge a part of your duties of shop owner.').'</p>
|
||||
// </li>
|
||||
// </ul>
|
||||
// ';
|
||||
|
||||
$result = array('total_sales' => 0.0, 'total_orders' => 0);
|
||||
$stats = Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'configuration`
|
||||
WHERE `name` = "ADMINHOME_STATS"
|
||||
AND `date_upd` > DATE_SUB(NOW(), INTERVAL 2 HOUR)
|
||||
');
|
||||
|
||||
echo '<p>Dernière mise à jour : ' . $stats['date_upd'] . '</p>';
|
||||
|
||||
if($stats) {
|
||||
$stats = explode(';', $stats['value']);
|
||||
$result['total_sales'] = (float) $stats[0];
|
||||
$result['total_orders'] = (int) $stats[1];
|
||||
} else {
|
||||
$stats_id_orders = array();
|
||||
foreach(Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT o.`id_order`, o.`total_paid_real`
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_history` h
|
||||
ON o.`id_order` = h.`id_order`
|
||||
WHERE (h.`id_order_state` = 2
|
||||
OR h.`id_order_state` = 13)
|
||||
AND h.`date_add` >= "'.pSQL(date('Y-m-01 00:00:00')).'"
|
||||
AND h.`date_add` < "'.pSQL(date('Y-m-01 00:00:00', strtotime('next month'))).'"
|
||||
GROUP BY o.`id_order`
|
||||
') as $row) {
|
||||
$result['total_sales'] += (float) $row['total_paid_real'];
|
||||
$result['total_orders']++;
|
||||
$stats_id_orders[] = (int) $row['id_order'];
|
||||
}
|
||||
|
||||
for($i=0, $l=count($stats_id_orders); $i < $l; $i+=2000) {
|
||||
foreach(Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT o.`total_paid_real`
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_history` h
|
||||
ON o.`id_order` = h.`id_order`
|
||||
WHERE (h.`id_order_state` = 2
|
||||
OR h.`id_order_state` = 13)
|
||||
AND h.`date_add` >= "'.pSQL(date('Y-m-01 00:00:00', strtotime('previous month'))).'"
|
||||
AND h.`date_add` < "'.pSQL(date('Y-m-01 00:00:00')).'"
|
||||
AND o.`id_order` IN ('.implode(', ', array_slice($stats_id_orders, $i, 2000)).')
|
||||
GROUP BY o.`id_order`
|
||||
') as $row) {
|
||||
$result['total_sales'] -= (float) $row['total_paid_real'];
|
||||
$result['total_orders']--;
|
||||
}
|
||||
}
|
||||
|
||||
$stats_id_orders = null;
|
||||
$result['total_sales'] -= (float) Db::getInstance()->getValue('
|
||||
SELECT SUM(ROUND((d.product_price * (1 - d.reduction_percent / 100) - d.reduction_amount) * (1 - d.group_reduction / 100) * (1 + d.tax_rate / 100), 2) * sd.`product_quantity`)
|
||||
FROM `'._DB_PREFIX_.'order_detail` d
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_slip_detail` sd
|
||||
ON d.`id_order_detail` = sd.`id_order_detail`
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_slip` s
|
||||
ON sd.`id_order_slip` = s.`id_order_slip`
|
||||
WHERE s.`date_add` >= "'.pSQL(date('Y-m-01 00:00:00')).'"
|
||||
AND s.`date_add` < "'.pSQL(date('Y-m-01 00:00:00', strtotime('next month'))).'"
|
||||
');
|
||||
$result['total_sales'] -= (float) Db::getInstance()->getValue('
|
||||
SELECT SUM(o.`total_shipping`)
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_slip` s
|
||||
ON o.`id_order` = s.`id_order`
|
||||
WHERE s.`date_add` >= "'.pSQL(date('Y-m-01 00:00:00')).'"
|
||||
AND s.`date_add` < "'.pSQL(date('Y-m-01 00:00:00', strtotime('next month'))).'"
|
||||
AND s.`shipping_cost` = 1
|
||||
');
|
||||
|
||||
Configuration::updateValue('ADMINHOME_STATS', $result['total_sales'].';'.$result['total_orders']);
|
||||
}
|
||||
|
||||
// $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
// SELECT SUM(o.`total_paid_real` / o.conversion_rate) as total_sales, COUNT(*) as total_orders
|
||||
// FROM `'._DB_PREFIX_.'orders` o
|
||||
// WHERE o.valid = 1
|
||||
// AND o.`invoice_date` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\' ');
|
||||
|
||||
$result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT COUNT(`id_customer`) AS total_registrations
|
||||
FROM `'._DB_PREFIX_.'customer` c
|
||||
WHERE c.`date_add` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'');
|
||||
WHERE c.`date_add` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'');
|
||||
$result3 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT SUM(pv.`counter`) AS total_viewed
|
||||
FROM `'._DB_PREFIX_.'page_viewed` pv
|
||||
|
Loading…
Reference in New Issue
Block a user