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 .= '

'.$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(Tools::isSubmit('submitTestLaposte')) { $this->_html .= '

'.$this->l('Registration complete, label sent to printer').'


'; $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]); $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').'


'; } $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 .= '

'.$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; $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; } } $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.=' '; $helperForm->_js .=' '; $this->_html.='

'.$this->l('Select sale').'


'; $this->_html.='

'.$this->l('Select order').'

'; $this->_html .= ' '; $this->_html .= $helperForm->renderScript(); echo $this->_html; } }