611 lines
36 KiB
PHP
611 lines
36 KiB
PHP
<?php
|
|
require_once dirname(__FILE__).'/../../config/config.inc.php';
|
|
|
|
$laposte_modes = array(
|
|
'DOM' => 'SO à domicile',
|
|
'RDV' => 'SO sur RDV',
|
|
'BPR' => 'SO en bureau de poste',
|
|
'ACP' => 'SO en agence ColiPoste',
|
|
'CDI' => 'SO en centre de distribution',
|
|
'A2P' => 'SO en commerce de proximité',
|
|
'MRL' => 'SO à domicile (+?)',
|
|
'CIT' => 'SO en espace Cityssimo',
|
|
'DOS' => 'SO à domicile contre signature',
|
|
'COLI' => 'Colissimo Expert Inter',
|
|
'COL' => 'Colissimo Expert France',
|
|
'COM' => 'Colissimo Access OM',
|
|
'COLD' => 'Colissimo Access France',
|
|
'COE' => 'Colissimo Eco OM',
|
|
'CORE' => 'Colissimo Service France',
|
|
'CDS' => 'Colissimo Expert OM',
|
|
'COP' => 'Colissimo Expert Interne',
|
|
);
|
|
|
|
$mr_modes = array(
|
|
'24R' => '24R : Livraison dans un Point Relais',
|
|
'24L' => '24L : Livraison dans un Point Relais XL',
|
|
'24X' => '24X : Livraison dans un Point Relais XXL',
|
|
'DRI' => 'DRI : Livraison Colis Drive',
|
|
'LD1' => 'LD1 : Livraison à domicile RDC (1 personne)',
|
|
'LDS' => 'LDS : Livraison à domicile spécialisée (2 personnes)',
|
|
'HOM' => 'HOM : Livraison à domicile spécialisée',
|
|
);
|
|
|
|
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')
|
|
);
|
|
}
|
|
|
|
$mr_carriers = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_MR')));
|
|
$laposte_carriers = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_SOCOL')));
|
|
$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')))) {
|
|
|
|
$profile = Tools::getValue('id_profile');
|
|
$order = new Order($id_order);
|
|
if(Validate::isLoadedObject($order)) {
|
|
$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;
|
|
}
|
|
}
|
|
|
|
$customer = Db::getInstance()->getRow('
|
|
SELECT `firstname`, `lastname`, `email`
|
|
FROM `'._DB_PREFIX_.'customer`
|
|
WHERE `id_customer` = '.(int) $order->id_customer.'
|
|
');
|
|
|
|
$delivery_infos_laposte = FALSE;
|
|
$delivery_infos_exapaq = FALSE;
|
|
$delivery_infos_mr = FALSE;
|
|
|
|
if($order->id_carrier == Configuration::get('SOCOLISSIMO_CARRIER_ID')) {
|
|
$delivery_infos_laposte = Db::getInstance()->getRow('
|
|
SELECT i.*, cl.`name` AS `country_name`
|
|
FROM `'._DB_PREFIX_.'socolissimo_delivery_info` i
|
|
LEFT JOIN `'._DB_PREFIX_.'country` c
|
|
ON i.`cecountry` = c.`iso_code`
|
|
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl
|
|
ON c.`id_country` = cl.`id_country`
|
|
WHERE i.`id_cart` = '.(int) $order->id_cart.'
|
|
AND cl.`id_lang` = 2
|
|
');
|
|
} elseif(in_array((int) $order->id_carrier, $mr_carriers)) {
|
|
// MondialRelay
|
|
$delivery_infos_mr = Db::getInstance()->getRow('
|
|
SELECT mr_s.*, mr_m.*, cl.`name` AS `country_name`
|
|
FROM `'._DB_PREFIX_.'mr_selected` mr_s
|
|
LEFT JOIN `'._DB_PREFIX_.'country` c ON (mr_s.`MR_Selected_Pays` = c.`iso_code`)
|
|
LEFT JOIN `'._DB_PREFIX_.'mr_method` mr_m ON (mr_m.`id_mr_method` = mr_s.`id_method`)
|
|
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country`)
|
|
WHERE mr_s.`id_cart` = '.(int) $order->id_cart.'
|
|
AND cl.`id_lang` = 2
|
|
');
|
|
if(!$delivery_infos_mr || empty($delivery_infos_mr)) {
|
|
$delivery_infos_mr = Db::getInstance()->getRow('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'mr_selected` s
|
|
INNER JOIN `'._DB_PREFIX_.'mr_method` m ON (m.`id_mr_method` = s.`id_method`)
|
|
WHERE s.`id_cart` = '.(int) $order->id_cart.'
|
|
');
|
|
}
|
|
}
|
|
|
|
$delivery_infos_exapaq = Db::getInstance()->getRow('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'icirelais_selected`
|
|
WHERE `id_cart` = '.(int) $order->id_cart.'
|
|
');
|
|
|
|
$status = Db::getInstance()->getRow('
|
|
SELECT `name`
|
|
FROM `'._DB_PREFIX_.'order_state_lang`
|
|
WHERE `id_order_state` = '.(int) $order->getCurrentState().'
|
|
AND `id_lang` = 2
|
|
');
|
|
|
|
$locations = array();
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
SELECT d.`product_id`, d.`product_attribute_id`, IF(IFNULL(a.`location`, "") = "", p.`location`, a.`location`) AS `location`
|
|
FROM `'._DB_PREFIX_.'order_detail` d
|
|
LEFT JOIN `'._DB_PREFIX_.'product` p
|
|
ON p.`id_product` = d.`product_id`
|
|
LEFT JOIN `'._DB_PREFIX_.'product_attribute` a
|
|
ON a.`id_product_attribute` = d.`product_attribute_id`
|
|
WHERE d.`id_order` = '.(int) $order->id.'
|
|
') as $row) {
|
|
$locations[(int) $row['product_id'].'-'.(int) $row['product_attribute_id']] = $row['location'];
|
|
}
|
|
|
|
$invoice_address = new Address($order->id_address_invoice);
|
|
$delivery_address = new Address($order->id_address_delivery);
|
|
|
|
$france_address_error = FALSE;
|
|
$france_address_suggestions = array();
|
|
|
|
$id_order_details = array();
|
|
|
|
$sales_carriers = array();
|
|
|
|
$link = new Link(2);
|
|
$products = array();
|
|
foreach($order->getProductsDetail() as $p) {
|
|
// --- Get quantity sent
|
|
$p['product_quantity_sent'] = 0;
|
|
// 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']
|
|
);
|
|
// 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']
|
|
);
|
|
// 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']
|
|
);
|
|
// 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) {
|
|
$img = Db::getInstance()->getRow('
|
|
SELECT `id_image`
|
|
FROM `'._DB_PREFIX_.'product_attribute_image`
|
|
WHERE `id_product_attribute` = '.(int) $p['product_attribute_id'].'
|
|
');
|
|
|
|
$p['id_image'] = $img['id_image'];
|
|
}
|
|
|
|
if ($p['id_image'] == 0) {
|
|
$img = Db::getInstance()->getRow('
|
|
SELECT `id_image`
|
|
FROM `'._DB_PREFIX_.'image`
|
|
WHERE `cover` = 1
|
|
AND `id_product` = '.(int) $p['product_id'].'
|
|
');
|
|
|
|
$p['id_image'] = $img['id_image'];
|
|
}
|
|
|
|
$p['image'] = '//'.$link->getImageLink('image', $p['product_id'].'-'.$p['id_image'], 'home');
|
|
|
|
$p['id_shipping'] = 1;
|
|
$p['id_sale'] = (int) Db::getInstance()->getValue('
|
|
SELECT `id_sale`
|
|
FROM `'._DB_PREFIX_.'product_ps_cache`
|
|
WHERE `id_product` = '.(int) $p['product_id'].'
|
|
');
|
|
|
|
$p['is_pending'] = Db::getInstance()->getValue('
|
|
SELECT COUNT(id_product)
|
|
FROM `'._DB_PREFIX_.'logistics_pending`
|
|
WHERE `id_product` = '.(int) $p['product_id'].' AND id_order = '.(int)$id_order
|
|
);
|
|
|
|
if (!isset($sales_carriers[(int) $p['id_sale']])) {
|
|
$sales_carriers[(int) $p['id_sale']] = array();
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
SELECT `id_carrier`
|
|
FROM `'._DB_PREFIX_.'privatesale_carrier`
|
|
WHERE `id_sale` = '.(int) $p['id_sale'].'
|
|
') as $row) {
|
|
$sales_carriers[(int) $p['id_sale']][] = (int) $row['id_carrier'];
|
|
}
|
|
}
|
|
|
|
$p['carriers'] = $sales_carriers[(int) $p['id_sale']];
|
|
|
|
// --- Get Shipping Numbers
|
|
$shipping_numbers = array();
|
|
// Philea
|
|
foreach (Db::getInstance()->ExecuteS('
|
|
SELECT l.`shipping_number`
|
|
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 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']).'"';
|
|
}
|
|
// Exapaq
|
|
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`)
|
|
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']).'"';
|
|
}
|
|
// MondialRelay
|
|
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`)
|
|
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']).'"';
|
|
}
|
|
if ((int)$p['product_quantity_sent'] === 0) {
|
|
if (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']
|
|
);
|
|
}
|
|
}
|
|
|
|
/* Pack */
|
|
if (Pack::isPack($p['product_id'])){
|
|
$p['items_pack'] = Pack::getCompleteSimplePack((int) $p['product_id']);
|
|
}
|
|
|
|
$products[] = $p;
|
|
$id_order_details[] = (int) $p['id_order_detail'];
|
|
}
|
|
|
|
$id_carriers = array((int) $order->id_carrier);
|
|
foreach(array_values($sales_carriers) as $c) {
|
|
$id_carriers = array_merge($id_carriers, $c);
|
|
}
|
|
|
|
$carriers = array();
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
SELECT `id_carrier`, `name`
|
|
FROM `'._DB_PREFIX_.'carrier`
|
|
WHERE `id_carrier` IN ('.implode(', ', array_unique($id_carriers)).')
|
|
') as $row) {
|
|
$carriers[(int) $row['id_carrier']] = $row['name'];
|
|
}
|
|
|
|
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`, "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, "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);
|
|
}
|
|
|
|
// 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, "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);
|
|
}
|
|
|
|
// Send by DROPSHIPPING
|
|
if($l = Db::getInstance()->ExecuteS('
|
|
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`
|
|
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);
|
|
}
|
|
} else {
|
|
$logs = array();
|
|
}
|
|
|
|
// Carriers
|
|
$_carriers = $carriers[$order->id_carrier].($delivery_infos_laposte
|
|
? ' ('.$laposte_modes[$delivery_infos_laposte['delivery_mode']].')'
|
|
: ($delivery_infos_exapaq
|
|
? ' (ICI Relais)'
|
|
: ($delivery_infos_mr
|
|
? ' ('.$mr_modes[$delivery_infos_mr['dlv_mode']].')'
|
|
: ''
|
|
)
|
|
)
|
|
);
|
|
|
|
$html_detail = '<ul class="list-unstyled">
|
|
<li style="margin-bottom:5px;" class="text-center"><strong>'.$status['name'].'</strong></li>
|
|
<li><span class="anticon anticon-cart"></span> '.$order->id_cart.'</li>
|
|
<li><span class="anticon anticon-user"></span> '.$customer['firstname'].' '.$customer['lastname'].' ('.$customer['email'].')'.'</li>
|
|
<li><span class="anticon anticon-calendar"></span> '.date('d/m/Y H:i:s',strtotime($order->date_add)).'</li>
|
|
<li><span class="anticon anticon-'.($order->payment=='Paybox'?'credit-card':'paypal').'"></span> '.$order->payment.'</li>
|
|
<li><span class="anticon anticon-truck"></span> '.$_carriers.'</li>
|
|
</ul>';
|
|
|
|
$html_invoice_address = ($invoice_address->company? $invoice_address->company.'<br />':'')
|
|
.$invoice_address->firstname.' '.$invoice_address->lastname.'<br />'
|
|
.($invoice_address->address1? $invoice_address->address1.'<br />': '')
|
|
.($invoice_address->address2? $invoice_address->address2.'<br />': '')
|
|
.$invoice_address->postcode.' '.$invoice_address->city.'<br />'
|
|
.($invoice_address->country? $invoice_address->country.'<br />':'')
|
|
.($invoice_address->phone? $invoice_address->phone.'<br />':'')
|
|
.($invoice_address->phone_mobile? $invoice_address->phone_mobile.'<br />':'');
|
|
|
|
if(in_array((int) $order->id_carrier,$ooh) && in_array((int) $order->id_carrier,$mr_carriers)){
|
|
$html_delivery_address = ($delivery_address->company? $delivery_address->company.'<br />':'')
|
|
.$delivery_address->firstname.' '.$delivery_address->lastname.'<br />'
|
|
.($delivery_infos_mr['MR_Selected_LgAdr1']?$delivery_infos_mr['MR_Selected_LgAdr1'].'<br />':'')
|
|
.($delivery_infos_mr['MR_Selected_LgAdr2']?$delivery_infos_mr['MR_Selected_LgAdr2'].'<br />':'')
|
|
.($delivery_infos_mr['MR_Selected_LgAdr3']?$delivery_infos_mr['MR_Selected_LgAdr3'].'<br />':'')
|
|
.($delivery_infos_mr['MR_Selected_LgAdr4']?$delivery_infos_mr['MR_Selected_LgAdr4'].'<br />':'')
|
|
.$delivery_infos_mr['MR_Selected_CP'].' '.$delivery_infos_mr['MR_Selected_Ville'].'<br />'
|
|
.$delivery_infos_mr['MR_Selected_Pays'].'<br />';
|
|
} elseif (in_array((int) $order->id_carrier,$ooh) && in_array((int) $order->id_carrier,$laposte_carriers) && $delivery_infos_laposte){
|
|
$html_delivery_address = ($delivery_infos_laposte['prcompladress']? $delivery_infos_laposte['prcompladress'].'<br />': '')
|
|
.$delivery_infos_laposte['prfirstname'].' '.$delivery_infos_laposte['prname'].'<br />'
|
|
.$delivery_infos_laposte['cefirstname'].' '.$delivery_infos_laposte['cename'].'<br />'
|
|
.($delivery_infos_laposte['pradress1']? $delivery_infos_laposte['pradress1'].'<br />': '')
|
|
.($delivery_infos_laposte['pradress2']? $delivery_infos_laposte['pradress2'].'<br />': '')
|
|
.($delivery_infos_laposte['pradress3']? $delivery_infos_laposte['pradress3'].'<br />': '')
|
|
.($delivery_infos_laposte['pradress4']? $delivery_infos_laposte['pradress4'].'<br />': '')
|
|
.$delivery_infos_laposte['przipcode'].' '.$delivery_infos_laposte['prtown'].'<br />'
|
|
.$delivery_infos_laposte['country_name'].'<br />'
|
|
.($delivery_infos_laposte['cephonenumber']? $delivery_infos_laposte['cephonenumber'].'<br />':'');
|
|
} else {
|
|
$html_delivery_address = ($delivery_address->company? $delivery_address->company.'<br />':'')
|
|
.$delivery_address->firstname.' '.$delivery_address->lastname.'<br />'
|
|
.($delivery_address->address1? $delivery_address->address1.'<br />':'')
|
|
.($delivery_address->address2? $delivery_address->address2.'<br />':'')
|
|
.$delivery_address->postcode.' '.$delivery_address->city.'<br />'
|
|
.($delivery_address->country? $delivery_address->country.'<br />':'')
|
|
.($delivery_address->phone? $delivery_address->phone.'<br />':'')
|
|
.($delivery_address->phone_mobile? $delivery_address->phone_mobile.'<br />':'');
|
|
}
|
|
|
|
$html_products = '';
|
|
foreach($products as $key => $p) {
|
|
$html_products.='
|
|
<tr data-weight="'.((float)($products[$key]['product_weight']) == 0.001 ? 0.24 : $products[$key]['product_weight']).'" data-carrier="'.implode(',',$products[$key]['carriers']).'" rel="'.($products[$key]['product_ean13'] ? $products[$key]['product_ean13'] : '').'"
|
|
class="'
|
|
.($products[$key]['id_shipping'] == 2 ? 'fed_ship' : '')
|
|
.(in_array($products[$key]['product_id'], $locked_products) ? 'blocked' : '')
|
|
.(($products[$key]['product_quantity'] - ($products[$key]['product_quantity_refunded'] > 0 ? $products[$key]['product_quantity_refunded']: $products[$key]['product_quantity_return']) - $products[$key]['product_quantity_sent'] > 0) && (in_array((int)($products[$key]['id_sale']), $sales_list)) ? '' : 'grey')
|
|
.(max(in_array($products[$key]['product_id'], $locked_products)? 0: ($products[$key]['product_quantity'] - ($products[$key]['product_quantity_refunded'] > 0? $products[$key]['product_quantity_refunded']: $products[$key]['product_quantity_return']) - $products[$key]['product_quantity_sent']), 0) > 1 ? ' blue' : '')
|
|
.'"';
|
|
if(isset($p['items_pack'])){
|
|
foreach($p['items_pack'] as $item){
|
|
$html_products.='data-pack_'.$item['id_product'].'="'.$item['pack_quantity'].'"';
|
|
}
|
|
}
|
|
$html_products.='
|
|
>
|
|
<td>'.(isset($p['items_pack'])?'<strong>LOT</strong>':'<img src="'.$products[$key]['image'].'" alt="" width="200" height="200" />').'</td>
|
|
<td style="font-size:16px;"><strong>'.str_replace(' - ','<br>',$products[$key]['product_name']).'</strong></td>
|
|
<td class="right">'.($products[$key]['product_reference']? $products[$key]['product_reference'].'<br />': '').($products[$key]['product_ean13']? $products[$key]['product_ean13']: '').($products[$key]['location']?'<br /><span class="location">'.$products[$key]['location'].'</span>': '').'</td>
|
|
<td class="right" style="display: none;">'.($products[$key]['product_supplier_reference']? $products[$key]['product_supplier_reference']: '').'</td>
|
|
<td class="center"><span style="font-size:18px;opacity:0.4">'.$products[$key]['product_quantity'].' / '.($products[$key]['product_quantity_refunded'] > 0 ? $products[$key]['product_quantity_refunded']: $products[$key]['product_quantity_return']).' / '.$products[$key]['product_quantity_sent'].'</span></td>
|
|
<td style="font-size:18px;" class=" center toship'.($products[$key]['product_quantity'] - $products[$key]['product_quantity_return'] - $products[$key]['product_quantity_sent'] == 0? ' bg-danger': '').'"><strong>'.max(in_array($products[$key]['product_id'], $locked_products)? '0': ($products[$key]['product_quantity'] - ($products[$key]['product_quantity_refunded'] > 0? $products[$key]['product_quantity_refunded']: $products[$key]['product_quantity_return']) - $products[$key]['product_quantity_sent']), 0).'</strong></td>
|
|
<td class="center"><input type="checkbox" name="product_ids[]" value="'.$products[$key]['product_id'].'" '.($products[$key]['is_pending']>0?'checked disabled':'').'/></td>
|
|
<td class="shipped text-center">';
|
|
|
|
if ($products[$key]['id_shipping'] != 2
|
|
|| ($products[$key]['id_shipping'] == 2 && in_array((int)$profile, array(1,7)))
|
|
) {
|
|
if(isset($p['items_pack'])){
|
|
$html_products.='<input class="input_quantity" readonly="true" onchange="checkParcelCarrier($(this));" name="shipped['.$products[$key]['id_order_detail'].']" type="text" value="0" autocomplete="off" />';
|
|
} else {
|
|
$html_products.='<input class="input_quantity" readonly="true" onchange="checkParcelCarrier($(this));" name="shipped['.$products[$key]['id_order_detail'].']" type="text" value="0" autocomplete="off" /><span class="qtyblock"><a onclick="qtyUp($(this), '.(in_array($products[$key]['product_id'], $locked_products)? 0: max(($products[$key]['product_quantity'] - ($products[$key]['product_quantity_refunded'] > 0? $products[$key]['product_quantity_refunded']: $products[$key]['product_quantity_return']) - $products[$key]['product_quantity_sent']), 0)).'); return false;">+</a><a class="qty_down" onclick="qtyDown($(this)); return false;">-</a></span>';
|
|
}
|
|
}
|
|
$html_products.='
|
|
</td>
|
|
</tr>';
|
|
if(isset($p['items_pack'])){
|
|
foreach($p['items_pack'] as $item){
|
|
$link = new Link(2);
|
|
$img = Db::getInstance()->getRow('
|
|
SELECT `id_image`
|
|
FROM `'._DB_PREFIX_.'image`
|
|
WHERE `cover` = 1
|
|
AND `id_product` = '.(int) $item['id_product'].'
|
|
');
|
|
$id_image = $img?$img['id_image']:0;
|
|
$quantity = ($p['product_quantity']*$item['pack_quantity']) - ($p['product_quantity_return']*$item['pack_quantity']) - ($p['product_quantity_sent']*$item['pack_quantity']);
|
|
$html_products.='
|
|
<tr class="pack_'.$p['id_order_detail'].' pack_item '
|
|
.(in_array($products[$key]['product_id'], $locked_products)? 'blocked': '')
|
|
.(($products[$key]['product_quantity'] - ($products[$key]['product_quantity_refunded'] > 0? $products[$key]['product_quantity_refunded']: $products[$key]['product_quantity_return']) - $products[$key]['product_quantity_sent'] > 0) && (in_array((int)($products[$key]['id_sale']), $sales_list))? '': 'grey')
|
|
.(max(in_array($products[$key]['product_id'], $locked_products)? 0: ($products[$key]['product_quantity'] - ($products[$key]['product_quantity_refunded'] > 0? $products[$key]['product_quantity_refunded']: $products[$key]['product_quantity_return']) - $products[$key]['product_quantity_sent']), 0) > 1? ' blue': '').'"
|
|
data-weight="'.((float)($item['weight']) == 0.001? 0.24: $item['weight']*$item['pack_quantity']).'" rel="'.($item['ean13']? $item['ean13'].'_pack': '').'"
|
|
>
|
|
<td><img src="'.'//'.$link->getImageLink('image', $item['id_product'].'-'.$id_image, 'home').'"/></td>
|
|
<td style="font-size:16px;"><strong>'.str_replace(' - ','<br>',$item['name']).'</strong></td>
|
|
<td class="right">'.($item['reference']? $item['reference'].'<br />': '').($item['ean13']? $item['ean13']: '').($item['location']?'<br /><span class="location">'.$item['location'].'</span>': '').'</td>
|
|
<td class="right" style="display: none;">'.($item['supplier_reference']? $item['supplier_reference']: '').'</td>
|
|
<td></td>
|
|
<td style="font-size:18px;" class=" center toship'.($quantity == 0? ' bg-danger': '').'"><strong>'.max(in_array($p['product_id'], $locked_products)? '0': (($p['product_quantity']*$item['pack_quantity']) - (($p['product_quantity_refunded']*$item['pack_quantity']) > 0? $p['product_quantity_refunded']*$item['pack_quantity']: ($p['product_quantity_return']*$item['pack_quantity'])) - ($p['product_quantity_sent']*$item['pack_quantity'])), 0).'</strong></td>
|
|
<td></td>
|
|
<td class="shipped text-center">';
|
|
if ($products[$key]['id_shipping'] != 2
|
|
|| ($products[$key]['id_shipping'] == 2 && in_array((int)$profile, array(1,7)))
|
|
) {
|
|
$html_products.='<input data-item="'.$item['id_product'].'" data-id_order_detail="'.$p['id_order_detail'].'" class="input_quantity" readonly="true" onchange="checkQuantityPack('.$p['id_order_detail'].');" type="text" value="0" autocomplete="off" /><span class="qtyblock"><a onclick="qtyUp($(this), '.(in_array($products[$key]['product_id'], $locked_products)? 0: max(($products[$key]['product_quantity']*$item['pack_quantity'] - ($products[$key]['product_quantity_refunded']*$item['pack_quantity'] > 0? $products[$key]['product_quantity_refunded']*$item['pack_quantity']: $products[$key]['product_quantity_return']*$item['pack_quantity']) - $products[$key]['product_quantity_sent']*$item['pack_quantity']), 0)).'); return false;">+</a><a class="qty_down" onclick="qtyDown($(this)); return false;">-</a></span>';
|
|
}
|
|
$html_products.='
|
|
</td>
|
|
</tr>';
|
|
}
|
|
}
|
|
}
|
|
|
|
$carrier_names = array('laposte' => 'La Poste', 'mondialrelay' => 'Mondial Relay');
|
|
$html_logs = '';
|
|
foreach($logs as $key => $log){
|
|
$html_logs .=
|
|
'<tr>
|
|
<td>'.str_replace(" ", "<br />",date('d/m/Y H:i:s',strtotime($logs[$key]['date_add']))).'</td>\
|
|
<td>'.(!isset($logs[$key]['lastname'])? $logs[$key]['firstname'] : $logs[$key]['firstname'] .' '.$logs[$key]['lastname']) .'</td>
|
|
<td class="text-center">'.$logs[$key]['quantity'].'</td>
|
|
<td>'.str_replace(" - ", "<br />",$logs[$key]['product_name']).'</td>\
|
|
<td>'.$logs[$key]['product_reference'].'</td>
|
|
<td>'.$logs[$key]['product_supplier_reference'].'</td>
|
|
<td>'.$logs[$key]['shipping_number'].'</td>
|
|
<td>'.(($logs[$key]['carrier'] == "laposte" || $logs[$key]['carrier'] == "mondialrelay") ? $carrier_names[$logs[$key]['carrier']] : $logs[$key]['carrier']) .'</td>
|
|
'.(( in_array((int)$profile, array(1,9,7,13,14)) ) ?
|
|
(($logs[$key]['carrier'] == "laposte" || $logs[$key]['carrier'] == "mondialrelay") ? '<td><a class="need_token" href="/adm/index.php?tab=AdminAntLogistic&id_order='.$order->id.'&delete_'.$logs[$key]['carrier'].'='.$logs[$key]['id_order_detail'].'&delete_number='.$logs[$key]['shipping_number'].'"><span class="anticon anticon-bin"></span></a></td>': '<td></td>'):'<td></td>').'
|
|
'.(( in_array((int)$profile, array(1,9,7,13,14)) )?
|
|
(($logs[$key]['carrier'] == "laposte" || $logs[$key]['carrier'] == "mondialrelay") ? '<td><a title="Re print" data-toggle="modal" data-target="#modalRePrint" class="reprint" data-product="'.str_replace(" - ", "<br />",$logs[$key]['product_name']).'" data-weight="'.((float)$logs[$key]['weight']>0?(float)$logs[$key]['weight']:0.24).'" data-ref="'.$logs[$key]['product_reference'] .'" data-id_order="'.$order->id.'" data-carrier="'.$logs[$key]['carrier'].'" data-id_order_detail="'.$logs[$key]['id_order_detail'].'"><span class="anticon anticon-printer"></span></a></td>': '<td></td>'):'<td></td>').'
|
|
</tr>';
|
|
}
|
|
|
|
$html_form ='<div class="form-inline">';
|
|
if((in_array($order->id_carrier, $laposte_carriers)
|
|
|| in_array($order->id_carrier, $mr_carriers))
|
|
&& in_array((int)($delivery_address->id_country),
|
|
array(1, 2, 3, 6, 8, 10, 12, 13, 15, 17, 26, 40, 148, 245)) ){
|
|
$html_form.=
|
|
'<div class="form-group">
|
|
<label for="parcel_carrier">Transporteur :</label>
|
|
<select class="form-control input-sm" onchange="changeCarrier();" id="parcel_carrier" name="parcel_carrier">
|
|
<option value="laposte">La Poste</option>
|
|
<option value="mondialrelay">Mondial Relay</option>
|
|
</select>
|
|
</div>';
|
|
}
|
|
$html_form .= '
|
|
<div class="form-group">
|
|
<label for="weight">Poids :</label>
|
|
<div class="input-group">
|
|
<input style="width:60px;" class="form-control input-sm" type="text" value="0" name="weight" id="weight" />
|
|
<div class="input-group-addon">kg</div>
|
|
</div>
|
|
</div>
|
|
<input id="button4" onclick="checkPrinting(); return false;" type="submit" class="pull-right btn btn-primary btn-sm" name="submitShip" value="[F1] Enregistrer le colis et imprimer l\'étiquette">
|
|
</div>';
|
|
|
|
echo json_encode(array(
|
|
'errors' => false,
|
|
'html_detail' => (string)$html_detail,
|
|
'html_invoice_address' => (string)$html_invoice_address,
|
|
'html_delivery_address' => (string)$html_delivery_address,
|
|
'html_products' => (string)$html_products,
|
|
'html_logs' => (string)$html_logs,
|
|
'html_form' => (string)$html_form,
|
|
'order' => $order,
|
|
'products' => $products,
|
|
'status' => $status['name'],
|
|
'carrier' => $_carriers,
|
|
'carriers' => $carriers,
|
|
'customer' => $customer['firstname'].' '.$customer['lastname'].' ('.$customer['email'].')',
|
|
'invoice_address' => $invoice_address,
|
|
'delivery_address' => $delivery_address,
|
|
'delivery_infos_laposte' => $delivery_infos_laposte,
|
|
'delivery_infos_exapaq' => $delivery_infos_exapaq,
|
|
'delivery_infos_mr' => $delivery_infos_mr,
|
|
'weight' => $order->getTotalWeight(),
|
|
'logs' => $logs,
|
|
'france_address_error' => $france_address_error,
|
|
'france_address_suggestions' => $france_address_suggestions,
|
|
));
|
|
} else {
|
|
echo json_encode(array('errors' => 'not found'));
|
|
}
|
|
}
|