bebeboutik/modules/privatesales_livestats/privatesales_livestats.php
Srv Bebeboutik 6c0978166c add modules
2016-01-04 12:49:26 +01:00

77 lines
2.4 KiB
PHP

<?php
if(!defined('_PS_VERSION_')) {
exit;
}
class PrivateSales_LiveStats extends Module {
public $_html = '';
function __construct() {
$this->name = 'privatesales_livestats';
$this->tab = 'administration';
$this->version = '1.0';
$this->author = 'Antadis';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Statistics for Private Sales');
$this->description = $this->l('Allows to get daily statistics about Private Sales');
}
function install() {
# Add admin tabs
$tabs_i18n = array(
'fr' => 'Ventes privées',
'en' => 'Private sales',
);
$t = new Tab();
$t->id_parent = (int) Tab::getIdFromClassName('AdminStats');
$t->position = (int) Tab::getNewLastPosition($st->id_parent);
$t->active = TRUE;
$t->module = 'privatesales_livestats';
$t->class_name = 'AdminPrivateSalesLiveStats';
foreach(Language::getLanguages() as $lang) {
if(isset($tabs_i18n[$lang['iso_code']])) {
$t->name[$lang['id_lang']] = $tabs_i18n[$lang['iso_code']];
} else {
$t->name[$lang['id_lang']] = $tabs_i18n['en'];
}
}
$t->save();
return Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesale_livestats` (
`id_sale` INTEGER UNSIGNED NOT NULL,
`day` DATE NOT NULL,
`total_sales_wt` DECIMAL(20, 6) NOT NULL,
`total_products` VARCHAR(64) NOT NULL,
`date_upd` DATETIME NOT NULL,
PRIMARY KEY(`id_sale`, `day`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
') && Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesale_livestats_sale` (
`id_sale` INTEGER UNSIGNED NOT NULL,
`init_stock` INTEGER NOT NULL,
`total_sales_wt` DECIMAL(20, 6) NOT NULL,
`total_products` VARCHAR(64) NOT NULL,
`oos` INTEGER NOT NULL,
`oos_sold` INTEGER NOT NULL,
`warning` TINYINT NOT NULL,
`date_upd` DATETIME NOT NULL,
PRIMARY KEY(`id_sale`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
') && parent::install();
Configuration::updateValue('PRIVATESALES_LIVESTATS_DATE', time());
}
public function uninstall() {
return Db::getInstance()->ExecuteS('DROP TABLE IF EXISTS `'._DB_PREFIX_.'privatesale_livestats`')
&& Db::getInstance()->ExecuteS('DROP TABLE IF EXISTS `'._DB_PREFIX_.'privatesale_livestats_stock`')
&& parent::uninstall();
}
}