Merge branch 'ticket-11985-statLogMR' into develop

This commit is contained in:
Marion Muszynski 2017-06-16 14:20:55 +02:00
commit 2bee96172e
5 changed files with 212 additions and 54 deletions

View File

@ -24,7 +24,7 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
session_start();
define('PS_ADMIN_DIR', getcwd());
include(PS_ADMIN_DIR.'/../config/config.inc.php');
@ -52,6 +52,7 @@ $functionArray = array(
'privatesalesM3' => 'generateInvoicesPDFPrivateM3',
'privatesalesAll' => 'generateInvoicesPDFPrivateSalesAll',
'pendingorders' => 'generatePendingOrdersInvoice',
'privatesalesManyOrders' => 'generateManyInvoicesPDF',
);
foreach ($functionArray as $var => $function)
@ -61,6 +62,17 @@ foreach ($functionArray as $var => $function)
die;
}
function generateManyInvoicesPDF()
{
if (!isset($_SESSION['id_orders']))
die (Tools::displayError('Missing order ID'));
$orders = $_SESSION['id_orders'];
unset($_SESSION['id_orders']);
session_destroy();
PDF::multipleInvoices($orders, false, true, false, true);
}
function generateInvoicePDF()
{
if (!isset($_GET['id_order']))

View File

@ -241,6 +241,25 @@ class AdminAntConfigurations extends AdminTab
HelperFormBootstrap::displayWarning($this->l('Aucun résultat pour cette période'));
}
}
}elseif(Tools::isSubmit('submitOrderPdf')){
if(isset($_FILES['csvfile']) && $_FILES['csvfile']['name'] != '') {
$f = fopen($_FILES['csvfile']['tmp_name'], 'r');
fgetcsv($f, 0, ';');
$i = 1;
$orders = array();
while($line = fgetcsv($f, 0, ';')) {
$i++;
$orders[] = (int) $line[0];
}
if(!empty($orders)) {
session_start();
$_SESSION['id_orders'] = $orders;
Tools::redirectAdmin('pdf.php?privatesalesManyOrders&gift=1&token='.$this->token);
//PDF::multipleInvoices($orders, false, true, false, true);
}
}
}
}
@ -308,8 +327,9 @@ class AdminAntConfigurations extends AdminTab
FROM `'._DB_PREFIX_.'privatesale` p
LEFT JOIN `'._DB_PREFIX_.'category_lang` c ON (c.`id_category` = p.`id_category`)
WHERE c.`id_lang` = '.$cookie->id_lang.'
AND p.`date_start` > "2015-01-01 00:00:00"
AND p.`date_start` > "2017-01-01 00:00:00"
ORDER BY p.`id_sale` DESC
LIMIT 800
') as $row) {
$extrafields = Category::getSalesInfos(array((int) $row['id_category']));
$id_sale_options[] = array(
@ -345,6 +365,9 @@ class AdminAntConfigurations extends AdminTab
<li role="presentation" class="'.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'loyalties'?'active':'').'">
<a href="#loyalties" aria-controls="loyalty" role="tab" data-toggle="tab"><span class="text-rose anticon anticon-star-full"></span> '.$this->l('Suivi crédits fidélités').'</a>
</li>
<li role="presentation" class="'.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'invoices'?'active':'').'">
<a href="#invoices" aria-controls="loyalty" role="tab" data-toggle="tab"><span class="text-rose anticon anticon-file-pdf"></span> '.$this->l('Factures').'</a>
</li>
</ul>
<div class="tab-content">
@ -457,6 +480,34 @@ class AdminAntConfigurations extends AdminTab
</form>
</div>
</div>
<div role="tabpanel" class="tab-pane '.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'invoices'?'active':'').'" id="invoices">
<div class="panel-content">
<h3 class="">'.$this->l('Générer un PDF de plusieurs commandes').'</h3>
<br>
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&tab-pan=invoices" method="post" enctype="multipart/form-data">
<div class="col-md-6 col-md-offset-4">';
$help = '<br>
<p class="help-block">'.$this->l('Format: id_order').'</p>
<p class="help-block">'.$this->l('The subsequent columns and the first line are ignored.').'</p>
';
$input = array(
'type' => 'file',
'label' => $this->l('File:'),
'name' => 'csvfile',
'html' => $help
);
$form .= $helperForm->generateInput($input);
$form .= '
</div>
<div class="clearfix"></div>
<div class="ln_solid"></div>
<div class="form-group text-right">
<button type="submit" class="btn btn-primary" name="submitOrderPdf">'.$this->l('Générer PDF').'</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>

View File

@ -171,32 +171,6 @@ class AdminPrivateSalesLogistique extends AdminTab {
});
</script>';
// $this->html .= '
// <link rel="stylesheet" type="text/css" href="'.__PS_BASE_URI__.'modules/privatesales_logistique/css/chosen.min.css" />
// <link rel="stylesheet" type="text/css" href="'.__PS_BASE_URI__.'modules/privatesales_logistique/css/privatesales_logistique.css" />
// <script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales_logistique/js/jquery-ui-1.8.20.custom.min.js"></script>
// <script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales_logistique/js/jquery-ui-timepicker-addon.js"></script>
// <script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales_logistique/js/chosen.jquery.min.js"></script>
// <script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales_logistique/js/filtre.js"></script>
// <style type="text/css">
// @import url("'.__PS_BASE_URI__.'modules/privatesales/jquery-ui-1.8.20.custom.css");
// </script>
// <script type="text/javascript">
// $(function() {
// $(".chosen-select").chosen(
// {
// allow_single_deselect:true,
// placeholder_text_single : "Choisir une vente",
// no_results_text : "Aucun résultat",
// enable_split_word_search : true,
// search_contains : true,
// }
// );
// });
// </script>';
}
public function _displayAfterContent($helperForm, $option_sales,$option_select_langs)
@ -262,7 +236,7 @@ class AdminPrivateSalesLogistique extends AdminTab {
'</div>
<div class="clearfix"></div>';
$this->html .= '</div>
$this->html .= '
<div class="clearfix"></div>
<div class="ln_solid"></div>
<div class="form-group text-right">

View File

@ -37,13 +37,15 @@ class AdminStatsLogistic extends AdminTab {
$this->date_export_begin = Tools::getValue('date_export_begin', $this->date_export_begin);
$this->date_export_end = Tools::getValue('date_export_end', $this->date_export_end);
$sale_ids = $this->getSales();
if ($sale_ids) {
foreach ($sale_ids as $sale) {
//$ps = new Sale((int)$sale['id_sale']);
//$product_ids = $ps->getProducts();
$product_ids = $this->getProducts((int)$sale['id_sale']);
if(!$product_ids){
continue;
}
$products = $this->getSaleDetails($product_ids);
/*foreach ($products as $key => $product) {
$order_detail_ids[] = (int)$product['id_order_detail'];
@ -86,6 +88,7 @@ class AdminStatsLogistic extends AdminTab {
$result[(int)$sale['id_sale']]['nb_pole_4'] = 0;
$result[(int)$sale['id_sale']]['nb_pole_5'] = 0;
$result[(int)$sale['id_sale']]['nb_pole_6'] = 0;
$result[(int)$sale['id_sale']]['nb_pole_philea'] = 0;
foreach($products as $row) {
if (!in_array((int)$row['id_order'],$id_orders)) {
@ -164,6 +167,9 @@ class AdminStatsLogistic extends AdminTab {
foreach ($shipping_numbers as $id_employee => $value) {
$nb_package += count($value);
switch ($id_employee) {
case '999':
$result[(int)$sale['id_sale']]['nb_pole_philea'] += count($value);
break;
case '52':
$result[(int)$sale['id_sale']]['nb_pole_1'] += count($value);
break;
@ -196,6 +202,7 @@ class AdminStatsLogistic extends AdminTab {
$result[(int)$sale['id_sale']]['nb_pole_4'] = number_format(($result[(int)$sale['id_sale']]['nb_pole_4'] / $nb_package)*100,2);
$result[(int)$sale['id_sale']]['nb_pole_5'] = number_format(($result[(int)$sale['id_sale']]['nb_pole_5'] / $nb_package)*100,2);
$result[(int)$sale['id_sale']]['nb_pole_6'] = number_format(($result[(int)$sale['id_sale']]['nb_pole_6'] / $nb_package)*100,2);
$result[(int)$sale['id_sale']]['nb_pole_philea'] = number_format(($result[(int)$sale['id_sale']]['nb_pole_philea'] / $nb_package)*100,2);
}
}
if ($result) {
@ -213,11 +220,16 @@ class AdminStatsLogistic extends AdminTab {
} else {
echo '<p class="conf">'.$this->l('No sale found.').'</p>';
}
} elseif (Tools::getValue('submitExportExp')) {
} elseif (Tools::isSubmit('submitExportExpLP') || Tools::isSubmit('submitExportExpMR') || Tools::isSubmit('submitExportExpPH')) {
$this->date_expe_begin = Tools::getValue('date_expe_begin', $this->date_expe_begin);
$this->date_expe_end = Tools::getValue('date_expe_end', $this->date_expe_end);
$details = $this->getShippingDetails();
if(Tools::isSubmit('submitExportExpLP')) {
$details = $this->getShippingDetails();
} elseif(Tools::isSubmit('submitExportExpMR')) {
$details = $this->getShippingMRDetails();
} elseif(Tools::isSubmit('submitExportExpPH')) {
$details = $this->getShippingPhileaDetails();
}
if ($details) {
foreach ($details as $key => &$row) {
$sale_info = $this->getSaleInfo((int)$row['id_sale']);
@ -317,7 +329,7 @@ class AdminStatsLogistic extends AdminTab {
$stats = $this->getStats();
$poles = array();
for ($i=0; $i < 6; $i++) {
for ($i=0; $i < 7; $i++) {
$poles[] = array(
'recap' => array(
'quantity' => 0,
@ -332,12 +344,18 @@ class AdminStatsLogistic extends AdminTab {
$poles[3]['name'] = 'Pôle 4 : Postes complementaires';
$poles[4]['name'] = 'Pôle 5 : Multi';
$poles[5]['name'] = 'Pôle 6 : Autre';
$poles[6]['name'] = 'Pôle Philea';
$total_quantity = 0;
foreach ($stats as $key => $stat) {
if (!isset($stat['id_employee'])) {
continue;
}
switch ($stat['id_employee']) {
switch ((int)$stat['id_employee']) {
case '999':
$poles[6]['recap']['quantity'] += $stat['quantity'];
$poles[6]['recap']['nb_package'] += $stat['nb_package'];
$poles[6]['employee'][] = $stat;
break;
case '52':
$poles[0]['recap']['quantity'] += $stat['quantity'];
$poles[0]['recap']['nb_package'] += $stat['nb_package'];
@ -402,10 +420,10 @@ class AdminStatsLogistic extends AdminTab {
</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['id_employee']==999?"Expe Philéa":$stat['id_employee']).'</td>
<td>'.(isset($stat['firstname'])?$stat['firstname']:"").'</td>
<td>'.(isset($stat['lastname'])?$stat['lastname']:"").'</td>
<td>'.(isset($stat['email'])?$stat['email']:"").'</td>
<td>'.$stat['quantity'].'</td>
<td>'.$stat['nb_package'].'</td>
<td>'. number_format(($stat['nb_package']* 100 / $total_colis), 2) .' %</td>
@ -506,7 +524,7 @@ class AdminStatsLogistic extends AdminTab {
.'</form>
</fieldset>';
echo '<br><br><h2 style="margin-top:15px">Export Expeditions La Poste</h2>
echo '<br><br><h2 style="margin-top:15px">Export Expeditions</h2>
<fieldset>
<p>Exporter le détail des expeditions dont la date est comprise entre : </p>
<form method="POST" action="'.$currentIndex.'" >'
@ -520,7 +538,9 @@ class AdminStatsLogistic extends AdminTab {
.'</span>'
.'<input type="hidden" name="token" value="'.Tools::getAdminTokenLite(__CLASS__).'" />'
.'<input type="hidden" name="tab" value="'.__CLASS__.'" />'
.'<input type="submit" class="button" name="submitExportExp" value="Exporter les Expéditions" />'
.'<input type="submit" class="button" name="submitExportExpLP" value="Expé La Poste" />'
.'<input type="submit" class="button" name="submitExportExpMR" value="Expé Mondial Relay" />'
.'<input type="submit" class="button" name="submitExportExpPH" value="Expé Philéa" />'
.'</form>
</fieldset>'
;
@ -528,7 +548,7 @@ class AdminStatsLogistic extends AdminTab {
}
public function getStats() {
return Db::getInstance()->executeS('
$query1 = Db::getInstance()->executeS('
SELECT
e.`id_employee`,
e.`email`,
@ -540,8 +560,21 @@ class AdminStatsLogistic extends AdminTab {
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).'"
AND e.`id_employee` IS NOT NULL
GROUP BY s.`id_employee`
');
$query2 = Db::getInstance()->executeS('
SELECT
`id_employee`,
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
WHERE s.`date` BETWEEN "'.pSQL($this->date_begin).'" AND "'.pSQL($this->date_end).'"
AND s.`id_employee` = 999
GROUP BY s.`id_employee`
');
return array_merge($query1,$query2);
}
public function getTotalColis() {
@ -573,30 +606,52 @@ class AdminStatsLogistic extends AdminTab {
}
public function getSaleDetails($product_ids) {
return Db::getInstance()->ExecuteS('
$sale_details = array();
$sale_details_lpw = Db::getInstance()->ExecuteS('
SELECT od.*, rr.`id_reason`, pws.`id_employee`, pws.`shipping_number`,
ROUND(((od.`product_price` * (1 - od.`reduction_percent` / 100) - od.`reduction_amount`) * (1 - od.`group_reduction` / 100) * (1 + od.`tax_rate` / 100)), 6) AS `price`
FROM `'._DB_PREFIX_.'order_detail` od
-- LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = od.`id_order`)
LEFT JOIN `'._DB_PREFIX_.'order_slip` os ON (os.`id_order` = od.`id_order`)
LEFT JOIN `'._DB_PREFIX_.'lapostews` pws ON (pws.`id_order_detail` = od.`id_order_detail`)
LEFT JOIN `'._DB_PREFIX_.'refundreason` rr ON (rr.`id_order_slip` = os.`id_order_slip`)
WHERE od.`product_id` IN ('.implode(',', $product_ids).')
-- AND o.`valid` = 1
-- AND od.`product_quantity_refunded`>0
AND pws.id_order_detail IS NOT NULL
ORDER BY rr.`id_reason`');
$sale_details_mr = Db::getInstance()->ExecuteS('
SELECT od.*, rr.`id_reason`, mrp.`id_employee`, mrp.`shipping_number`,
ROUND(((od.`product_price` * (1 - od.`reduction_percent` / 100) - od.`reduction_amount`) * (1 - od.`group_reduction` / 100) * (1 + od.`tax_rate` / 100)), 6) AS `price`
FROM `'._DB_PREFIX_.'order_detail` od
LEFT JOIN `'._DB_PREFIX_.'order_slip` os ON (os.`id_order` = od.`id_order`)
LEFT JOIN `'._DB_PREFIX_.'mondialrelay_parcel` mrp ON (mrp.`id_order_detail` = od.`id_order_detail`)
LEFT JOIN `'._DB_PREFIX_.'refundreason` rr ON (rr.`id_order_slip` = os.`id_order_slip`)
WHERE od.`product_id` IN ('.implode(',', $product_ids).')
AND mrp.id_order_detail IS NOT NULL
ORDER BY rr.`id_reason`
');
$sale_details_ph = Db::getInstance()->ExecuteS('
SELECT od.*, rr.`id_reason`, "999" AS `id_employee`, ph.`shipping_number`,
ROUND(((od.`product_price` * (1 - od.`reduction_percent` / 100) - od.`reduction_amount`) * (1 - od.`group_reduction` / 100) * (1 + od.`tax_rate` / 100)), 6) AS `price`
FROM `'._DB_PREFIX_.'order_detail` od
LEFT JOIN `'._DB_PREFIX_.'order_slip` os ON (os.`id_order` = od.`id_order`)
LEFT JOIN `'._DB_PREFIX_.'philea_parcel` ph ON (ph.`id_order_detail` = od.`id_order_detail`)
LEFT JOIN `'._DB_PREFIX_.'refundreason` rr ON (rr.`id_order_slip` = os.`id_order_slip`)
WHERE od.`product_id` IN ('.implode(',', $product_ids).')
AND ph.id_order_detail IS NOT NULL
ORDER BY rr.`id_reason`
');
$sale_details = array_merge($sale_details_lpw, $sale_details_mr,$sale_details_ph);
return $sale_details;
}
public function getPackageDetails($order_detail_ids) {
public function getPackageDetails($order_detail_ids) {
return Db::getInstance()->ExecuteS('
SELECT pws.`id_order_detail`, pws.`id_employee`, pws.`shipping_number`
FROM `'._DB_PREFIX_.'lapostews` pws
WHERE pws.`id_order_detail` IN ('.implode(',', $order_detail_ids).')
');
}
}
public function getShippingDetails() {
public function getShippingDetails() {
return Db::getInstance()->ExecuteS('
SELECT pws.`id_order_detail`, pws.`shipping_number`, pws.`date_add`, pws.`quantity`, e.`email` AS `poste`, od.`id_order`, od.`product_id`, od.`product_attribute_id`, od.`product_name`, psc.`id_sale`, od.`product_quantity`,
ROUND(((od.`product_price` * (1 - od.`reduction_percent` / 100) - od.`reduction_amount`) * (1 - od.`group_reduction` / 100) * (1 + od.`tax_rate` / 100)), 6) AS `price`
@ -607,7 +662,32 @@ class AdminStatsLogistic extends AdminTab {
WHERE pws.`date_add` BETWEEN "'.pSQL($this->date_expe_begin).'" AND "'.pSQL($this->date_expe_end).'"
ORDER BY pws.`date_add` ASC
');
}
}
public function getShippingMRDetails() {
return Db::getInstance()->ExecuteS('
SELECT pmr.`id_order_detail`, pmr.`shipping_number`, pmr.`date_add`, pmr.`quantity`, e.`email` AS `poste`, od.`id_order`, od.`product_id`, od.`product_attribute_id`, od.`product_name`, psc.`id_sale`, od.`product_quantity`,
ROUND(((od.`product_price` * (1 - od.`reduction_percent` / 100) - od.`reduction_amount`) * (1 - od.`group_reduction` / 100) * (1 + od.`tax_rate` / 100)), 6) AS `price`
FROM `'._DB_PREFIX_.'mondialrelay_parcel` pmr
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = pmr.`id_order_detail`)
LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.`id_employee` = pmr.`id_employee`)
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` psc ON (psc.`id_product` = od.`product_id`)
WHERE pmr.`date_add` BETWEEN "'.pSQL($this->date_expe_begin).'" AND "'.pSQL($this->date_expe_end).'"
ORDER BY pmr.`date_add` ASC
');
}
public function getShippingPhileaDetails() {
return Db::getInstance()->ExecuteS('
SELECT pph.`id_order_detail`, pph.`shipping_number`, pph.`date_add`, pph.`quantity`,"Philéa" AS `poste`, od.`id_order`, od.`product_id`, od.`product_attribute_id`, od.`product_name`, psc.`id_sale`, od.`product_quantity`,
ROUND(((od.`product_price` * (1 - od.`reduction_percent` / 100) - od.`reduction_amount`) * (1 - od.`group_reduction` / 100) * (1 + od.`tax_rate` / 100)), 6) AS `price`
FROM `'._DB_PREFIX_.'philea_parcel` pph
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = pph.`id_order_detail`)
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` psc ON (psc.`id_product` = od.`product_id`)
WHERE pph.`date_add` BETWEEN "'.pSQL($this->date_expe_begin).'" AND "'.pSQL($this->date_expe_end).'"
ORDER BY pph.`date_add` ASC
');
}
public function getSales() {
return Db::getInstance()->ExecuteS('
@ -759,7 +839,8 @@ class AdminStatsLogistic extends AdminTab {
"% colis Pole 3",
"% colis Pole 4",
"% colis Pole 5",
"% colis Pole 6"
"% colis Pole 6",
"% colis Pole Philea"
)
);
fputcsv ($fp,$row_1,$delim);
@ -773,7 +854,7 @@ class AdminStatsLogistic extends AdminTab {
$data[] = $val;
}
} else {
$data[] = $value;
$data[] = $value;
}
}
fputcsv ($fp,array_map('utf8_decode',array_values($data)),$delim);

View File

@ -10,7 +10,7 @@ if (!empty($argv[1])) {
}
Configuration::updateValue('MAJ_STAT_LOGISTIC', date('Y-m-d H:i:s'));
// laposte
$query = '
INSERT INTO `'._DB_PREFIX_.'stats_logistic`
SELECT
@ -28,5 +28,45 @@ $query = '
`quantity` = VALUES(`quantity`),
`nb_package` = VALUES(`nb_package`)
';
Db::getInstance()->execute($query);
// philea
$query = '
INSERT INTO `'._DB_PREFIX_.'stats_logistic`
SELECT
NULL AS `id`,
"999" AS `id_employee`,
`date_add` AS `date`,
COUNT(`id_order_detail`) AS `nb_product`,
SUM(`quantity`) AS `quantity`,
COUNT(DISTINCT `shipping_number`) AS `nb_package`
FROM `'._DB_PREFIX_.'philea_parcel`
WHERE DATE(`date_add`) = "'.pSQL($date).'"
GROUP BY `id_employee` , DATE(`date_add`)
ON DUPLICATE KEY UPDATE
`nb_product` = VALUES(`nb_product`),
`quantity` = VALUES(`quantity`),
`nb_package` = VALUES(`nb_package`)
';
Db::getInstance()->execute($query);
// Mondial relay
$query = '
INSERT INTO `'._DB_PREFIX_.'stats_logistic`
SELECT
NULL AS `id`,
`id_employee` AS `id_employee`,
`date_add` AS `date`,
COUNT(`id_order_detail`) AS `nb_product`,
SUM(`quantity`) AS `quantity`,
COUNT(DISTINCT `shipping_number`) AS `nb_package`
FROM `'._DB_PREFIX_.'mondialrelay_parcel`
WHERE DATE(`date_add`) = "'.pSQL($date).'"
GROUP BY `id_employee` , DATE(`date_add`)
ON DUPLICATE KEY UPDATE
`nb_product` = VALUES(`nb_product`),
`quantity` = VALUES(`quantity`),
`nb_package` = VALUES(`nb_package`)
';
Db::getInstance()->execute($query);