name = 'shippingstats';
$this->tab = 'administration';
$this->version = '1.0';
$this->author = 'Antadis';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Shipping Statistics');
$this->description = $this->l('Shows statistics about shipping per employee');
}
public function getContent($standalone=FALSE) {
$from = Tools::getValue('from', date('Y-m-d'));
$to = Tools::getValue('to', date('Y-m-d'));
$this->_html = '
'.$this->displayName.'
';
$this->_html .= '';
$employees_parcels = array();
$employees_products = array();
$employees = array();
$total_parcels = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_employee`, COUNT(DISTINCT `shipping_number`) AS `total`
FROM `'._DB_PREFIX_.'lapostews` l
WHERE `date_add` >= "'.pSQL($from).' 00:00:00"
AND `date_add` <= "'.pSQL($to).' 23:59:59"
GROUP BY l.`id_employee`
') as $row) {
if(!isset($total_parcels[(int) $row['id_employee']])) {
$total_parcels[(int) $row['id_employee']] = 0;
}
$total_parcels[(int) $row['id_employee']] = (int) $row['total'];
}
foreach(Db::getInstance()->ExecuteS('
SELECT `id_employee`, COUNT(DISTINCT `shipping_number`) AS `total`
FROM `'._DB_PREFIX_.'exapaqws` l
WHERE `date_add` >= "'.pSQL($from).' 00:00:00"
AND `date_add` <= "'.pSQL($to).' 23:59:59"
GROUP BY l.`id_employee`
') as $row) {
if(!isset($total_parcels[(int) $row['id_employee']])) {
$total_parcels[(int) $row['id_employee']] = 0;
}
$total_parcels[(int) $row['id_employee']] = (int) $row['total'];
}
$total_products = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_employee`, SUM(`quantity`) AS `total`
FROM `'._DB_PREFIX_.'lapostews` l
WHERE `date_add` >= "'.pSQL($from).' 00:00:00"
AND `date_add` <= "'.pSQL($to).' 23:59:59"
GROUP BY l.`id_employee`
') as $row) {
if(!isset($total_products[(int) $row['id_employee']])) {
$total_products[(int) $row['id_employee']] = 0;
}
$total_products[(int) $row['id_employee']] = (int) $row['total'];
}
foreach(Db::getInstance()->ExecuteS('
SELECT `id_employee`, SUM(`quantity`) AS `total`
FROM `'._DB_PREFIX_.'exapaqws` l
WHERE `date_add` >= "'.pSQL($from).' 00:00:00"
AND `date_add` <= "'.pSQL($to).' 23:59:59"
GROUP BY l.`id_employee`
') as $row) {
if(!isset($total_products[(int) $row['id_employee']])) {
$total_products[(int) $row['id_employee']] = 0;
}
$total_products[(int) $row['id_employee']] = (int) $row['total'];
}
foreach(Db::getInstance()->ExecuteS('
SELECT `id_employee`, CONCAT(`firstname`, \' \', `lastname`) AS "name"
FROM `'._DB_PREFIX_.'employee`
WHERE `active` = 1
ORDER BY `email`
') as $employee) {
$employees_parcels[$employee['id_employee']] = isset($total_parcels[(int) $employee['id_employee']])? $total_parcels[(int) $employee['id_employee']]: 0;
$employees_products[$employee['id_employee']] = isset($total_products[(int) $employee['id_employee']])? $total_products[(int) $employee['id_employee']]: 0;
$employees[$employee['id_employee']] = $employee['name'];
}
arsort($employees_parcels);
$this->_html .= '
'.$this->l('Employee').' | '.$this->l('Parcels sent').' | '.$this->l('Products sent').' | '.$this->l('Ratio').' |
';
$total_parcels = 0;
$total_products = 0;
foreach($employees_parcels as $id_employee => $parcels) {
if($parcels == 0) {
break;
}
$this->_html .= ''.$employees[$id_employee].' | '.(int) $parcels.' | '.(int) $employees_products[$id_employee].' | '.Tools::ps_round((int) $employees_products[$id_employee] / (int) $parcels, 2).' | ';
$total_parcels += (int) $parcels;
$total_products += (int) $employees_products[$id_employee];
}
$this->_html .= '
| '.$total_parcels.' | '.$total_products.' | '.Tools::ps_round($total_products / $total_parcels, 2).' |
';
$this->_html .= '
';
return $this->_html;
}
}