2016-01-04 12:49:26 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AdminStatsLogistic extends AdminTab {
|
|
|
|
public function __construct() {
|
|
|
|
$this->table = 'stats_logistic';
|
|
|
|
$this->lang = false;
|
|
|
|
$this->date_begin = date('Y-m-d');
|
|
|
|
$this->date_end = date('Y-m-d');
|
2016-05-20 17:13:05 +02:00
|
|
|
$this->date_stock = date('Y-m-d');
|
2016-01-04 12:49:26 +01:00
|
|
|
|
|
|
|
if (!empty($_GET['date_begin'])) {
|
|
|
|
$this->date_begin = $_GET['date_begin'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($_GET['date_end'])){
|
|
|
|
$this->date_end = $_GET['date_end'];
|
|
|
|
}
|
2016-05-20 17:13:05 +02:00
|
|
|
|
|
|
|
if (!empty($_GET['date_stock'])){
|
|
|
|
$this->date_stock = $_GET['date_stock'];
|
|
|
|
}
|
2016-01-04 12:49:26 +01:00
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function display() {
|
|
|
|
global $currentIndex, $cookie;
|
|
|
|
|
|
|
|
$date = Configuration::get('MAJ_STAT_LOGISTIC');
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<style type="text/css">
|
|
|
|
.ui-datepicker .ui-datepicker-prev span, .ui-datepicker .ui-datepicker-next span {
|
|
|
|
font-size: 0px;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ui-timepicker-div-day {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2016-05-20 17:13:05 +02:00
|
|
|
#date_begin, #date_end, #date_stock {
|
|
|
|
width: 115px;
|
2016-01-04 12:49:26 +01:00
|
|
|
text-align: right;
|
|
|
|
padding: 2px;
|
|
|
|
}
|
|
|
|
label {
|
|
|
|
float: none;
|
|
|
|
display: inline-block;
|
|
|
|
margin-right: 5px;
|
|
|
|
}
|
|
|
|
.button {
|
|
|
|
margin-left: 10px;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
fieldset label {
|
|
|
|
width: 160px;
|
|
|
|
}
|
|
|
|
span.date {
|
|
|
|
margin-left: 30px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales_livestats/jquery-ui-1.8.20.custom.min.js"></script>
|
|
|
|
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales/jquery-ui-timepicker-addon.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(document).ready(function() {
|
2016-05-20 17:13:05 +02:00
|
|
|
$("input[name=date_end], input[name=date_begin], input[name=date_stock]").datepicker({
|
2016-01-04 12:49:26 +01:00
|
|
|
showTime: false,
|
|
|
|
dateFormat: "yy-mm-dd",
|
|
|
|
formattedDate: "yy-mm-dd",
|
|
|
|
maxDate: new Date,
|
|
|
|
minDate: new Date(2014, 1, 1)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales_livestats/jquery-ui-fr.js"></script>';
|
|
|
|
|
|
|
|
echo
|
|
|
|
'<fieldset>
|
|
|
|
<form method="GET" action="'.$currentIndex.'">'
|
|
|
|
.'<span class="form-group">'
|
|
|
|
.'<label style="float: none;" class="control-label" for="date_begin">Date de début :</label>'
|
|
|
|
.'<input type="date" name="date_begin" value="'.pSQl($this->date_begin).'" id="date_begin" class="form-control" />'
|
|
|
|
.'</span>'
|
|
|
|
.'<span class="form-group">'
|
|
|
|
.'<label style="float: none;" class="control-label" for="date_end">Date de fin :</label>'
|
|
|
|
.'<input type="date" name="date_end" value="'.pSQl($this->date_end).'" id="date_end" class="form-control" />'
|
|
|
|
.'</span>'
|
|
|
|
.'<input type="hidden" name="token" value="'.Tools::getAdminTokenLite(__CLASS__).'" />'
|
|
|
|
.'<input type="hidden" name="tab" value="'.__CLASS__.'" />'
|
|
|
|
.'<button type="submit" class="button">Filtrer</button>
|
|
|
|
<span class="date">Dernière mise à jour : <b>'.$date.'</b></span>'
|
|
|
|
.'</form>
|
|
|
|
</fieldset>'
|
|
|
|
;
|
|
|
|
|
|
|
|
$stats = $this->getStats();
|
2016-05-20 15:42:50 +02:00
|
|
|
$poles = array();
|
|
|
|
for ($i=0; $i < 6; $i++) {
|
|
|
|
$poles[] = array(
|
|
|
|
'recap' => array(
|
|
|
|
'quantity' => 0,
|
|
|
|
'nb_package' => 0
|
|
|
|
),
|
|
|
|
'employee' => array(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$poles[0]['name'] = 'Pôle 1 : Petites marques';
|
|
|
|
$poles[1]['name'] = 'Pôle 2 : Marques moyenne';
|
|
|
|
$poles[2]['name'] = 'Pôle 3 : Grosses marques';
|
|
|
|
$poles[3]['name'] = 'Pôle 4 : Postes complementaires';
|
|
|
|
$poles[4]['name'] = 'Pôle 5 : Multi';
|
|
|
|
$poles[5]['name'] = 'Pôle 6 : Autre';
|
|
|
|
foreach ($stats as $key => $stat) {
|
2016-05-20 17:13:05 +02:00
|
|
|
if (!isset($stat['id_employee'])) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-05-20 15:42:50 +02:00
|
|
|
switch ($stat['id_employee']) {
|
|
|
|
case '52':
|
|
|
|
$poles[0]['recap']['quantity'] += $stat['quantity'];
|
|
|
|
$poles[0]['recap']['nb_package'] += $stat['nb_package'];
|
|
|
|
$poles[0]['employee'][] = $stat;
|
|
|
|
break;
|
|
|
|
case '22':
|
|
|
|
case '24':
|
|
|
|
$poles[1]['recap']['quantity'] += $stat['quantity'];
|
|
|
|
$poles[1]['recap']['nb_package'] += $stat['nb_package'];
|
|
|
|
$poles[1]['employee'][] = $stat;
|
|
|
|
break;
|
|
|
|
case '25':
|
|
|
|
case '44':
|
|
|
|
$poles[2]['recap']['quantity'] += $stat['quantity'];
|
|
|
|
$poles[2]['recap']['nb_package'] += $stat['nb_package'];
|
|
|
|
$poles[2]['employee'][] = $stat;
|
|
|
|
break;
|
|
|
|
case '47':
|
|
|
|
case '48':
|
|
|
|
$poles[3]['recap']['quantity'] += $stat['quantity'];
|
|
|
|
$poles[3]['recap']['nb_package'] += $stat['nb_package'];
|
|
|
|
$poles[3]['employee'][] = $stat;
|
|
|
|
break;
|
|
|
|
case '35':
|
|
|
|
case '36':
|
|
|
|
$poles[4]['recap']['quantity'] += $stat['quantity'];
|
|
|
|
$poles[4]['recap']['nb_package'] += $stat['nb_package'];
|
|
|
|
$poles[4]['employee'][] = $stat;
|
|
|
|
break;
|
|
|
|
case '28':
|
2016-05-20 15:45:11 +02:00
|
|
|
default:
|
2016-05-20 15:42:50 +02:00
|
|
|
$poles[5]['recap']['quantity'] += $stat['quantity'];
|
|
|
|
$poles[5]['recap']['nb_package'] += $stat['nb_package'];
|
|
|
|
$poles[5]['employee'][] = $stat;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$total_quantity += $stat['quantity'];
|
|
|
|
}
|
2016-01-04 12:49:26 +01:00
|
|
|
$total_colis = $this->getTotalColis();
|
|
|
|
$total_quantity = 0;
|
|
|
|
echo '
|
|
|
|
<h2 style="margin-top:15px">Stats de la logistique</h2>
|
|
|
|
<table class="table" style="width:100%; margin-top:15px">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Id Employee</th>
|
|
|
|
<th>Prénom</th>
|
|
|
|
<th>Nom</th>
|
|
|
|
<th>Email</th>
|
|
|
|
<th>Quantité</th>
|
|
|
|
<th>Nombre de colis</th>
|
|
|
|
<th>% total</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>';
|
2016-05-20 15:42:50 +02:00
|
|
|
foreach ($poles as $k => $pole) {
|
|
|
|
echo '<tr style="background:#00bbff;">
|
|
|
|
<td colspan="4" style="color:#fff;">'.$pole['name'].'</td>
|
|
|
|
<td style="color:#fff;">'.$pole['recap']['quantity'].'</td>
|
|
|
|
<td style="color:#fff;">'.$pole['recap']['nb_package'].'</td>
|
|
|
|
<td style="color:#fff;">'. number_format(($pole['recap']['nb_package']* 100 / $total_colis), 2) .' %</td>
|
|
|
|
</tr>';
|
|
|
|
foreach ($pole['employee'] as $key => $stat) {
|
|
|
|
echo '<tr>
|
|
|
|
<td>'.$stat['id_employee'].'</td>
|
|
|
|
<td>'.$stat['firstname'].'</td>
|
|
|
|
<td>'.$stat['lastname'].'</td>
|
|
|
|
<td>'.$stat['email'].'</td>
|
|
|
|
<td>'.$stat['quantity'].'</td>
|
|
|
|
<td>'.$stat['nb_package'].'</td>
|
|
|
|
<td>'. number_format(($stat['nb_package']* 100 / $total_colis), 2) .' %</td>
|
|
|
|
</tr>';
|
|
|
|
}
|
2016-01-04 12:49:26 +01:00
|
|
|
}
|
|
|
|
echo '<tbody>
|
|
|
|
<tfoot style="font-weight:bold">
|
|
|
|
<tr>
|
|
|
|
<td colspan="4">Total :</td>
|
|
|
|
<td style="background:#f1f1f1;">'.$total_quantity.'</td>
|
|
|
|
<td style="background:#f1f1f1;">'.$total_colis.'</td>
|
|
|
|
<td style="background:#f1f1f1;">100 %</td>
|
|
|
|
</tr>
|
|
|
|
</tfoot>
|
|
|
|
</table>';
|
2016-05-20 17:13:05 +02:00
|
|
|
|
|
|
|
$reports = array(
|
|
|
|
'25' => array(
|
|
|
|
'name' => 'Nb commandes > 25j',
|
|
|
|
'payment' => $this->getReport(25,2),
|
|
|
|
'partial' => $this->getReport(25,17)
|
|
|
|
),
|
|
|
|
'21' => array(
|
|
|
|
'name' => 'Nb commandes > 21j',
|
|
|
|
'payment' => $this->getReport(21,2),
|
|
|
|
'partial' => $this->getReport(21,17)
|
|
|
|
),
|
|
|
|
'18' => array(
|
|
|
|
'name' => 'Nb commandes > 18j',
|
|
|
|
'payment' => $this->getReport(18,2),
|
|
|
|
'partial' => $this->getReport(18,17)
|
|
|
|
),
|
|
|
|
'2' => array(
|
|
|
|
'name' => 'Nb commandes > 2j',
|
|
|
|
'payment' => $this->getReport(2,2),
|
|
|
|
'partial' => $this->getReport(2,17)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
echo '<br><br><h2 style="margin-top:15px">Report Stock</h2>
|
|
|
|
<fieldset>
|
|
|
|
<form method="GET" action="'.$currentIndex.'">'
|
|
|
|
.'<span class="form-group">'
|
|
|
|
.'<label style="float: none;" class="control-label" for="date_stock">Date :</label>'
|
|
|
|
.'<input type="date" name="date_stock" value="'.pSQl($this->date_stock).'" id="date_stock" class="form-control" />'
|
|
|
|
.'<input type="hidden" name="date_begin" value="'.pSQl($this->date_begin).'" class="form-control" />'
|
|
|
|
.'<input type="hidden" name="date_end" value="'.pSQl($this->date_end).'" class="form-control" />'
|
|
|
|
.'</span>'
|
|
|
|
.'<input type="hidden" name="token" value="'.Tools::getAdminTokenLite(__CLASS__).'" />'
|
|
|
|
.'<input type="hidden" name="tab" value="'.__CLASS__.'" />'
|
|
|
|
.'<button type="submit" class="button">Filtrer</button>'
|
|
|
|
.'</form>
|
|
|
|
</fieldset>'
|
|
|
|
;
|
|
|
|
|
|
|
|
echo '<table class="table" style="width:100%; margin-top:15px">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th colspan="2"></th>
|
|
|
|
<th>Paiement accepté</th>
|
|
|
|
<th>Commande partiellement expédiée</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>';
|
|
|
|
foreach ($reports as $k => $report) {
|
|
|
|
echo '<tr">
|
|
|
|
<td>'.$report['name'].'</td>
|
|
|
|
<td>'.date('Y-m-d', strtotime($this->date_stock. ' - '.$k.' days')).'</td>
|
|
|
|
<td>'.$report['payment'].'</td>
|
|
|
|
<td>'.$report['partial'].'</td>
|
|
|
|
</tr>';
|
|
|
|
}
|
|
|
|
echo '<tbody>
|
|
|
|
</table>';
|
2016-01-04 12:49:26 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getStats() {
|
|
|
|
return Db::getInstance()->executeS('
|
|
|
|
SELECT
|
|
|
|
e.`id_employee`,
|
|
|
|
e.`email`,
|
|
|
|
e.`lastname`,
|
|
|
|
e.`firstname`,
|
|
|
|
SUM(s.`nb_product`) AS `nb_product`,
|
|
|
|
SUM(s.`quantity`) AS `quantity`,
|
|
|
|
SUM(s.`nb_package`) AS `nb_package`
|
|
|
|
FROM `'._DB_PREFIX_.'stats_logistic` s
|
|
|
|
LEFT JOIN `'._DB_PREFIX_.'employee` e USING(`id_employee`)
|
|
|
|
WHERE s.`date` BETWEEN "'.pSQL($this->date_begin).'" AND "'.pSQL($this->date_end).'"
|
|
|
|
GROUP BY s.`id_employee`
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTotalColis() {
|
|
|
|
return Db::getInstance()->getValue('
|
|
|
|
SELECT
|
|
|
|
SUM(s.`nb_package`) AS `nb_package`
|
2016-05-20 17:13:05 +02:00
|
|
|
FROM `'._DB_PREFIX_.'stats_logistic` s
|
|
|
|
WHERE s.`date` BETWEEN "'.pSQL($this->date_begin).'" AND "'.pSQL($this->date_end).'"
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getReport($day = 25, $state = 2) {
|
|
|
|
return Db::getInstance()->getValue('
|
|
|
|
SELECT COUNT(o.`id_order`)
|
|
|
|
FROM `'._DB_PREFIX_.'orders` o
|
2016-05-20 17:39:57 +02:00
|
|
|
WHERE (o.`date_add` BETWEEN DATE_SUB("'.pSQL($this->date_stock).'",INTERVAL '.(int)($day).' DAY) AND DATE_SUB("'.pSQL($this->date_stock).'",INTERVAL '.(int)($day-1).' DAY))
|
|
|
|
-- (o.`date_add` BETWEEN DATE_SUB("'.pSQL($this->date_stock).'",INTERVAL '.(int)$day.' DAY) AND "'.pSQL($this->date_stock).'")
|
2016-05-20 17:13:05 +02:00
|
|
|
AND
|
|
|
|
(
|
|
|
|
SELECT id_order_state
|
|
|
|
FROM '._DB_PREFIX_.'order_history oh
|
|
|
|
WHERE o.id_order = oh.id_order
|
|
|
|
ORDER BY id_order_history DESC
|
|
|
|
LIMIT 1
|
|
|
|
) = '.(int)$state.'
|
2016-01-04 12:49:26 +01:00
|
|
|
');
|
|
|
|
}
|
|
|
|
}
|