bebeboutik/modules/ant_logistic/AdminAntLogistic.php
2018-02-20 15:46:42 +01:00

1063 lines
52 KiB
PHP
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
if (!defined('_PS_VERSION_')) {
exit;
}
global $logistics_carriers;
foreach(array_map(function($value) {
return str_replace('.', '', $value);
}, array_diff(scandir(dirname(__FILE__).'/carriers'), array('.', '..'))) as $lg) {
if(is_dir(dirname(__FILE__).'/carriers/'.$lg)) {
include dirname(__FILE__).'/carriers/'.$lg.'/'.$lg.'.php';
$name = ucfirst($lg).'Carrier';
$logistics_carriers[$lg] = new $name();
}
}
include _PS_ROOT_DIR_.'/modules/privatesales/Sale.php';
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
class AdminAntLogistic extends AdminTab
{
public $_html = '';
public $submitShipAfter = false;
private function stripaccents($str)
{
return preg_replace(
'~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);~i',
'$1',
htmlentities($str, ENT_NOQUOTES, 'UTF-8')
);
}
private function isoreplace($str)
{
// ISO/CEI 646
return str_replace(array(
'Ç', 'ü', 'é', 'â', 'ä', 'à',
'å', 'ç', 'ê', 'ë', 'è', 'ï',
'î', 'ì', 'Ä', 'Å', 'É', 'æ',
'Æ', 'ô', 'ö', 'ò', 'û', 'ù',
'ÿ', 'Ö', 'Ü', '¢', '£', '¥',
'₧', 'ƒ', 'á', 'í', 'ó', 'ú',
'ñ', 'Ñ', 'ª', 'º', '¿', '⌐',
'¬', '½', '¼', '¡', '«', '»',
'░', '▒', '▓', '│', '┤', '╡',
'╢', '╖', '╕', '╣', '║', '╗',
'╝', '╜', '╛', '┐', '└', '┴',
'┬', '├', '─', '┼', '╞', '╟',
'╚', '╔', '╩', '╦', '╠', '═',
'╬', '╧', '╨', '╤', '╥', '╙',
'╘', '╒', '╓', '╫', '╪', '┘',
'┌', '█', '▄', '▌', '▐', '▀',
'α', 'ß', 'Γ', 'π', 'Σ', 'σ',
'µ', 'τ', 'Φ', 'Θ', 'Ω', 'δ',
'∞', 'φ', 'ε', '∩', '≡', '±',
'≥', '≤', '⌠', '⌡', '÷', '≈',
'°', '∙', '·', '√', 'ⁿ', '²',
'■',
), array(
chr(128), chr(129), chr(130), chr(131), chr(132), chr(133),
chr(134), chr(135), chr(136), chr(137), chr(138), chr(139),
chr(140), chr(141), chr(142), chr(143), chr(144), chr(145),
chr(146), chr(147), chr(148), chr(149), chr(150), chr(151),
chr(152), chr(153), chr(154), chr(155), chr(156), chr(157),
chr(158), chr(159), chr(160), chr(161), chr(162), chr(163),
chr(164), chr(165), chr(166), chr(167), chr(165), chr(166),
chr(167), chr(168), chr(169), chr(170), chr(171), chr(172),
chr(173), chr(174), chr(175), chr(176), chr(177), chr(178),
chr(179), chr(180), chr(181), chr(182), chr(183), chr(184),
chr(185), chr(186), chr(187), chr(188), chr(189), chr(190),
chr(191), chr(192), chr(193), chr(194), chr(195), chr(196),
chr(197), chr(198), chr(199), chr(200), chr(201), chr(202),
chr(203), chr(204), chr(205), chr(206), chr(207), chr(208),
chr(209), chr(210), chr(211), chr(209), chr(210), chr(211),
chr(212), chr(213), chr(214), chr(215), chr(216), chr(217),
chr(218), chr(219), chr(220), chr(221), chr(222), chr(223),
chr(224), chr(225), chr(226), chr(227), chr(228), chr(229),
chr(230), chr(231), chr(232), chr(233), chr(234), chr(235),
chr(236), chr(237), chr(238), chr(239), chr(240), chr(241),
chr(242), chr(243), chr(244), chr(245), chr(246), chr(247),
chr(248), chr(249), chr(250), chr(251), chr(252), chr(253),
chr(254),
), $str);
}
private function printLabel($data, $mr=false)
{
global $cookie;
$redis = new Predis\Client();
if($mr){
$redis->publish(
Configuration::get('LOGISTICS_QUEUE_'.(int) $cookie->id_employee),
json_encode(array('data' => base64_encode(
chr(2).'n'."\n" // Inch mode
.chr(2).'O0100'."\n" // Start position
.chr(2).'L'."\n"
.'C0000'."\n"
.'D11'."\n"
.chr(2).'L'."\n"
.$this->isoreplace($data)
.'Q0001'."\n" // Number of labels to print
.'E'."\n" // End
)))
);
} else {
$redis->publish(
Configuration::get('LOGISTICS_QUEUE_'.(int) $cookie->id_employee),
json_encode(array('data' => base64_encode(
$data
)))
);
}
return TRUE;
}
public function postProcess()
{
global $cookie, $logistics_carriers;
// Delete number
if(( in_array((int)$cookie->profile, array(1,9,7,13,14)) )
&& ( $delete_number = Tools::getValue('delete_number') )) {
// Suppression LAPOSTE
if($delete = (int) Tools::getValue('delete_laposte')) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'lapostews`
WHERE `id_order_detail` = '.$delete.'
AND `shipping_number` = "'.pSQL($delete_number).'"
');
if(!Db::getInstance()->getRow('
SELECT l.`shipping_number`
FROM `'._DB_PREFIX_.'lapostews` l
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
ON l.`id_order_detail` = d.`id_order_detail`
WHERE l.`shipping_number` = "'.pSQL($delete_number).'"
AND d.`id_order` = '.(int) Tools::getValue('id_order').'
')) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` = '.(int) Tools::getValue('id_order').'
AND `shipping_number` = "'.pSQL($delete_number).'"
');
}
}
// Suppression EXAPAQ
elseif ($delete = (int) Tools::getValue('delete_exapaq')) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'exapaqws`
WHERE `id_order_detail` = '.$delete.'
AND `shipping_number` = "'.pSQL($delete_number).'"
');
if(!Db::getInstance()->getRow('
SELECT `shipping_number`
FROM `'._DB_PREFIX_.'exapaqws`
WHERE `shipping_number` = "'.pSQL($delete_number).'"
')) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` = '.(int) Tools::getValue('id_order').'
AND `shipping_number` = "'.pSQL($delete_number).'"
');
}
}
// Suppression MONDIAL RELAY
elseif ($delete = (int) Tools::getValue('delete_mondialrelay')) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'mondialrelay_parcel`
WHERE `id_order_detail` = '.$delete.'
AND `shipping_number` = "'.pSQL($delete_number).'"
');
if(!Db::getInstance()->getRow('
SELECT `shipping_number`
FROM `'._DB_PREFIX_.'mondialrelay_parcel`
WHERE `shipping_number` = "'.pSQL($delete_number).'"
')) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` = '.(int) Tools::getValue('id_order').'
AND `shipping_number` = "'.pSQL($delete_number).'"
');
}
}
// Suppression PHILEA
elseif ($delete = (int) Tools::getValue('delete_philea')) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'philea_parcel`
WHERE `id_order_detail` = '.$delete.'
AND `shipping_number` = "'.pSQL($delete_number).'"
');
if(!Db::getInstance()->getRow('
SELECT `shipping_number`
FROM `'._DB_PREFIX_.'philea_parcel`
WHERE `shipping_number` = "'.pSQL($delete_number).'"
')) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` = '.(int) Tools::getValue('id_order').'
AND `shipping_number` = "'.pSQL($delete_number).'"
');
}
}
// Pour les commandes et les articles mise à jours en commande non envoyé, simplement payé
$id_order_details = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order_detail`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) Tools::getValue('id_order').'
') as $row) {
$id_order_details[] = (int) $row['id_order_detail'];
}
if(!Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'lapostews`
WHERE `id_order_detail` IN ('.implode(', ', $id_order_details).')
')) {
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'order_history` VALUES (
DEFAULT,
'.(int) $cookie->id_employee.',
'.(int) Tools::getValue('id_order').',
'.(int) Configuration::get('PS_OS_PAYMENT').',
NOW()
)
');
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'order_state_current` VALUES (
'.(int) Tools::getValue('id_order').',
'.(int) Configuration::get('PS_OS_PAYMENT').',
NOW()
)
ON DUPLICATE KEY UPDATE
`id_order_state` = '.(int) Configuration::get('PS_OS_PAYMENT').',
`date_upd` = NOW()
');
}
Tools::redirectLink('http://'.$_SERVER['SERVER_NAME'].'/adm/index.php?tab=AdminAntLogistic&token='.Tools::getAdminTokenLite('AdminAntLogistic').'&id_order='.(int) Tools::getValue('id_order').'&mode='.Tools::getValue('mode', '').'#'.Tools::getValue('mode', ''));
}
// Generate a new shipping number for product sent with many parcels
if( (Tools::isSubmit('submitReprintShip'))
&& in_array((int)$cookie->profile, array(1,9,7,13,14))
&& (
($id_order = Tools::getValue('id_order_reprint'))
&& ($products = Tools::getValue('products_reprint'))
&& ($parcel_carrier = Tools::getValue('carrier_reprint'))
)
) {
$weight = 0.24;
$order = new Order((int) $id_order);
if(Validate::isLoadedObject($order)) {
$parcel_carrier == 'laposte' ? $weight = 0.24 : true;
if ($parcel_carrier == 'laposte' || $parcel_carrier == 'mondialrelay') {
$result = $logistics_carriers[$parcel_carrier]->registerParcel($order, $products, $weight);
if($result[0] != '') {
$this->_html .= $result[0];
return;
}
$render = $logistics_carriers[$parcel_carrier]->renderLabel($order, $weight, $result[1]);
if($render === 'pr_error') {
$this->_html .= '<p class="error">'.$this->l('Unknown delivery point').'</p><br />';
} elseif($render === 'route_error') {
$this->_html .= '<p class="error">'.$this->l('Route not found').'</p><br />';
} elseif($render !== FALSE) {
if($parcel_carrier == 'mondialrelay') {
$this->printLabel($render,true);
$f = fopen(dirname(__FILE__).'/label_mr.txt', 'a+');
fwrite($f, $render);
fclose($f);
} else {
$this->printLabel($render);
}
$this->_html .= '<p class="conf">'.$this->l('Registration complete, label sent to printer').'</p><br />';
if($_SERVER['REMOTE_ADDR'] != '109.190.53.175'
&& $_SERVER['REMOTE_ADDR'] != '78.226.56.137'
&& $_SERVER['REMOTE_ADDR'] != '88.163.22.223'
&& $_SERVER['REMOTE_ADDR'] != '37.160.139.229'
&& substr($_SERVER['REMOTE_ADDR'], 0, 2) != '37') {
$products_names = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order_detail`, `product_name`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order_detail` IN ('.implode(', ', array_keys($products)).')
') as $p) {
$products_names[(int) $p['id_order_detail']] = $p['product_name'];
}
$logistics_carriers[$parcel_carrier]->logParcel($result[1], $products);
foreach($products as $k => $v) {
if($v > 0) {
$products_sent .= '<br />'."\r\n".$v.' x '.(isset($products_names[$k])? $products_names[$k]: '--');
}
}
$logistics_carriers[$parcel_carrier]->addOrderHistory($result[1], $order, $products_sent);
}
} else {
$this->_html .= '<p class="error">'.$this->l('An error happened during the label rendering').'</p><br />';
}
}
}
} elseif(Tools::isSubmit('submitTestLaposte')) {
$this->_html .= '<p class="conf">'.$this->l('Registration complete, label sent to printer').'</p><br />';
$this->printLabel($logistics_carriers['laposte']->renderLabel(new Order(223001), 0.24, '6J12345123451'));
} elseif(Tools::isSubmit('submitTestExapaq')) {
$this->_html .= '<p class="conf">'.$this->l('Registration complete, label sent to printer').'</p><br />';
$this->printLabel($logistics_carriers['exapaq']->renderLabel(new Order(23336), 0.24, array('shipping_number' => '100000000', 'exapass' => '250094100000000068')));
} elseif(Tools::isSubmit('submitTestMondialrelay')) {
$this->_html .= '<p class="conf">'.$this->l('Registration complete, label sent to printer').'</p><br />';
$weight = 0.100000;
$id_order = 628811;
$id_order_detail = 1994641;
$product = array('5189355' => "1");
$result = $logistics_carriers['mondialrelay']->_getRegisteredParcel(new Order($id_order), $id_order_detail, $product, $weight);
$render = $logistics_carriers['mondialrelay']->renderLabel(new Order($id_order), $weight, $result[1]);
$this->printLabel($render,true);
} elseif(Tools::isSubmit('submitShip') && ($id_order = (int) Tools::getValue('id_order'))) {
$order = new Order((int) $id_order);
$to_ship = array();
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, SUM(d.`product_quantity`) AS `product_quantity`, SUM(d.`product_quantity_refunded`) AS `product_quantity_refunded`, SUM(d.`product_quantity_return`) AS `product_quantity_return`, SUM(w.`quantity`) AS `quantity_sent`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'lapostews` w
ON d.`id_order_detail` = w.`id_order_detail`
WHERE d.`id_order` = '.$id_order.'
GROUP BY d.`id_order_detail`
') as $p) {
$to_ship[(int) $p['id_order_detail']] = $p['product_quantity'] - ($p['product_quantity_refunded'] > 0? $p['product_quantity_refunded']: $p['product_quantity_return']) - (int) $p['quantity_sent'];
}
if (Validate::isLoadedObject($order)) {
$parcel_carrier = Tools::getValue('parcel_carrier', 'laposte');
if(($weight = Tools::getValue('weight')) && ($products = Tools::getValue('shipped'))) {
$parcel_carrier == 'laposte'? $weight = 0.24: TRUE;
$total_products = 0;
foreach($products as $k => $v) {
if($v > 0) {
if($cookie->profile == 1) {
$total_products = 1;
break;
} else {
if(isset($to_ship[$k]) && $to_ship[$k] > 0 && $v <= $to_ship[$k]) {
$total_products++;
} else {
$total_products = 0;
break;
}
}
}
}
if($total_products != 0) {
$result = $logistics_carriers[$parcel_carrier]->registerParcel($order, $products, $weight);
if($result[0] != '') {
$this->_html .= $result[0];
return;
}
$render = $logistics_carriers[$parcel_carrier]->renderLabel($order, $weight, $result[1]);
if($render === 'pr_error') {
$this->_html .= '<p class="error">'.$this->l('Unknown delivery point').'</p><br />';
} elseif($render === 'route_error') {
$this->_html .= '<p class="error">'.$this->l('Route not found').'</p><br />';
} elseif($render !== FALSE) {
if($parcel_carrier == 'mondialrelay') {
$this->printLabel($render,true);
} else {
$this->printLabel($render);
}
$this->_html .= '<p class="conf">'.$this->l('Registration complete, label sent to printer').'</p><br />';
if($_SERVER['REMOTE_ADDR'] != '109.190.53.175'
&& $_SERVER['REMOTE_ADDR'] != '78.226.56.137'
&& $_SERVER['REMOTE_ADDR'] != '88.163.22.223'
&& $_SERVER['REMOTE_ADDR'] != '37.160.139.229'
&& substr($_SERVER['REMOTE_ADDR'], 0, 2) != '37') {
$products_sent = '';
$products_names = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order_detail`, `product_name`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order_detail` IN ('.implode(', ', array_keys($products)).')
') as $p) {
$products_names[(int) $p['id_order_detail']] = $p['product_name'];
}
$logistics_carriers[$parcel_carrier]->logParcel($result[1], $products);
foreach($products as $k => $v) {
if($v > 0) {
$products_sent .= '<br />'."\r\n".$v.' x '.(isset($products_names[$k])? $products_names[$k]: '--');
}
}
$logistics_carriers[$parcel_carrier]->addOrderHistory($result[1], $order, $products_sent);
}
} else {
$this->html .= '<p class="error">'.$this->l('An error happened during the label rendering').'</p><br />';
}
} else {
$this->_html .= '<p class="error">'.$this->l('Please enter a weight and select at least one product').'</p><br />';
}
} else {
$this->_html .= '<p class="error">'.$this->l('Please enter a weight and select at least one product').'</p><br />';
}
$this->submitShipAfter = true;
}
} elseif(Tools::isSubmit('submitMod') && ($id_order = (int) Tools::getValue('id_order'))) {
$product_ids = Tools::getValue('product_ids');
foreach ($product_ids as $id) {
$id_sale = Db::getInstance()->getValue('
SELECT `id_sale`
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` = '.(int) $id
);
if (!$id_sale) {
$id_sale = 0;
}
Db::getInstance()->ExecuteS('
INSERT IGNORE INTO `'._DB_PREFIX_.'logistics_pending`
VALUES ('.(int) $id_order.','.(int) $id.','.(int) $id_sale.')
');
}
$id_order_state = Db::getInstance()->getRow('
SELECT `id_order_state`
FROM `'._DB_PREFIX_.'order_history`
WHERE `id_order`= '.(int) $id_order.'
ORDER BY `id_order_history` DESC
');
// commande en attente
if ((int)$id_order_state['id_order_state'] != 19) {
$history = new OrderHistory();
$history->id_order = (int)$id_order;
$history->id_employee = (int)($cookie->id_employee);
$history->changeIdOrderState(19, (int)($id_order));
if ($history->add()) {
$this->_html .= '<p class="conf">'.$this->l('Order status changed').'</p><br />';
} else {
$this->_html .= '<p class="error">'.$this->l('Error occured').'</p><br />';
}
} else {
$this->_html .= '<p class="conf">'.$this->l('Order in pending').'</p><br />';
}
}
}
public function display()
{
global $cookie, $logistics_carriers;
$unavailable_carriers = array();
foreach($logistics_carriers as $name => $class) {
if(!$class->checkavailability()) {
$unavailable_carriers[] = $name;
$this->_html .= '<p class="error">'.$class->displayName.' '.$this->l('Webservices are unavailable at the moment, please try again later.').'</p>';
}
}
$locked_products = array();
$_locked_products = Configuration::get('LOGISTICS_LOCK');
if($_locked_products === FALSE || $_locked_products == 0 || $_locked_products == 's:8:"s:1:"0"' || empty($_locked_products)) {
$_locked_products = serialize(array());
}
foreach(unserialize($_locked_products) as $id_s) {
$_s = new Sale($id_s);
foreach($_s->getProducts() as $p) {
$locked_products[] = $p;
}
}
$sales_list = array();
if(isset($_COOKIE['logistics_sales'])) {
foreach(explode('-', $_COOKIE['logistics_sales']) as $chunk) {
$sales_list[] = (int) $chunk;
}
}
$helperForm = new HelperFormBootstrap();
$helperForm->_css.='
body.mode_light, body.mode_light #top_container, body.mode_light #container, body.mode_light #container #content {
background: #f5f5f9;
border: 0px;
}
body.mode_light #orderInfos .addresses,
body.mode_light #orderInfos > .infos,
body.mode_light #orderInfos #shippingLogs,
body.mode_light #header_infos,
body.mode_light #header_search,
body.mode_light #header_quick,
body.mode_light ul#menu,
body.mode_light ul#submenu,
body.mode_light #footer,
body.mode_light .path_bar,
body.mode_light div#tab1_subtabs, body.mode_light div#tab2_subtabs, body.mode_light div#tab3_subtabs, body.mode_light div#tab4_subtabs, body.mode_light div#tab5_subtabs, body.mode_light div#tab6_subtabs, body.mode_light div#tab7_subtabs, body.mode_light div#tab8_subtabs, body.mode_light div#tab9_subtabs, body.mode_light div#tab29_subtabs, body.mode_light div#tab89_subtabs {
display: none;
}
.ui-multiselect {
padding: 2px 0 2px 4px;
text-align: left;
}
.ui-multiselect span.ui-icon {
float: right;
}
.ui-multiselect-single .ui-multiselect-checkboxes input {
left: -9999px;
position: absolute !important;
top: auto !important;
}
.ui-multiselect-single .ui-multiselect-checkboxes label {
padding: 5px !important;
}
.ui-multiselect-header {
margin-bottom: 3px;
padding: 3px 0 3px 4px;
}
.ui-multiselect-header ul {
font-size: 0.9em;
}
.ui-multiselect-header ul li {
float: left;
padding: 0 10px 0 0;
}
.ui-multiselect-header a {
text-decoration: none;
}
.ui-multiselect-header a:hover {
text-decoration: underline;
}
.ui-multiselect-header span.ui-icon {
float: left;
}
.ui-multiselect-header li.ui-multiselect-close {
float: right;
padding-right: 0;
text-align: right;
}
.ui-multiselect-menu {
display: none;
padding: 3px;
position: absolute;
text-align: left;
z-index: 10000;
width: 842px;
}
.ui-multiselect-checkboxes {
overflow-y: scroll;
position: relative;
}
.ui-multiselect-checkboxes label {
border: 1px solid transparent;
cursor: default;
display: block;
padding: 3px 1px;
float: none;
text-align: left;
width: auto;
}
.ui-multiselect-checkboxes label input {
position: relative;
top: 1px;
margin-right: 5px;
}
.ui-multiselect-checkboxes li {
clear: both;
font-size: 0.9em;
padding-right: 3px;
}
.ui-multiselect-checkboxes li.ui-multiselect-optgroup-label {
border-bottom: 1px solid;
font-weight: bold;
text-align: center;
}
.ui-multiselect-checkboxes li.ui-multiselect-optgroup-label a {
display: block;
margin: 1px 0;
padding: 3px;
text-decoration: none;
}
* html .ui-multiselect-checkboxes label {
border: medium none;
}
.ui-multiselect-hasfilter ul { position:relative; top:2px }
.ui-multiselect-filter { float:left; margin-right:10px; font-size:11px }
.ui-multiselect-filter input { width:300px; font-size:10px; margin-left:5px; height:15px; padding:2px; border:1px solid #292929; -webkit-appearance:textfield; -webkit-box-sizing:content-box; }
.location {
color: #0066ff;
}
#html_products thead th,
#html_logs thead th{
font-size:12px;
vertical-align:middle;
}
#html_products tbody tr.grey{
background:#efefef !important;
}
#html_products tbody tr td{
vertical-align:middle;
}
#html_products tbody tr td input.input_quantity{
width: 40px;
font-size: 22px;
display: inline-block;
vertical-align: middle;
height: 41px;
text-align: center;
}
#html_products tbody tr td .qtyblock{
width: 30px;
display: inline-block;
vertical-align: middle;
}
#html_products tbody tr td .qtyblock a{
background: #504d8b;
font-size: 18px;
width: 30px;
text-align: center;
display: block;
line-height: 20px;
cursor: pointer;
color:#fff;
}
#html_products tbody tr td .qtyblock a.qty_down{
border-top:1px solid;
}
';
$this->_html .= $helperForm->renderStyle();
$helperForm->_js.='
<script type="text/javascript">
$(document).on("click",".qtyblock a", function(e){
$("#eaninput").focus();
});
var carriers = ';
$js_carriers = array();
foreach($logistics_carriers as $k => $v) {
$js_carriers[$k] = $v->displayName;
}
$helperForm->_js.= json_encode($js_carriers);
$helperForm->_js.=';
var carriers_laposte = $.parseJSON("'.addslashes(json_encode(unserialize(Configuration::get('LAPOSTEWS_CARRIERS')))).'");
var carriers_exapaq = $.parseJSON("'.addslashes(json_encode(unserialize(Configuration::get('EXAPAQWS_CARRIERS')))).'");
var carriers_mondialrelay = $.parseJSON("'.addslashes(json_encode(unserialize(Configuration::get('MONDIALRELAYWS_CARRIERS')))).'");
var locked_products = $.parseJSON("'.addslashes(json_encode($locked_products)).'");
var sales_list = $.parseJSON("'.addslashes(json_encode($sales_list)).'");
var req = null;
function loadOrder(id_order, ean_focus) {
if(!(typeof id_order == "number")) {
if($("#barcodeinput:focus").length > 0) {
var bc = $("#barcodeinput").val();
if(bc.substr(0, 2) == "O-" && bc.length > 3) {
if(bc.indexOf(" ") != -1) {
id_order = parseInt(bc.substr(2).replace(" ", ""));
$("#barcodeinput").val("");
} else {
id_order = parseInt(bc.substr(2));
}
}
if(typeof id_order == "undefined") {
return;
}
} else {
id_order = parseInt($("#manualinput").val());
}
}
try {
$("#order_detail").hide();
$("#shipping_detail").hide();
req.cancel();
} catch(e) {}
isRelay = 0;
lockPrint = false;
req = $.get("'.__PS_BASE_URI__.'modules/ant_logistic/ajax.php?id_profil='.$cookie->profile.'&id_employee='.(int) $cookie->id_employee.'&token='.Tools::getValue('token').'&id_order=" + id_order, function(loaded) {
if(loaded) {
var loaded = $.parseJSON(loaded);
isRelay = $.inArray(parseInt(loaded.delivery_address.id_country), [1, 2, 3, 6, 10, 12, 13, 17, 26, 40, 148, 245]) != -1
? 0
: (loaded.delivery_infos_laposte
? (loaded.delivery_infos_laposte.delivery_mode != \'DOM\'
? 1
: 0 )
: (loaded.delivery_infos_exapaq
? 2
: (loaded.delivery_infos_mr
? (loaded.delivery_infos_mr.dlv_mode != \'LD1\' && loaded.delivery_infos_mr.dlv_mode != \'LDS\' && loaded.delivery_infos_mr.dlv_mode != \'HOM\'
? 3
: 0
)
: 0
)
)
);
lockPrint = false;
if(!loaded.errors) {
$("#order_detail #order_id").html(loaded.order.id);
$("#order_detail #button1").attr(\'href\',$("#order_detail #button1").attr(\'href\')+\'&id_customer=\'+loaded.order.id_customer);
$("#order_detail #button2").attr(\'href\',$("#order_detail #button2").attr(\'href\')+\'&id_order=\'+loaded.order.id);
$("#order_detail #button3").attr(\'href\',$("#order_detail #button3").attr(\'href\')+\'&id_order=\'+loaded.order.id);
$("#html_form").html(loaded.html_form);
$("#html_detail").html(loaded.html_detail);
$("#html_invoice_address").html(loaded.html_invoice_address);
$("#html_delivery_address").html(loaded.html_delivery_address);
$("#html_products tbody").html(loaded.html_products);
$("#order_detail").show();
if(loaded.logs.length){
$("#html_logs tbody").html(loaded.html_logs);
$("#shipping_detail").show();
$("a.need_token").each(function(){
$(this).attr(\'href\',$(this).attr(\'href\')+\'&token='.Tools::getAdminTokenLite('AdminAntLogistic').'\');
});
}
if($.inArray(String(loaded.order.id_carrier), carriers_laposte) != -1) {
$("#parcel_carrier option[value=\'laposte\']").attr("selected","selected");
} else if($.inArray(String(loaded.order.id_carrier), carriers_exapaq) != -1) {
$("#parcel_carrier option[value=\'exapaq\']").attr("selected","selected");
} else if($.inArray(String(loaded.order.id_carrier), carriers_mondialrelay) != -1) {
$("#parcel_carrier option[value=\'mondialrelay\']").attr("selected","selected");
}
$("#orderInfos").show();
$("#main table.std tbody").append($("#main table.std tbody tr").get().sort(function(a, b) {
return $(a).attr("class") == "grey";
}));
if(ean_focus) {
$("#eaninput").focus();
}
$("#modalRePrint").on("show.bs.modal", function (event) {
var button = $(event.relatedTarget);
var modal = $(this);
modal.find(".modal-body span#product-name").html(button.data("product"));
modal.find(".modal-body span#product-ref").text(button.data("ref"));
modal.find(".modal-body #carrier-reprint").val(button.data("carrier"));
modal.find(".modal-body #id_order-reprint").val(button.data("id_order"));
modal.find(".modal-body #id_order_detail-reprint").val(button.data("id_order_detail"));
modal.find(".modal-body #weight-reprint").val(button.data("weight"));
modal.find(".modal-body #quantity-reprint").attr("name","products_reprint["+button.data("id_order_detail")+"]");
});
}
}
});
}';
if ($this->submitShipAfter && Tools::getIsset('id_order')) {
$helperForm->_js .= '
$(function() {
$("#manualinput").val('.Tools::getValue('id_order').');
$("#barcodeinput").val("");
loadOrder(null, true);
});
';
}
$helperForm->_js .= '</script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/ant_logistic/libs/jquery.hotkeys.js"></script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/ant_logistic/libs/jquery.multiselect.min.js"></script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/ant_logistic/libs/jquery.multiselect.filter.min.js"></script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/ant_logistic/script.js?v=1"></script>';
$helperForm->_js .='
<div class="modal" id="confirm" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Erreur</h4>
</div>
<div class="modal-body">
<div class="message"></div>
</div>
</div>
</div>
</div>
<div class="modal" id="prompt" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Confirmation</h4>
</div>
<div class="modal-body">
<div class="message"></div>
</div>
<div class="modal-footer">
<button class="btn btn-primary yes" type="button">Valider</button>
<button class="btn btn-default no" type="button">Annuler</button>
</div>
</div>
</div>
</div>';
$this->_html.='
<div class="row">
<div class="col-md-12">
<div class="panel">
<div class="panel-title">
<h2 class=""><span class="anticon anticon-filter text-rose"></span> '.$this->l('Select sale').'</h2>
<div class="clearfix"></div>
</div>
<div class="panel-content">
<form action="'.__PS_BASE_URI__.'modules/ant_logistic/select_sale.php?token='.Tools::getValue('token').'&id_employee='.(int) $cookie->id_employee.'" method="POST">
<div>
<select multiple="true" id="filter_id_sale" name="filter_id_sale[]" style="display:none;">';
foreach(Db::getInstance()->ExecuteS('
SELECT s.`id_sale`, c.`name`
FROM `'._DB_PREFIX_.'privatesale` s
LEFT JOIN `'._DB_PREFIX_.'category_lang` c ON (c.`id_category` = s.`id_category`)
WHERE c.`id_lang` = 2
AND (
s.`date_end` > DATE_SUB(NOW(), INTERVAL 90 DAY)
OR s.`public` = 1
)
') as $row) {
$this->_html .= '<option value="'.(int) $row['id_sale'].'"'.(in_array((int) $row['id_sale'], $sales_list)? ' selected="selected"': '').'>'.(int) $row['id_sale'].' - '.htmlentities($row['name']).'</option>';
}
$this->_html .= '</select>
<input class="btn btn-primary pull-right" type="submit" value="Valider" /><br style="clear: both" />
</div>
</form>
</div>
</div>
</div>
</div>';
$this->_html.='
<div class="row">
<div class="col-md-12">
<div class="panel" style="'.($cookie->profile == 1 || count($sales_list) > 0? ' display: block;': 'display: none;').'">
<div class="panel-title">
<h2 class=""><span class="text-rose anticon anticon-price-tag"></span> '.$this->l('Select order').'</h2>
<ul class="nav navbar-right panel-toolbox">
<li class="pull-left"><a onclick="toggleMode(this);" href="#light" class="collapse-link"><i class="anticon anticon-'.(Tools::getValue('mode') == 'light'? 'shrink2': 'enlarge2').'"></i> [F11]</a></li>
<li class="pull-left"><a class="collapse-link"><i class="anticon anticon-barcode"></i> [F12]</a></li>
<li class="pull-left"><a class="collapse-link" onclick="window.open(\'/modules/shippingstats/showstats.php?token='.Tools::getValue('token').'&id_employee='.(int) $cookie->id_employee.'\', \'\', \'menubar=no, status=no, width=400, height=400\');">Statistiques</a></li>
</ul>
<div class="clearfix"></div>
</div>
<div class="panel-content">
<div class="row">
<div class="col-md-5">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="anticon anticon-barcode"></i></span>
<input type="text" id="barcodeinput" value="" autocomplete="off" placeholder="'.$this->l('Click here and scan a barcode').'" class="form-control" />
</div>
</div>
</div>
<div class="col-md-2"></div>
<div class="col-md-5">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="anticon anticon-price-tag"></i></span>
<input type="text" id="manualinput" value="" autocomplete="off" placeholder="'.$this->l('Enter an order id and click ENTER').'" class="form-control" />
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="ln_solid"></div>
</div>
<div class="clearfix"></div>
</div>
</div>
<div class="col-md-12">
<div class="panel" id="order_detail" style="display:none;">
<div class="panel-title">
<h2 class="">Commande #<span id="order_id"></span></h2>
<ul class="nav navbar-right panel-toolbox">
<li class="pull-left">
<a id="button1" class="collapse-link" onclick="window.open(this.href); return false;" href="'.__PS_BASE_URI__.'adm/index.php?tab=AdminCustomers&viewcustomer&token='.Tools::getAdminTokenLite('AdminCustomers').'">[F4] Fiche client</a>
</li>
<li class="pull-left">
<a id="button2" class="collapse-link" onclick="window.open(this.href); return false;" href="'.__PS_BASE_URI__.'adm/index.php?tab=AdminOrders&vieworder&token='.Tools::getAdminTokenLite('AdminOrders').'">[F3] Commande</a>
</li>
<li class="pull-left">
<a id="button3" class="collapse-link" onclick="window.open(this.href); return false;" href="'.__PS_BASE_URI__.'adm/pdf.php?pdf">[F2] Facture</a>
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="panel-content">
<div class="row">
<div class="col-md-4">
<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;">'.$this->l('Information').'</h5>
<p style="padding:10px 20px;background:#efefef;" id="html_detail"></p>
</div>
<div class="col-md-4">
<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;">'.$this->l('Adresse facturation').'</h5>
<p style="padding:10px 20px;background:#efefef;" id="html_invoice_address"></p>
</div>
<div class="col-md-4">
<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;">'.$this->l('Adresse livraison').'</h5>
<p style="padding:10px 20px;background:#efefef;" id="html_delivery_address"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="ln_solid"></div>
<div class="row">
<form id="button_form" method="POST" action="">
<div class="col-md-8 col-md-offset-2" id="html_form"></div>
<div class="col-md-8 col-md-offset-2">
<div class="ln_solid"></div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="anticon anticon-barcode"></i></span>
<input type="text" autocomplete="off" id="eaninput" onkeydown="return filterKeys(event);" onkeyup="checkEAN();" placeholder="'.$this->l('Entrée EAN13').'" class="form-control" />
</div>
</div>
</div>
<div class="col-md-12">
<div class="table-responsive">
<table id="html_products" class="table table-custombordered" style="margin-bottom:0;">
<thead>
<tr>
<th>'.$this->l('Produit').'</th>
<th></th>
<th class="text-center">'.$this->l('Référence').'</th>
<th class="text-center" width="100">'.$this->l('Quantités').'</th>
<th class="text-center" width="80px">'.$this->l('Quantité à envoyée').'</th>
<th class="text-center">'.$this->l('Att').'</th>
<th class="text-center" width="110px">'.$this->l('Quantité envoyée').'</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td colspan="5"></td>
<td style="text-align: center;"><input type="submit" class="btn btn-primary btn-sm" name="submitMod" value="'.$this->l('MOD').'"/></td>
<td></td>
</tr>
</tfoot>
</table>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="panel" id="shipping_detail" style="display:none;">
<div class="panel-title">
<h2 class=""><span class="text-rose anticon anticon-truck"></span> Historique des envois</h2>
<div class="clearfix"></div>
</div>
<div class="panel-content">
<div class="table-responsive">
<form id="log_form" method="POST" action="">
<table id="html_logs" class="table table-custombordered" style="margin-bottom:0;">
<thead>
<tr>
<th>'.$this->l('Date').'</th>
<th>'.$this->l('Employé').'</th>
<th>'.$this->l('Quantité').'</th>
<th>'.$this->l('Produit').'</th>
<th>'.$this->l('Référence').'</th>
<th>'.$this->l('Référence fournisseur').'</th>
<th>'.$this->l('Numéro de suivi').'</th>
<th>'.$this->l('Transporteur').'</th>
'.(( in_array((int)$cookie->profile, array(1,9,7,13,14)) ) ?'<th></th>': '' ).'
'.(( in_array((int)$cookie->profile, array(1,9,7,13,14)) ) ?'<th></th>': '' ).'
</tr>
</thead>
<tbody>
</tbody>
</table>
</form>
</div>
</div>
</div>
</div>
</div>';
$this->_html .= '
<div class="modal" id="modalRePrint" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form id="log_form" method="POST" action="">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Ré-Imprimer l\'étiquette</h4>
</div>
<div class="modal-body">
<div class="row">
<p class="col-md-11 text-left"><label class="col-md-3">'.$this->l('Produit:').'</label> <span id="product-name"></span></p>
<p class="col-md-11 text-left"><label class="col-md-3">'.$this->l('Référence:').'</label> <span id="product-ref"></span></p>
<p class="col-md-11 text-left"><label class="col-md-3" for="products">'.$this->l('Quantité:').'</label> <input type="text" value="1" name="products_reprint[]" id="quantity-reprint" /></p>
<input type="hidden" value="laposte" name="carrier_reprint" id="carrier-reprint" />
<input type="hidden" value="0" name="id_order_reprint" id="id_order-reprint" />
<input type="hidden" value="0" name="id_order_detail_reprint" id="id_order_detail-reprint" />
<input type="hidden" value="0.24" name="weight_reprint" id="weight-reprint" />
</div>
<div class=clearfix"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" >Close</button>
<input class="btn btn-primary" id="button5" type="submit" name="submitReprintShip" value="Enregistrer et Imprimer" />
</div>
</form>
</div>
</div>
</div>';
$this->_html .= $helperForm->renderScript();
echo $this->_html;
}
}