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(
/*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*/
$data
)))
);
}
return TRUE;
}
public function postProcess() {
global $cookie, $logistics_carriers;
if(( in_array((int)$cookie->profile, array(1,9,7,13,14)) )
&& ( $delete_number = Tools::getValue('delete_number') )) {
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).'"
');
}
} 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).'"
');
}
} 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).'"
');
}
}
$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=AdminLogistics&token='.Tools::getAdminTokenLite('AdminLogistics').'&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 .= '
'.$this->l('Unknown delivery point').'
';
} elseif($render === 'route_error') {
$this->_html .= ''.$this->l('Route not found').'
';
} 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 .= ''.$this->l('Registration complete, label sent to printer').'
';
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 .= '
'."\r\n".$v.' x '.(isset($products_names[$k])? $products_names[$k]: '--');
}
}
$logistics_carriers[$parcel_carrier]->addOrderHistory($result[1], $order, $products_sent);
}
} else {
$this->html .= ''.$this->l('An error happened during the label rendering').'
';
}
}
// elseif($parcel_carrier=='mondialrelay'
// && (
// ($id_order_detail = Tools::getValue('id_order_detail_reprint'))
// && ($weight = Tools::getValue('weight_reprint'))
// )
// ){
// $result = $logistics_carriers['mondialrelay']->_getRegisteredParcel(new Order($id_order), $id_order_detail, $products, $weight);
// $render = $logistics_carriers['mondialrelay']->renderLabel(new Order($id_order), $weight, $result[1]);
// $this->printLabel($render,true);
// }
}
//$this->printLabel($logistics_carriers['laposte']->renderLabel(new Order((int) $id_order), $weight, $reprint_number));
} elseif(Tools::isSubmit('submitTestLaposte')) {
$this->_html .= ''.$this->l('Registration complete, label sent to printer').'
';
//$this->printLabel($logistics_carriers['laposte']->renderLabel(new Order(23336), 0.24, '6A12345123451'));
$this->printLabel($logistics_carriers['laposte']->renderLabel(new Order(223001), 0.24, '6J12345123451'));
} elseif(Tools::isSubmit('submitTestExapaq')) {
$this->_html .= ''.$this->l('Registration complete, label sent to printer').'
';
$this->printLabel($logistics_carriers['exapaq']->renderLabel(new Order(23336), 0.24, array('shipping_number' => '100000000', 'exapass' => '250094100000000068')));
} elseif(Tools::isSubmit('submitTestMondialrelay')) {
$this->_html .= ''.$this->l('Registration complete, label sent to printer').'
';
$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]);
$f = fopen(dirname(__FILE__).'/label_mr.txt', 'a+');
fwrite($f, $render);
fclose($f);
$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 .= ''.$this->l('Unknown delivery point').'
';
} elseif($render === 'route_error') {
$this->_html .= ''.$this->l('Route not found').'
';
} elseif($render !== FALSE) {
if($parcel_carrier == 'mondialrelay') {
$this->printLabel($render,true);
} else {
$this->printLabel($render);
}
$this->_html .= ''.$this->l('Registration complete, label sent to printer').'
';
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 .= '
'."\r\n".$v.' x '.(isset($products_names[$k])? $products_names[$k]: '--');
}
}
$logistics_carriers[$parcel_carrier]->addOrderHistory($result[1], $order, $products_sent);
}
} else {
$this->html .= ''.$this->l('An error happened during the label rendering').'
';
}
} else {
$this->_html .= ''.$this->l('Please enter a weight and select at least one product').'
';
}
} else {
$this->_html .= ''.$this->l('Please enter a weight and select at least one product').'
';
}
}
} 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 .= ''.$this->l('Order status changed').'
';
} else {
$this->_html .= ''.$this->l('Error occured').'
';
}
} else {
$this->_html .= ''.$this->l('Order in pending').'
';
}
}
}
public function display() {
global $cookie, $logistics_carriers;
/*if(!in_array($cookie->id_employee, array(1, 2, 3, 10, 68, 70, 89, 91))) {
echo 'Fonctionnalité indisponible actuellement'; return;
}*/
$unavailable_carriers = array();
foreach($logistics_carriers as $name => $class) {
if(!$class->checkavailability()) {
$unavailable_carriers[] = $name;
$this->_html .= ''.$class->displayName.' – '.$this->l('Webservices are unavailable at the moment, please try again later.').'
';
}
}
$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;
}
}
$this->_html .= '
';
echo $this->_html;
}
}