155 lines
5.6 KiB
PHP
155 lines
5.6 KiB
PHP
<?php
|
|
if(!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
|
|
|
|
class ShippingStats extends Module {
|
|
public $_html = '';
|
|
|
|
function __construct() {
|
|
$this->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 = '<h2>'.$this->displayName.'</h2>
|
|
|
|
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/jquery/jquery-ui-1.8.10.custom.min.js"></script>
|
|
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/jquery/datepicker/ui/i18n/ui.datepicker-fr.js"></script>
|
|
<script type="text/javascript">
|
|
<!--
|
|
$(document).ready(function() {
|
|
$("#date_from, #date_to").datepicker({
|
|
prevText:"",
|
|
nextText:"",
|
|
dateFormat:"yy-mm-dd"
|
|
});
|
|
});
|
|
-->
|
|
</script>
|
|
';
|
|
|
|
$this->_html .= '<fieldset>
|
|
<legend>'.$this->l('Date interval').'</legend>
|
|
<p>
|
|
<label for="date_from">'.$this->l('From (included):').'</label>
|
|
<input type="text" id="date_from" value="'.$from.'" />
|
|
</p>
|
|
<p>
|
|
<label for="date_to">'.$this->l('To (included):').'</label>
|
|
<input type="text" id="date_to" value="'.$to.'" />
|
|
</p>
|
|
<p class="submit" style="padding-left: 205px; padding-top: 5px;">
|
|
<a style="cursor: pointer;" class="button" onclick="document.location.href=\''.($standalone? '/modules/shippingstats/showstats.php?id_employee='.(int) Tools::getValue('id_employee').'&token='.Tools::getValue('token'): 'index.php?tab=AdminModules&configure=shippingstats&token='.Tools::getValue('token').'&tab_module=administration&module_name=shippingstats').'&from=\' + $(\'#date_from\').val() + \'&to=\' + $(\'#date_to\').val();">'.$this->l('Submit').'</a>
|
|
</p>
|
|
</fieldset>';
|
|
|
|
$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 .= '<br /><br />
|
|
<table class="std table" style="width: 100%;">
|
|
<tr><th>'.$this->l('Employee').'</th><th>'.$this->l('Parcels sent').'</th><th>'.$this->l('Products sent').'</th><th>'.$this->l('Ratio').'</th></tr>';
|
|
|
|
$total_parcels = 0;
|
|
$total_products = 0;
|
|
|
|
foreach($employees_parcels as $id_employee => $parcels) {
|
|
if($parcels == 0) {
|
|
break;
|
|
}
|
|
|
|
$this->_html .= '<tr><td>'.$employees[$id_employee].'</td><td>'.(int) $parcels.'</td><td>'.(int) $employees_products[$id_employee].'</td><td>'.Tools::ps_round((int) $employees_products[$id_employee] / (int) $parcels, 2).'</td>';
|
|
|
|
$total_parcels += (int) $parcels;
|
|
$total_products += (int) $employees_products[$id_employee];
|
|
}
|
|
|
|
$this->_html .= '
|
|
<tr style="background: #f4e7ca; font-weight: bold;"><td></td><td style="color: #000000;">'.$total_parcels.'</td><td style="color: #000000;">'.$total_products.'</td><td style="color: #000000;">'.Tools::ps_round($total_products / $total_parcels, 2).'</td></tr>
|
|
</table>';
|
|
|
|
$this->_html .= '<br /><br />';
|
|
|
|
return $this->_html;
|
|
}
|
|
}
|