* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 8943 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminHome extends AdminTab { public function postProcess() { } private function _displayOptimizationTips() {} public function display() { global $cookie; $this->warnDomainName(); $tab = get_class(); $protocol = Tools::usingSecureMode()?'https':'http'; $isoDefault = Language::getIsoById(intval(Configuration::get('PS_LANG_DEFAULT'))); $isoUser = Language::getIsoById(intval($cookie->id_lang)); $isoCountry = Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT')); $currency = new Currency((int)(Configuration::get('PS_CURRENCY_DEFAULT'))); $employee = new Employee($cookie->id_employee); echo '

'.$this->l('Dashboard').'


'; echo '
'; // echo ' //
// // '; $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 '

Dernière mise à jour : ' . $stats['date_upd'] . '

'; 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\''); $result3 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT SUM(pv.`counter`) AS total_viewed FROM `'._DB_PREFIX_.'page_viewed` pv LEFT JOIN `'._DB_PREFIX_.'date_range` dr ON pv.`id_date_range` = dr.`id_date_range` LEFT JOIN `'._DB_PREFIX_.'page` p ON pv.`id_page` = p.`id_page` LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type` WHERE pt.`name` = \'product.php\' AND dr.`time_start` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\' AND dr.`time_end` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\''); $results = array_merge($result, array_merge($result2, $result3)); echo '
'.$this->l('View more').' '.$this->l('Monthly Statistics').'
'.$this->l('Sales').' '.Tools::displayPrice($results['total_sales'], $currency).'
'.$this->l('Total registrations').' '.(int)($results['total_registrations']).'
'.$this->l('Total orders').' '.(int)($results['total_orders']).'
'.$this->l('Product pages viewed').' '.(int)($results['total_viewed']).'
'; $all = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'customer_thread'); $unread = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'customer_thread` WHERE `status` = "open"'); $pending = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'customer_thread` WHERE `status` LIKE "%pending%"'); $close = $all - ($unread + $pending); echo '
'.$this->l('View more').' '.$this->l('Customers service').'
'.$this->l('Thread unread').' '.$unread.'
'.$this->l('Thread pending').' '.$pending.'
'.$this->l('Thread closed').' '.$close.'
'.$this->l('Total thread').' '.$all.'
'.$this->l('View more').' '.$this->l('Statistics').' / '.$this->l('Sales of the week').'
'; define('PS_BASE_URI', __PS_BASE_URI__); $chart = new Chart(); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT total_paid / conversion_rate as total_converted, invoice_date FROM '._DB_PREFIX_.'orders o WHERE valid = 1 AND invoice_date BETWEEN \''.date('Y-m-d', strtotime('-7 DAYS', time())).' 00:00:00\' AND \''.date('Y-m-d H:i:s').'\''); foreach ($result as $row) $chart->getCurve(1)->setPoint(strtotime($row['invoice_date']), $row['total_converted']); $chart->setSize(580, 170); $chart->setTimeMode(strtotime('-7 DAYS', time()), time(), 'd'); $chart->getCurve(1)->setLabel($this->l('Sales +Tx').' ('.strtoupper($currency->iso_code).')'); $chart->display(); echo '
'; $orders = Order::getOrdersWithInformations(10); $i = 0; foreach ($orders AS $order) { $currency = Currency::getCurrency((int)$order['id_currency']); echo ' '; $i++; } echo '
'.$this->l('ID').' '.$this->l('Customer Name').' '.$this->l('Status').' '.$this->l('Total').' '.$this->l('Action').'
'.(int)$order['id_order'].' '.Tools::htmlentitiesUTF8($order['firstname']).' '.Tools::htmlentitiesUTF8($order['lastname']).' '.Tools::htmlentitiesUTF8($order['state_name']).' '.Tools::displayPrice((float)$order['total_paid'], $currency).' '.$this->l('See').'
'; echo Module::hookExec('backOfficeHome'); } }