diff --git a/modules/ant_logistic/AdminAntLogistic.php b/modules/ant_logistic/AdminAntLogistic.php index fe527e53..a08b61ff 100644 --- a/modules/ant_logistic/AdminAntLogistic.php +++ b/modules/ant_logistic/AdminAntLogistic.php @@ -1,5 +1,5 @@ ';var_dump($data);echo '';die(); - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Option/OptionInterface.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Option/AbstractOption.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Command/Processor/CommandProcessingInterface.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Command/PrefixableCommandInterface.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Command/CommandInterface.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Command/AbstractCommand.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Command/PrefixableCommand.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Command/PubSubPublish.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Connection/ConnectionInterface.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Connection/SingleConnectionInterface.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Connection/AbstractConnection.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Connection/StreamConnection.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Connection/ConnectionParametersInterface.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Connection/ConnectionParameters.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Connection/ConnectionFactoryInterface.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Connection/ConnectionFactory.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Profile/ServerProfileInterface.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Profile/ServerProfile.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Profile/ServerVersion26.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Option/ClientCluster.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Option/ClientPrefix.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Option/ClientExceptions.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Option/ClientReplication.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Option/ClientConnectionFactory.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Option/ClientProfile.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Option/ClientOptionsInterface.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Option/ClientOptions.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/BasicClientInterface.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/ClientInterface.php'; - require_once _PS_ROOT_DIR_.'/modules/logistics/libs/predis/lib/Predis/Client.php'; $redis = new Predis\Client(); @@ -144,13 +117,15 @@ class AdminAntLogistic extends AdminTab { return TRUE; } - public function postProcess() { + public function postProcess() + { global $cookie, $logistics_carriers; - if( - ((int) $cookie->profile == 1 || (int) $cookie->profile == 9 || (int) $cookie->profile == 7 || (int) $cookie->profile == 14) - && ($delete_number = Tools::getValue('delete_number')) - ){ + // 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` @@ -172,7 +147,9 @@ class AdminAntLogistic extends AdminTab { AND `shipping_number` = "'.pSQL($delete_number).'" '); } - } elseif($delete = (int) Tools::getValue('delete_exapaq')) { + } + // Suppression EXAPAQ + elseif ($delete = (int) Tools::getValue('delete_exapaq')) { Db::getInstance()->ExecuteS(' DELETE FROM `'._DB_PREFIX_.'exapaqws` WHERE `id_order_detail` = '.$delete.' @@ -190,7 +167,9 @@ class AdminAntLogistic extends AdminTab { AND `shipping_number` = "'.pSQL($delete_number).'" '); } - } elseif($delete = (int) Tools::getValue('delete_mondialrelay')) { + } + // Suppression MONDIAL RELAY + elseif ($delete = (int) Tools::getValue('delete_mondialrelay')) { Db::getInstance()->ExecuteS(' DELETE FROM `'._DB_PREFIX_.'mondialrelay_parcel` WHERE `id_order_detail` = '.$delete.' @@ -209,7 +188,28 @@ class AdminAntLogistic extends AdminTab { '); } } + // 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` @@ -250,7 +250,7 @@ class AdminAntLogistic extends AdminTab { // Generate a new shipping number for product sent with many parcels if( (Tools::isSubmit('submitReprintShip')) - && ((int) $cookie->profile == 1 || (int) $cookie->profile == 9 || (int) $cookie->profile == 7 || (int) $cookie->profile == 14) + && in_array((int)$cookie->profile, array(1,9,7,13,14)) && ( ($id_order = Tools::getValue('id_order_reprint')) && ($products = Tools::getValue('products_reprint')) @@ -260,8 +260,8 @@ class AdminAntLogistic extends AdminTab { $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") { + $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]; diff --git a/modules/ant_logistic/ajax.php b/modules/ant_logistic/ajax.php index 1154a4ff..cbe3cced 100644 --- a/modules/ant_logistic/ajax.php +++ b/modules/ant_logistic/ajax.php @@ -1,5 +1,5 @@ 'SO à domicile', @@ -44,9 +44,10 @@ $laposte_carriers = array_map('intval',explode(',', Configuration::get('ANT_CARR $ooh = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_OOH'))); if(($id_order = (int) Tools::getValue('id_order')) -&& (Tools::getValue('token') === Tools::getAdminToken('AdminAntLogistic'.(int) Tab::getIdFromClassName('AdminAntLogistic').(int) Tools::getValue('id_employee')))) { + && (Tools::getValue('token') === Tools::getAdminToken('AdminAntLogistic'.(int) Tab::getIdFromClassName('AdminAntLogistic').(int) Tools::getValue('id_employee')))) { + + $profile = Tools::getValue('id_profile'); $order = new Order($id_order); - $profile = Tools::getValue('id_profil'); if(Validate::isLoadedObject($order)) { $locked_products = array(); $_locked_products = Configuration::get('LOGISTICS_LOCK'); @@ -89,9 +90,7 @@ if(($id_order = (int) Tools::getValue('id_order')) AND cl.`id_lang` = 2 '); } elseif(in_array((int) $order->id_carrier, $mr_carriers)) { - /** - * @Override MondialRelay - */ + // MondialRelay $delivery_infos_mr = Db::getInstance()->getRow(' SELECT mr_s.*, mr_m.*, cl.`name` AS `country_name` FROM `'._DB_PREFIX_.'mr_selected` mr_s @@ -109,7 +108,6 @@ if(($id_order = (int) Tools::getValue('id_order')) WHERE s.`id_cart` = '.(int) $order->id_cart.' '); } - // $delivery_infos_laposte = FALSE; } $delivery_infos_exapaq = Db::getInstance()->getRow(' @@ -151,41 +149,39 @@ if(($id_order = (int) Tools::getValue('id_order')) $link = new Link(2); $products = array(); foreach($order->getProductsDetail() as $p) { + // --- Get quantity sent + // LaPoste $p['product_quantity_sent'] += (int) Db::getInstance()->getValue(' SELECT IFNULL(SUM(`quantity`), 0) FROM `'._DB_PREFIX_.'lapostews` WHERE `id_order_detail` = '.(int) $p['id_order_detail'].' '); + // Exapaq $p['product_quantity_sent'] += (int) Db::getInstance()->getValue(' SELECT IFNULL(SUM(`quantity`), 0) FROM `'._DB_PREFIX_.'exapaqws` WHERE `id_order_detail` = '.(int) $p['id_order_detail'].' '); - /** - * @Override MondialRelay - */ + // MondialRelay $p['product_quantity_sent'] += (int) Db::getInstance()->getValue(' SELECT IFNULL(SUM(`quantity`), 0) FROM `'._DB_PREFIX_.'mondialrelay_parcel` WHERE `id_order_detail` = ' . (int) $p['id_order_detail'] . ' '); - /** - * @Override Philea - */ + // Philea $p['product_quantity_sent'] += (int) Db::getInstance()->getValue(' SELECT IFNULL(SUM(`quantity`), 0) FROM `'._DB_PREFIX_.'philea_parcel` WHERE `id_order_detail` = ' . (int) $p['id_order_detail'] . ' '); - /** - * @Override Dropshipping - */ + // DropShipping $p['product_quantity_sent'] += (int) Db::getInstance()->getValue(' SELECT IFNULL(SUM(`quantity`), 0) FROM `'._DB_PREFIX_.'ant_dropshipping_parcel` WHERE `id_order_detail` = ' . (int) $p['id_order_detail'] . ' '); + // Image $p['id_image'] = 0; if((int) $p['product_attribute_id'] != 0) { @@ -237,45 +233,42 @@ if(($id_order = (int) Tools::getValue('id_order')) $p['carriers'] = $sales_carriers[(int) $p['id_sale']]; - $p['location'] = isset($locations[(int) $p['product_id'].'-'.(int) $p['product_attribute_id']])? $locations[(int) $p['product_id'].'-'.(int) $p['product_attribute_id']]: ''; - + // --- Get Shipping Numbers $shipping_numbers = array(); + // Philea foreach(Db::getInstance()->ExecuteS(' SELECT l.`shipping_number` - FROM `'._DB_PREFIX_.'lapostews` l + FROM `'._DB_PREFIX_.'philea_parcel` l LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (d.`id_order_detail` = l.`id_order_detail`) LEFT JOIN `'._DB_PREFIX_.'order_history` h ON (h.`id_order` = d.`id_order`) WHERE h.`id_order` = '.(int) $order->id.' ') as $row) { $shipping_numbers[] = '"'.pSQL($row['shipping_number']).'"'; } + // LaPoste foreach(Db::getInstance()->ExecuteS(' - SELECT e.`shipping_number` - FROM `'._DB_PREFIX_.'exapaqws` e - LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (d.`id_order_detail` = e.`id_order_detail`) + SELECT l.`shipping_number` + FROM `'._DB_PREFIX_.'lapostews` l + LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (d.`id_order_detail` = l.`id_order_detail`) LEFT JOIN `'._DB_PREFIX_.'order_history` h ON (h.`id_order` = d.`id_order`) WHERE h.`id_order` = '.(int) $order->id.' ') as $row) { $shipping_numbers[] = '"'.pSQL($row['shipping_number']).'"'; } - /* - * @Override MondialRelay - */ + // Exapaq foreach(Db::getInstance()->ExecuteS(' - SELECT l.`shipping_number` - FROM `'._DB_PREFIX_.'mondialrelay_parcel` l - LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (d.`id_order_detail` = l.`id_order_detail`) + SELECT e.`shipping_number` + FROM `'._DB_PREFIX_.'exapaqws` e + LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (d.`id_order_detail` = e.`id_order_detail`) LEFT JOIN `'._DB_PREFIX_.'order_history` h ON (h.`id_order` = d.`id_order`) WHERE h.`id_order` = '.(int) $order->id.' ') as $row) { $shipping_numbers[] = '"'.pSQL($row['shipping_number']).'"'; } - /* - * @Override Philea - */ + // MondialRelay foreach(Db::getInstance()->ExecuteS(' SELECT l.`shipping_number` - FROM `'._DB_PREFIX_.'philea_parcel` l + FROM `'._DB_PREFIX_.'mondialrelay_parcel` l LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (d.`id_order_detail` = l.`id_order_detail`) LEFT JOIN `'._DB_PREFIX_.'order_history` h ON (h.`id_order` = d.`id_order`) WHERE h.`id_order` = '.(int) $order->id.' @@ -283,15 +276,15 @@ if(($id_order = (int) Tools::getValue('id_order')) $shipping_numbers[] = '"'.pSQL($row['shipping_number']).'"'; } - if(((int) $p['product_quantity_sent'] === 0) - && Db::getInstance()->getRow(' + if(((int) $p['product_quantity_sent'] === 0) && Db::getInstance()->getRow(' SELECT h.`id_sale` FROM `'._DB_PREFIX_.'shipping_history` h WHERE h.`id_sale` = '.((int) $p['id_sale'] === 999999? 0: (int) $p['id_sale']).' AND h.`id_order` = '.(int) $order->id.' '.(count($shipping_numbers) > 0? 'AND h.`shipping_number` NOT IN ('.implode(', ', $shipping_numbers).')': '').' ')) { - $p['product_quantity_sent'] = $p['product_quantity'] - ($p['product_quantity_return'] > 0? $p['product_quantity_return']: $p['product_quantity_refunded']); + $p['product_quantity_sent'] = $p['product_quantity'] - ( $p['product_quantity_return'] > 0 ? + $p['product_quantity_return']: $p['product_quantity_refunded'] ); } /* Pack */ @@ -317,64 +310,78 @@ if(($id_order = (int) Tools::getValue('id_order')) $carriers[(int) $row['id_carrier']] = $row['name']; } - if(count($id_order_details) > 0) { + if (count($id_order_details) > 0) { $logs = array(); + // Send by PHILEA if($l = Db::getInstance()->ExecuteS(' - SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, e.`firstname`, e.`lastname`, "laposte" AS `carrier` - FROM `'._DB_PREFIX_.'lapostews` l + SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, "Philea" as firstname, + (CASE c.`external_module_name` WHEN "soflexibilite" THEN "laposte" ELSE c.`external_module_name` END) as carrier, + "1" as philea + FROM `'._DB_PREFIX_.'philea_parcel` l + LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`id_order_detail` = l.`id_order_detail` + LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order` + LEFT JOIN `'._DB_PREFIX_.'carrier` c ON c.`id_carrier` = o.`id_carrier` + WHERE l.`id_order_detail` IN ('.implode(', ', $id_order_details).') + AND l.`quantity` > 0 + ORDER BY l.`date_add` DESC + ')) { + $logs = array_merge($logs, $l); + } + + // Send by LAPOSTE + if($l = Db::getInstance()->ExecuteS(' + SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, + e.`firstname`, e.`lastname`, "laposte" as carrier, "0" as philea + FROM `'._DB_PREFIX_.'lapostews` l LEFT JOIN `'._DB_PREFIX_.'employee` e ON l.`id_employee` = e.`id_employee` LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`id_order_detail` = l.`id_order_detail` + LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order` + LEFT JOIN `ps_carrier` c ON c.`id_carrier` = o.`id_carrier` WHERE l.`id_order_detail` IN ('.implode(', ', $id_order_details).') AND l.`quantity` > 0 ORDER BY l.`date_add` DESC ')) { $logs = array_merge($logs, $l); } + + // Send by EXAPAQ if($l = Db::getInstance()->ExecuteS(' - SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, e.`firstname`, e.`lastname`, "exapaq" AS `carrier` - FROM `'._DB_PREFIX_.'exapaqws` l + SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, + e.`firstname`, e.`lastname`, "exapaq" as carrier, "0" as philea + FROM `'._DB_PREFIX_.'exapaqws` l LEFT JOIN `'._DB_PREFIX_.'employee` e ON l.`id_employee` = e.`id_employee` LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`id_order_detail` = l.`id_order_detail` + LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order` + LEFT JOIN `'._DB_PREFIX_.'carrier` c ON c.`id_carrier` = o.`id_carrier` WHERE l.`id_order_detail` IN ('.implode(', ', $id_order_details).') AND l.`quantity` > 0 ORDER BY l.`date_add` DESC ')) { $logs = array_merge($logs, $l); } - /* - * @Override MondialRelay - */ + + // Send by MONDIAL RELAY if($l = Db::getInstance()->ExecuteS(' - SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, e.`firstname`, e.`lastname`, "mondialrelay" AS `carrier` - FROM `'._DB_PREFIX_.'mondialrelay_parcel` l - LEFT JOIN `'._DB_PREFIX_.'employee` e ON l.`id_employee` = e.`id_employee` + SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, + e.`firstname`, e.`lastname`, "mondialrelay" as carrier, "0" as philea + FROM `'._DB_PREFIX_.'mondialrelay_parcel` l + LEFT JOIN `'._DB_PREFIX_.'employee` e ON l.`id_employee` = e.`id_employee` LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`id_order_detail` = l.`id_order_detail` + LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order` + LEFT JOIN `ps_carrier` c ON c.`id_carrier` = o.`id_carrier` WHERE l.`id_order_detail` IN ('.implode(', ', $id_order_details).') AND l.`quantity` > 0 ORDER BY l.`date_add` DESC ')) { $logs = array_merge($logs, $l); } - /* - * @Override Dropshipping - */ + + // Send by DROPSHIPPING if($l = Db::getInstance()->ExecuteS(' - SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, "Dropshipping" as firstname - FROM `'._DB_PREFIX_.'ant_dropshipping_parcel` l - LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`id_order_detail` = l.`id_order_detail` - WHERE l.`id_order_detail` IN ('.implode(', ', $id_order_details).') - AND l.`quantity` > 0 - ORDER BY l.`date_add` DESC - ')) { - $logs = array_merge($logs, $l); - } - /* - * @Override Philea - */ - if($l = Db::getInstance()->ExecuteS(' - SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, "Philea" as firstname, c.`name` as carrier - FROM `'._DB_PREFIX_.'philea_parcel` l + SELECT l.*, d.`product_name`, d.`product_reference`, d.`product_supplier_reference`, + "Dropshipping" as firstname, "0" as philea + FROM `'._DB_PREFIX_.'ant_dropshipping_parcel` l LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`id_order_detail` = l.`id_order_detail` LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order` LEFT JOIN `'._DB_PREFIX_.'carrier` c ON c.`id_carrier` = o.`id_carrier` @@ -452,20 +459,20 @@ if(($id_order = (int) Tools::getValue('id_order')) $html_products = ''; foreach($products as $key => $p) { $html_products.=' -
'.$this->l('An error happened during the label rendering').'
'.$this->l('An error happened during the label rendering').'
'.$this->l('Registration complete, label sent to printer').'
'.$this->l('Registration complete, label sent to printer').'