privilegedemarque/modules/chronopost/AdminExportChronopost.php
Serveur preprod f0c0c48223 first push
2016-04-14 16:14:31 +02:00

194 lines
7.9 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* MODULE PRESTASHOP OFFICIEL CHRONOPOST
*
* LICENSE : All rights reserved - COPY AND REDISTRIBUTION FORBIDDEN WITHOUT PRIOR CONSENT FROM OXILEO
* LICENCE : Tous droits réservés, le droit d'auteur s'applique - COPIE ET REDISTRIBUTION INTERDITES SANS ACCORD EXPRES D'OXILEO
*
* @author Oxileo SAS <contact@oxileo.eu>
* @copyright 2001-2014 Oxileo SAS
* @license Proprietary - no redistribution without authorization
*/
class AdminExportChronopost extends AdminTab
{
public function __construct()
{
$this->table = 'order';
$this->className = 'AdminExportChronopost';
$this->view = false;
$this->noLink = true;
$this->delete = true;
$this->colorOnBackground = true;
/*
// set default filtering state
if(!isset($_POST) || !array_key_exists('submitFilter', $_POST))
{
$this->_filter=" AND os.`id_order_state` = 3 ";
$_POST['orderFilter_os!id_order_state']='3';
}
*/
$this->_select = '
a.id_order AS id_pdf,
CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`,
osl.`name` AS `osname`,
os.`color`,
IF((SELECT COUNT(so.id_order) FROM `'._DB_PREFIX_.'orders` so WHERE so.id_customer = a.id_customer) > 1, 0, 1) as new,
(SELECT COUNT(od.`id_order`) FROM `'._DB_PREFIX_.'order_detail` od WHERE od.`id_order` = a.`id_order` GROUP BY `id_order`) AS product_number';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`)
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = a.`id_order`)
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`)
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)($this->context->language->id).')';
$this->_where = 'AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`) '
.' AND (a.id_carrier='.((int)Configuration::get('CHRONOPOST_CARRIER_ID'))
.' OR a.id_carrier='.((int)Configuration::get('CHRONORELAIS_CARRIER_ID'))
.' OR a.id_carrier='.((int)Configuration::get('CHRONOEXPRESS_CARRIER_ID'))
.' OR a.id_carrier='.((int)Configuration::get('CHRONO10_CARRIER_ID'))
.' OR a.id_carrier='.((int)Configuration::get('CHRONO18_CARRIER_ID'))
.' OR a.id_carrier='.((int)Configuration::get('CHRONOCLASSIC_CARRIER_ID'))
.') ';
$statesArray = array();
$states = OrderState::getOrderStates((int)($this->context->language->id));
foreach ($states AS $state)
$statesArray[$state['id_order_state']] = $state['name'];
$this->fieldsDisplay = array(
//'id_pdf' => array('title' => $this->l('Export'), 'callback' => 'selectButton', 'orderby' => false, 'search' => false),
'id_order' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'customer' => array('title' => $this->l('Customer'), 'widthColumn' => 160, 'width' => 140, 'filter_key' => 'customer', 'tmpTableFilter' => true),
'total_paid' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'price' => true, 'currency' => true),
'payment' => array('title' => $this->l('Payment'), 'width' => 100),
'osname' => array('title' => $this->l('Status'), 'widthColumn' => 230, 'type' => 'select', 'select' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200),
'date_add' => array('title' => $this->l('Date'), 'width' => 35, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add')
);
parent::__construct();
}
public function display()
{
echo '<style>input.multi { width:20px;text-align:center; }</style>
<script type="text/javascript">
function checkOrdersSelected(e)
{
checkboxes=$("table input[type=checkbox]:checked");
if(checkboxes.length==0)
{
alert("Vous devez sélectionner des commandes pour effectuer un export.");
return false;
}
}
$(function() {
// change actions column
var i=0;
$("table tbody tr td.center:last-child").each(function() {
if(i!=0) {
var orderid=$(this).parent().children();
orderid=$(orderid[0]).children();
orderid=$(orderid[0]).attr("value");
$(this).html(
"<input name=\"multi["+orderid+"]\" class=\"multi multi"+orderid+"\" type=\"text\" value=\"1\"/>"
);
$.get("'._MODULE_DIR_.'/chronopost/async/nblt.php?orderid="+orderid, function(data) {
$("input.multi"+orderid).val(data);
});
}
i+=1;
});
$("table thead tr th:last-child").html("Nb de LT");
// hide errors
$("div.error").remove();
// change deletion button
$("input[name=submitDelorder]").attr("onclick", "");
$("input[name=submitDelorder]").click(checkOrdersSelected);
$("input[name=submitDelorder]").attr("value", "Exporter commandes");
$("input[name=submitDelorder]").css("clear:left;");
// add Chronopost fields
$("input[name=submitDelorder]").before("<input type=\"hidden\" name=\"shared_secret\" value=\"'.Configuration::get('CHRONOPOST_SECRET').'\">",
"<label style=\"display:block;clear:both;margin:5px;padding:2px;text-align:left;float:none\"><input type=\"radio\" name=\"cible\" value=\"CSO\" checked=\"\"> Export vers CSO</label>",
"<label style=\"display:block;clear:both;margin:5px;padding:2px;text-align:left;float:none\"><input type=\"radio\" name=\"cible\" value=\"CSS\"> Export vers CSS</label>",
"<label style=\"display:block;clear:both;margin:5px;padding:2px;text-align:left;float:none\"><input type=\"radio\" name=\"cible\" value=\"PDF\"> Impression des LT en masse</label>"
);
});
</script>';
echo '<h2>Gestion des exports Chronopost</h2>';
echo '<p class="hint" style="display:block;position:relative">Pour effectuer un export, selectionnez vos commandes, le type dexport souhaité puis cliquez sur le bouton “Exporter commandes”.</p><div style="clear:both"><center>';
$this->getList((int)($this->context->language->id), !Tools::getValue($this->table.'Orderby') ? 'date_add' : NULL, !Tools::getValue($this->table.'Orderway') ? 'DESC' : NULL);
$currency = new Currency((int)(Configuration::get('PS_CURRENCY_DEFAULT')));
$this->displayList();
echo '</center></div>';
}
public static function selectButton($id_order, $tr)
{
echo '<input type="checkbox" value="'.$id_order.'" id="exportSelect['.$id_order.']" class="exportSelect"/>';
}
public function deleteSelection($table)
{
switch(Tools::getValue('cible'))
{
case 'CSO':
echo '<div class="warn">Attention, l\'outil ChronoShip Office (CSO) ne permet pas l\'édition de lettres de transport utilisant le service Chrono Relais par intégration de fichier.</div>';
case 'CSS':
echo '<script type="text/javascript">
setTimeout("delayer()", 1000);
function delayer() {
window.location = "../modules/chronopost/importExport.php?shared_secret='.Tools::getValue('shared_secret')
.'&cible='.Tools::getValue('cible').'&orders='
.implode(';', Tools::getValue('orderBox')).'&multi='.addslashes(Tools::jsonEncode(Tools::getValue('multi'))).'";
};
</script>';
echo '<div class="conf">
Votre fichier export sera téléchargé automatiquement dans quelques secondes.
</div>';
break;
case 'PDF':
echo '<script type="text/javascript">
setTimeout("delayer()", 1000);
function delayer() {
window.location = "../modules/chronopost/postSkybill.php?shared_secret='.Tools::getValue('shared_secret')
.'&orders='
.implode(';', Tools::getValue('orderBox')).'&multi='.addslashes(Tools::jsonEncode(Tools::getValue('multi'))).'";
};
</script>';
echo '<div class="conf">
Le fichier comprenant la totalité de vos lettres de transport sera téléchargé automatiquement dans quelques secondes.
</div>';
break;
}
return false; // prevents redirection
}
}