Merge branch 'ticket-14739-PackLogistic' into develop

This commit is contained in:
Marion Muszynski 2017-11-29 14:48:49 +01:00
commit addf696db6
82 changed files with 106234 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,600 @@
<?php
include_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')))) {
$order = new Order($id_order);
$profile = Tools::getValue('id_profil');
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)) {
/**
* @Override 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_laposte = FALSE;
}
$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) {
$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'].'
');
$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
*/
$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
*/
$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
*/
$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'] . '
');
$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']];
$p['location'] = isset($locations[(int) $p['product_id'].'-'.(int) $p['product_attribute_id']])? $locations[(int) $p['product_id'].'-'.(int) $p['product_attribute_id']]: '';
$shipping_numbers = array();
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']).'"';
}
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']).'"';
}
/*
* @Override 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']).'"';
}
/*
* @Override 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']).'"';
}
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']);
}
/* 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();
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
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`
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);
}
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
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`
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
*/
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`
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 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
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 && ($profile == 1 || $profile == 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 && ($profile == 1 || $profile == 7))
) {
$html_products.='<input data-item="'.$item['id_product'].'" class="input_quantity" readonly="true" onchange="checkQuantityPack($(this),'.$item['id_product'].','.$p['id_order_detail'].','.$item['pack_quantity'].','.(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)).');" 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>
'.(((int) $profile == 1 || (int) $profile == 9 || (int) $profile == 7 || (int) $profile == 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>').'
'.(((int) $profile == 1 || (int) $profile == 9 || (int) $profile == 7 || (int) $profile == 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'));
}
}

View File

@ -0,0 +1,30 @@
<?php
if (!defined('_PS_VERSION_'))
exit;
class Ant_Logistic extends Module
{
public function __construct()
{
$this->name = 'ant_logistic';
$this->tab = 'administration';
$this->author = 'Antadis';
$this->version = '1.0';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Logistic manager');
$this->description = $this->l('Manager of logistic to send parcel for orders');
}
public function install()
{
# Register hooks
if(!(parent::install())) {
return false;
}
return true;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,108 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_PORT'] = 80;
include dirname(__FILE__).'/../../../../config/config.inc.php';
$count = (int) Configuration::get('EXAPAQWS_CRONCOUNT') + 1;
if($count > 99) {
Configuration::updateValue('EXAPAQWS_CRONCOUNT', 0);
$count = 1;
}
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_QUOTES, 'UTF-8')
);
}
$csv = fopen(dirname(__FILE__).'/summaries/'.strtolower(str_replace(' ', '', trim(stripaccents(Configuration::get('EXAPAQWS_EXP_COMPANY'))))).date('dmHis').sprintf('%02d', $count).'.txt', 'w');
foreach(Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'exapaqws_parcel_route`
WHERE `date_add` >= "'.pSQL($lastsummary = Configuration::get('EXAPAQWS_LASTSUMMARY')? $lastsummary: '0000-00-00 00:00:00').'"
ORDER BY `date_add` ASC
') as $row) {
$order = new Order((int) $row['id_order']);
if(!Validate::isLoadedObject($order)) {
// TODO
continue;
}
$delivery_infos = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'icirelais_selected`
WHERE `id_cart` = '.(int) $order->id_cart.'
');
$customer = new Customer((int) $order->id_customer);
$delivery_address = new Address($order->id_address_delivery);
fputcsv($csv, array(
substr($row['shipping_number'], 0, 18), // exapass
number_format($row['weight'], 2, '.', ''), // weight
substr('EXP'.(int) $order->id, 0, 35), // ref 1
'', // ref 2
'', // order id
'', // consolidation
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_COMPANY'))), 0, 12)), // exp company
date('d.m.Y', strtotime($row['date_add'])), // exp date
date('H:i:s', strtotime($row['date_add'])), // exp time
substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_'.($delivery_infos? 'B2C': 'B2B').'_COUNTRY_RETURN'))), 0, 6), // exp country
substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $row['ac'])), 0, 3), // ac
substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $row['tour'])), 0, 3), // tour
'', // value
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? $delivery_address->lastname.' '.$delivery_address->firstname: ($delivery_address->company != ''? $delivery_address->company.' ': '').$delivery_address->lastname.' '.$delivery_address->firstname)), 0, 35)), // dest name
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? $delivery_infos['address1']: $delivery_address->address1)), 0, 35)), // dest addr 1
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? $delivery_infos['address2']: $delivery_address->address2)), 0, 35)), // dest addr 2
'', // dest addr 3
'', // dest addr 4
'', // dest addr 5
'', // dest addr 6
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? $delivery_infos['postcode']: $delivery_address->postcode)), 0, 10)), // dest postcode
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? $delivery_infos['city']: $delivery_address->city)), 0, 35)), // dest city
substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $row['lpfx'])), 0, 3), // dest country
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_address->phone)), 0, 35)), // dest phone
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_COMPANY'))), 0, 35)), // exp company
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_ADDR1'))), 0, 35)), // exp addr 1
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_ADDR2'))), 0, 35)), // exp addr 2
'', // exp addr 3
'', // exp addr 4
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_POSTALCODE'))), 0, 10)), // exp postcode
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_CITY'))), 0, 35)), // exp city
strtoupper(Country::getIsoById((int) Configuration::get('EXAPAQWS_EXP_COUNTRY'))), // exp country
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_PHONE'))), 0, 30)), // exp phone
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_EMAIL'))), 0, 80)), // exp email
'', // exp mobile
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $customer->email)), 0, 80)), // dest email
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_address->phone_mobile)), 0, 35)), // dest mobile
'', // consolidation
substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_'.($delivery_infos? 'B2C': 'B2B').'_COUNTRY_AGENCY'))), 0, 6), // country + agency
'', // exasanté
$delivery_infos? 101: 1, // notification options
$delivery_infos? 2: 1, // service type
substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_'.($delivery_infos? 'B2C': 'B2B').'_CHARGING_ACCOUNT'))), 0, 6), // charging account
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', substr($delivery_address->lastname, 0, 30))), // dest lastname
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', substr($delivery_address->firstname, 0, 20))), // dest firstname
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? substr($delivery_infos['relay_id'], 0, 20): '')), // relay id
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? substr($delivery_infos['company'], 0, 50): '')), // relay company
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? substr($delivery_infos['address1'], 0, 40): '')), // relay addr 1
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? substr($delivery_infos['address2'], 0, 40): '')), // relay addr 2
'', // relay addr 3
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? substr($delivery_infos['postcode'], 0, 5): '')), // relay postcode
trim(str_replace(array("\n", "\r", '~', ';', '|'), '', $delivery_infos? substr($delivery_infos['city'], 0, 30): '')), // relay city
10, // keeping duration
stripaccents(mb_substr(trim(str_replace(array("\n", "\r", '~', ';', '|'), '', Configuration::get('EXAPAQWS_EXP_COMPANY'))), 0, 35)), // company name
), '|', '"');
}
fclose($csv);

View File

@ -0,0 +1,45 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_PORT'] = 80;
include dirname(__FILE__).'/../../../../config/config.inc.php';
$file = gzopen(dirname(__FILE__).'/plan2.gz', 'r');
fgets($file);
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'exapaqws_route`
');
while($line = fgets($file)) {
if($line == 'F') {
break;
}
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'exapaqws_route`
VALUES (
"'.pSQL(substr($line, 0, 2)).'",
"'.pSQL(substr($line, 2, 3)).'",
"'.pSQL(substr($line, 5, 10)).'",
"'.pSQL(substr($line, 15, 10)).'",
"'.pSQL(substr($line, 25, 1)).'",
"'.pSQL(substr($line, 26, 2)).'",
"'.pSQL(substr($line, 28, 1)).'",
"'.pSQL(substr($line, 29, 2)).'",
"'.pSQL(substr($line, 32, 3)).'",
"'.pSQL(substr($line, 35, 3)).'",
"'.pSQL(substr($line, 38, 3)).'",
"'.pSQL(substr($line, 41, 3)).'",
"'.pSQL(substr($line, 51, 3)).'",
"'.pSQL(substr($line, 54, 4)).'",
"'.pSQL(substr($line, 58, 1)).'"
)
');
}
gzclose($file);

View File

@ -0,0 +1,746 @@
<?php
if(!defined('_PS_VERSION_')) {
exit;
}
global $exapaq_formats;
$exapaq_formats = array(
'DOM' => '191100005670040Soumis aux conditions générales de vente de la FFOCT et aux conditions
191100005610040particulières de prestation d\'EXAPAQ. Notre responsabilité est contractuellement
191100005540040limitée à EUR 23,00 par KG transporté.
211200005500335EXAPAQ 6
211200005500322FR-06580 PEGOMAS
1Y1100002900320{EXASANTE}
1d0309204560100{EXAPASS_BARCODE}
1X1100005470100l01800003
1X1100004530100l01800003
1X1100002620040b0245018900010001
1X1100002620255l00010188
1X1100000070186b0165025300020002
1e230080000{SHIPPING_ALIGN}{SHIPPING_BC}
1X1100000070113b0071025300010001
1X1100000070040b0040025300010001'
/*FB+
292200203840295G 1/2
FB-*/
.'291100704480250{TOURPRINT}
2911007{TOURALIGN}0250{TOUR}
291100702870250{SMALL}
291100704150215{TRI1}
2911004{LIGNE1_ALIGN}0200{LIGNE1}
291100703150215{TRI2}
2911004{LIGNE2_ALIGN}0200{LIGNE2}
{PRETRI1}
2911008{ACPRINT_ALIGN}0150{ACPRINT}
{PRETRI2}
2e2309203980060C{CBTRI}
191100304330097{EXAPASS_PARCEL}
291100203800042{WEIGHT} kg
291100203200042{DATE}
291100504500010{MSG}
291100102550338Destinataire
291100201950338Tél.: {DADDR_0}
291100302550321{DADDR_1}
291100302550306{DADDR_2}
291100302550291{DADDR_3}
291100302550276{DADDR_4}
291100302550261{DADDR_5}
291100302550246{DADDR_6}
291100302550231{DADDR_7}
FB+
2911A1802550205{LPFX}-{DADDR_8}
FB-
291200202550187{DADDR_9}
291100202550171Expéditeur Tél.: {SADDR_0}
291100202550160{SADDR_1}
291100202550149{SADDR_2}
291100202550138{SADDR_3}
291100202550127{SADDR_4}
291100202550115F-{SADDR_5}
1X1100000070100b0013010000010001
FB+
2911A0801030101Nb.:
2911A08003201011 / 1
FB-
291100202550098N'.chr(248).' réf.:
291100202550085EXP{REFERENCE}
291100202550065{DADDR_INSTR1}
291100202550045{DADDR_INSTR2}
',
'ICI' => '191100005740040ICI Colis est un produit d\'ICI relais, marque appartenant à Exapaq SAS.
191100005670040Soumis aux conditions générales de vente de la FFOCT et aux conditions
191100005610040particulières de prestation d\'EXAPAQ. Notre responsabilité est contractuellement
191100005540040limitée à EUR 23,00 par KG transporté.
291100105780342ICI COLIS
291100105780335www.icirelais.com
1Y1100003400290ICICOLIS
1d0309204560100{EXAPASS_BARCODE}
1X1100005470100l01800003
1X1100004530100l01800003
1X1100002620040b0245018900010001
1X1100002620255l00010188
1X1100000070186b0165025300020002
1e230080000{SHIPPING_ALIGN}{SHIPPING_BC}
1X1100000070113b0071025300010001
1X1100000070040b0040025300010001
291100704480250{TOURPRINT}
2911007{TOURALIGN}0250{TOUR}
291100702870250{SMALL}
291100704150215{TRI1}
2911004{LIGNE1_ALIGN}0200{LIGNE1}
291100703150215{TRI2}
2911004{LIGNE2_ALIGN}0200{LIGNE2}
{PRETRI1}
2911008{ACPRINT_ALIGN}0150{ACPRINT}
{PRETRI2}
2e2309203980060C{CBTRI}
191100304330097{EXAPASS_PARCEL}
291100203800042{WEIGHT} kg
291100203200042{DATE}
291100102550338Destinataire
FB+
2911A1402550315RELAIS : {PR}
FB-
2X1100000090313l00020250
291100102550304Pour :
291100302550290{DADDR_3}
291100302550276{DADDR_4}
2X1100000090274l00020250
291100302550258{DADDR_0}
291100302550244{DADDR_1}
291100302550230F-{DADDR_2}
FB+
2911A0802520213POUR RETOUR CONTACTER L\'EXPEDITEUR
FB-
A5
1X1100000090206l00250249
A2
291100202550171Expéditeur Tél.: {SADDR_0}
291100202550160{SADDR_1}
291100202550149{SADDR_2}
291100202550138{SADDR_3}
291100202550127{SADDR_4}
291100202550115F-{SADDR_5}
1X1100000070100b0013010000010001
FB+
2911A0801030101Nb.:
2911A08003201011 / 1
FB-
291100202550098N'.chr(248).' réf.:
291100202550085EXP{REFERENCE}
291100202550067ICI-PASS
FB+
2911A1202300045{EXAPASS}
FB-
',
);
class ExapaqCarrier {
public $displayName = 'Exapaq';
public function checkavailability() {
return TRUE;
}
public function __toString() {
return $this->displayName;
}
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')
);
}
public function registerParcel($order, $products, $weight) {
if((int) Db::getInstance()->getValue('
SELECT `id_cart`
FROM `'._DB_PREFIX_.'icirelais_selected`
WHERE `id_cart` = (
SELECT `id_cart`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_order` = '.(int) $order->id.'
LIMIT 1
)
')) {
$delivery_mode = 'b2c';
} else {
$delivery_mode = 'b2b';
}
$shipping_number = sprintf('%09d', $this->getShippingNumber((int) $order->id));
$exapass = '250'.sprintf('%03d', Configuration::get('EXAPAQWS_'.strtoupper($delivery_mode).'_AGENCYCODE')).$shipping_number;
$key1 = sprintf('%02d', (98 - ((int) $exapass * 100 % 97)) % 97);
$exapass .= $key1;
$i = (int) substr($exapass, 0, 1) + (int) substr($exapass, 2, 1) + (int) substr($exapass, 4, 1) + (int) substr($exapass, 6, 1) + (int) substr($exapass, 8, 1) + (int) substr($exapass, 10, 1) + (int) substr($exapass, 12, 1) + (int) substr($exapass, 14, 1) + (int) substr($exapass, 16, 1);
$p = (int) substr($exapass, 1, 1) + (int) substr($exapass, 3, 1) + (int) substr($exapass, 5, 1) + (int) substr($exapass, 7, 1) + (int) substr($exapass, 9, 1) + (int) substr($exapass, 11, 1) + (int) substr($exapass, 13, 1) + (int) substr($exapass, 15, 1);
$t = ($i * 3) + $p;
$m = ceil($t / 10) * 10;
$key2 = (($m - $t) + 1) % 10;
$exapass .= $key2;
if($_SERVER['REMOTE_ADDR'] != '109.190.53.175' && $_SERVER['REMOTE_ADDR'] != '78.226.56.137' && $_SERVER['REMOTE_ADDR'] != '88.163.22.223') {
$order->shipping_number = $exapass;
$order->id_carrier_shipping = (int) Configuration::get('ICIRELAIS_ID_CARRIER');
$order->update();
}
return array('', array(
'exapass' => $exapass,
'shipping_number' => $shipping_number,
));
}
public function getShippingNumber($id_order) {
if((int) Db::getInstance()->getValue('
SELECT `id_cart`
FROM `'._DB_PREFIX_.'icirelais_selected`
WHERE `id_cart` = (
SELECT `id_cart`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_order` = '.(int) $id_order.'
LIMIT 1
)
')) {
$delivery_mode = 'b2c';
} else {
$delivery_mode = 'b2b';
}
Db::getInstance()->Execute('SET AUTOCOMMIT = 0');
Db::getInstance()->Execute('START TRANSACTION');
$res = Db::getInstance()->ExecuteS('
SELECT `value`
FROM `'._DB_PREFIX_.'logistics_shipping`
WHERE `carrier` = "exapaq"
AND `delivery_mode` = "'.pSQL($delivery_mode).'"
FOR UPDATE
');
$shipping_number = (int) $res[0]['value'] + 1;
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'logistics_shipping`
SET `value` = "'.(int) $shipping_number.'"
WHERE `carrier` = "exapaq"
AND `delivery_mode` = "'.pSQL($delivery_mode).'"
');
Db::getInstance()->Execute('COMMIT');
Db::getInstance()->Execute('SET AUTOCOMMIT = 1');
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'exapaqws_shippingnumber`
VALUES (
'.(int) $shipping_number.',
'.(int) $id_order.'
)
');
if((int) $shipping_number + 2000 >= (int) Configuration::get('EXAPAQWS_'.strtoupper($delivery_mode).'_SHIPPINGHIGH')) { // TODO: Move to cron
mail('perron@antadis.com', '[PSS] Renouvellement Plage '.strtoupper($delivery_mode).' Exapaq', $shipping_number);
}
return $shipping_number;
}
public function renderLabel($order, $weight, $shipping_data) {
global $cookie, $exapaq_formats;
$exp_firstname = Configuration::get('EXAPAQWS_EXP_FIRSTNAME');
$exp_lastname = Configuration::get('EXAPAQWS_EXP_LASTNAME');
$exp_company = Configuration::get('EXAPAQWS_EXP_COMPANY');
if(!empty($exp_firstname)) {
$sender_lines[] = $exp_firstname.' '.$exp_lastname;
}
if(!empty($exp_company)) {
$sender_lines[] = $exp_company;
}
$sender_lines[] = Configuration::get('EXAPAQWS_EXP_ADDR1');
$sender_lines[] = Configuration::get('EXAPAQWS_EXP_ADDR2');
$sender_line1 = isset($sender_lines[0])? $sender_lines[0]: '';
$sender_line2 = isset($sender_lines[1])? $sender_lines[1]: '';
$sender_line3 = isset($sender_lines[2])? $sender_lines[2]: '';
$sender_line4 = isset($sender_lines[3])? $sender_lines[3]: '';
$sender_postal = Configuration::get('EXAPAQWS_EXP_POSTALCODE');
$sender_city = Configuration::get('EXAPAQWS_EXP_CITY');
$sender_phone = Configuration::get('EXAPAQWS_EXP_PHONE');
if($delivery_infos = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'icirelais_selected`
WHERE `id_cart` = '.(int) $order->id_cart.'
')) {
$delivery_address = new Address((int) $order->id_address_delivery);
if(!Validate::isLoadedObject($delivery_address) || strtoupper(Country::getIsoById($delivery_address->id_country)) != 'FR') {
return FALSE;
}
$route = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'exapaqws_route`
WHERE `iso_code` = "FR"
AND (
("'.pSQL($delivery_infos['postcode']).'" BETWEEN `postcode_start` AND `postcode_end`)
OR (`postcode_start` IS NULL)
OR (`postcode_start` = "")
)
');
if(!$route) {
return 'route_error';
}
$shipping_number = $shipping_data['shipping_number'];
$exapass = $shipping_data['exapass'];
$exapass_legend = substr($exapass, 0, 15);
$i = (int) substr($exapass_legend, 0, 1) + (int) substr($exapass_legend, 2, 1) + (int) substr($exapass_legend, 4, 1) + (int) substr($exapass_legend, 6, 1) + (int) substr($exapass_legend, 8, 1) + (int) substr($exapass_legend, 10, 1) + (int) substr($exapass_legend, 12, 1) + (int) substr($exapass_legend, 14, 1);
$p = (int) substr($exapass_legend, 1, 1) + (int) substr($exapass_legend, 3, 1) + (int) substr($exapass_legend, 5, 1) + (int) substr($exapass_legend, 7, 1) + (int) substr($exapass_legend, 9, 1) + (int) substr($exapass_legend, 11, 1) + (int) substr($exapass_legend, 13, 1);
$t = ($i * 3) + $p;
$m = ceil($t / 10) * 10;
$key3 = $m - $t;
$exapass_legend .= $key3;
$dest_name0 = '';
$dest_name1 = '';
if($delivery_address->company == '') {
$dest_name0 = mb_substr($delivery_address->lastname, 0, 32);
$dest_name1 = mb_substr($delivery_address->firstname, 0, 32);
} else {
$dest_name0 = mb_substr($delivery_address->lastname, 0, 32);
$dest_name1 = mb_substr($delivery_address->company, 0, 32);
}
$shipping_bc = mb_substr(mb_strtoupper($this->stripaccents(str_replace(
array(' ', '', '', '', '“', '”', '„', '†', '‡', '‰', '', '', '♠', '♣', '♥', '♦', '‾', '←', '↑', '→', '↓', '™', '', '!', '“', '#', '$', '%', '&', '', '(', ')', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', ']', '_', '`', '{', '|', '', '}', '~', '', '—', '¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯', ),
'',
trim($delivery_infos['relay_id'])
))), 0, 12);
$format = str_replace(
array(
'{EXAPASS_BARCODE}',
'{SHIPPING_BC}',
'{SHIPPING_ALIGN}',
'{TOURPRINT}',
'{TOUR}',
'{TOURALIGN}',
'{SMALL}',
'{TRI1}',
'{LIGNE1}',
'{LIGNE1_ALIGN}',
'{TRI2}',
'{LIGNE2}',
'{LIGNE2_ALIGN}',
'{ACPRINT}',
'{ACPRINT_ALIGN}',
'{PRETRI1}',
'{PRETRI2}',
'{CBTRI}',
'{EXAPASS_PARCEL}',
'{WEIGHT}',
'{DATE}',
'{PR}',
'{DADDR_0}',
'{DADDR_1}',
'{DADDR_2}',
'{DADDR_3}',
'{DADDR_4}',
'{SADDR_0}',
'{SADDR_1}',
'{SADDR_2}',
'{SADDR_3}',
'{SADDR_4}',
'{SADDR_5}',
'{REFERENCE}',
'{EXAPASS}',
),
array(
$exapass,
$shipping_bc,
strlen($shipping_bc) == 12? '0103': (strlen($shipping_bc) == 11? '0118': (strlen($shipping_bc) == 10? '0136': (strlen($shipping_bc) == 9? '0153': (strlen($shipping_bc) == 8? '0168': (strlen($shipping_bc) == 7? '0183': (strlen($shipping_bc) == 6? '0198': (strlen($shipping_bc) == 5? '0212': (strlen($shipping_bc) == 4? '0233': (strlen($shipping_bc) == 3? '0248': '0263'))))))))),
trim($route['tourprint']),
trim($route['tour']),
strlen(trim($route['tour'])) == 1? '0368': (strlen(trim($route['tour'])) == 2? '0376': '0384'),
(float) $weight <= 1.0? 'P': '',
trim($route['tri1']),
trim($route['ligne1']),
strlen(trim($route['tri1'])) == 1? '0409': '0413',
trim($route['tri2']),
trim($route['ligne2']),
strlen(trim($route['tri2'])) == 1? '0309': '0313',
trim($route['acprint']),
strlen(trim($route['acprint'])) == 1? '0366': (strlen(trim($route['acprint'])) == 2? '0378': '0390'),
strtoupper(trim($route['pretri'])) == 'BOX'? '1X1100003950162l00250032': '',
strtoupper(trim($route['pretri'])) == 'BOX'? '1X1100002850162l00250032': '',
trim($route['cbtri']),
substr($exapass_legend, 3, 3).' '.substr($exapass_legend, 6, 9).' '.substr($exapass_legend, 15, 1),
number_format($weight * 0.8, 2, '.', ''),
date('d.m.Y'),
$delivery_infos['relay_id'],
mb_substr(mb_strtoupper($this->stripaccents($delivery_infos['company'])), 0, 32),
mb_substr(mb_strtoupper($this->stripaccents($delivery_infos['address1'])), 0, 32),
mb_substr(mb_strtoupper($this->stripaccents($delivery_infos['postcode'].' '.$delivery_infos['city'])), 0, 32),
mb_strtoupper($this->stripaccents($dest_name0)),
mb_strtoupper($this->stripaccents($dest_name1)),
$sender_phone,
$sender_line1,
$sender_line3,
$sender_line4,
$sender_line2,
$sender_postal.' '.$sender_city,
$order->id,
substr($exapass, 0, 3).' '.substr($exapass, 3, 3).' '.substr($exapass, 6, 9).' '.substr($exapass, 15),
),
$exapaq_formats['ICI']
);
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'exapaqws_parcel_route` VALUES (
"'.pSQL($exapass).'",
'.(int) $order->id.',
'.((float) $weight * 0.8).',
"'.pSQL($route['iso_code']).'",
"'.pSQL($route['lpfx']).'",
"'.pSQL($route['tri1']).'",
"'.pSQL($route['ligne1']).'",
"'.pSQL($route['tri2']).'",
"'.pSQL($route['ligne2']).'",
"'.pSQL($route['ac']).'",
"'.pSQL($route['acprint']).'",
"'.pSQL($route['tour']).'",
"'.pSQL($route['tourprint']).'",
"'.pSQL($route['pretri']).'",
"'.pSQL($route['cbtri']).'",
"'.pSQL($route['msg'] == 1? 'EXPORT A REETIQUETER': ($route['msg'] == 2? 'EXPORT A REETIQUETER AU TRI': '')).'"
)
');
return $format;
} else {
$delivery_address = new Address((int) $order->id_address_delivery);
if(!Validate::isLoadedObject($delivery_address)/* || strtoupper(Country::getIsoById($delivery_address->id_country)) != 'FR'*/) {
return FALSE;
}
$route = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'exapaqws_route`
WHERE `iso_code` = "'.pSQL(strtoupper(Country::getIsoById($delivery_address->id_country))).'"
AND (
("'.pSQL($delivery_address->postcode).'" BETWEEN `postcode_start` AND `postcode_end`)
OR (`postcode_start` IS NULL)
OR (`postcode_start` = "")
)
');
if(!$route) {
return 'route_error';
}
$shipping_number = $shipping_data['shipping_number'];
$exapass = $shipping_data['exapass'];
$exapass_legend = substr($exapass, 0, 15);
$i = (int) substr($exapass_legend, 0, 1) + (int) substr($exapass_legend, 2, 1) + (int) substr($exapass_legend, 4, 1) + (int) substr($exapass_legend, 6, 1) + (int) substr($exapass_legend, 8, 1) + (int) substr($exapass_legend, 10, 1) + (int) substr($exapass_legend, 12, 1) + (int) substr($exapass_legend, 14, 1);
$p = (int) substr($exapass_legend, 1, 1) + (int) substr($exapass_legend, 3, 1) + (int) substr($exapass_legend, 5, 1) + (int) substr($exapass_legend, 7, 1) + (int) substr($exapass_legend, 9, 1) + (int) substr($exapass_legend, 11, 1) + (int) substr($exapass_legend, 13, 1);
$t = ($i * 3) + $p;
$m = ceil($t / 10) * 10;
$key3 = $m - $t;
$exapass_legend .= $key3;
$dest_lines = array();
if($delivery_address->company != '') {
$dest_lines[] = trim(mb_substr($delivery_address->company, 0, 32));
}
if(mb_strlen($delivery_address->lastname.' '.$delivery_address->firstname) > 32) {
$dest_lines[] = trim(mb_substr($delivery_address->lastname, 0, 32));
$dest_lines[] = trim(mb_substr($delivery_address->firstname, 0, 32));
} else {
$dest_lines[] = trim(mb_substr($delivery_address->lastname.' '.$delivery_address->firstname, 0, 32));
}
if(mb_strlen($delivery_address->address1) > 32) {
$dest_lines[] = trim(mb_substr($delivery_address->address1, 0, 32));
$dest_lines[] = trim(mb_substr($delivery_address->address1, 32));
} else {
$dest_lines[] = trim($delivery_address->address1);
}
if(mb_strlen($delivery_address->address2) > 32) {
$dest_lines[] = trim(mb_substr($delivery_address->address2, 0, 32));
$dest_lines[] = trim(mb_substr($delivery_address->address2, 32));
} else {
$dest_lines[] = trim($delivery_address->address2);
}
$shipping_bc = mb_substr(mb_strtoupper($this->stripaccents(str_replace(
array(' ', '', '', '', '“', '”', '„', '†', '‡', '‰', '', '', '♠', '♣', '♥', '♦', '‾', '←', '↑', '→', '↓', '™', '', '!', '“', '#', '$', '%', '&', '', '(', ')', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', ']', '_', '`', '{', '|', '', '}', '~', '', '—', '¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯', ),
'',
trim($delivery_address->company != ''? $delivery_address->company: $delivery_address->lastname.' '.$delivery_address->firstname)
))), 0, 12);
$format = str_replace(
array(
'{EXASANTE}',
'{EXAPASS_BARCODE}',
'{SHIPPING_BC}',
'{SHIPPING_ALIGN}',
'{TOURPRINT}',
'{TOUR}',
'{TOURALIGN}',
'{SMALL}',
'{TRI1}',
'{LIGNE1}',
'{LIGNE1_ALIGN}',
'{TRI2}',
'{LIGNE2}',
'{LIGNE2_ALIGN}',
'{ACPRINT}',
'{ACPRINT_ALIGN}',
'{PRETRI1}',
'{PRETRI2}',
'{CBTRI}',
'{EXAPASS_PARCEL}',
'{WEIGHT}',
'{DATE}',
'{MSG}',
'{DADDR_0}',
'{DADDR_1}',
'{DADDR_2}',
'{DADDR_3}',
'{DADDR_4}',
'{DADDR_5}',
'{DADDR_6}',
'{DADDR_7}',
'{DADDR_8}',
'{DADDR_9}',
'{SADDR_0}',
'{SADDR_1}',
'{SADDR_2}',
'{SADDR_3}',
'{SADDR_4}',
'{SADDR_5}',
'{REFERENCE}',
'{DADDR_INSTR1}',
'{DADDR_INSTR2}',
'{LPFX}',
),
array(
(int) Configuration::get('EXPAQWS_EXASANTE')? 'EXASANTE': '',
$exapass,
$shipping_bc,
strlen($shipping_bc) == 12? '0103': (strlen($shipping_bc) == 11? '0118': (strlen($shipping_bc) == 10? '0136': (strlen($shipping_bc) == 9? '0153': (strlen($shipping_bc) == 8? '0168': (strlen($shipping_bc) == 7? '0183': (strlen($shipping_bc) == 6? '0198': (strlen($shipping_bc) == 5? '0212': (strlen($shipping_bc) == 4? '0233': (strlen($shipping_bc) == 3? '0248': '0263'))))))))),
trim($route['tourprint']),
trim($route['tour']),
strlen(trim($route['tour'])) == 1? '0368': (strlen(trim($route['tour'])) == 2? '0376': '0384'),
(float) $weight <= 1.0? 'P': '',
trim($route['tri1']),
trim($route['ligne1']),
strlen(trim($route['tri1'])) == 1? '0409': '0413',
trim($route['tri2']),
trim($route['ligne2']),
strlen(trim($route['tri2'])) == 1? '0309': '0313',
trim($route['acprint']),
strlen(trim($route['acprint'])) == 1? '0366': (strlen(trim($route['acprint'])) == 2? '0378': '0390'),
strtoupper(trim($route['pretri'])) == 'BOX'? '1X1100003950162l00250032': '',
strtoupper(trim($route['pretri'])) == 'BOX'? '1X1100002850162l00250032': '',
trim($route['cbtri']),
substr($exapass_legend, 3, 3).' '.substr($exapass_legend, 6, 9).' '.substr($exapass_legend, 15, 1),
number_format($weight * 0.8, 2, '.', ''),
date('d.m.Y'),
(int) $route['msg'] == 1? 'EXPORT A REETIQUETER': ((int) $route['msg'] == 2? 'EXPORT A REETIQUETER AU TRI': ''),
$delivery_address->phone_mobile != ''? $delivery_address->phone_mobile: $delivery_address->phone,
isset($dest_lines[0])? $dest_lines[0]: '',
isset($dest_lines[1])? $dest_lines[1]: '',
isset($dest_lines[2])? $dest_lines[2]: '',
isset($dest_lines[3])? $dest_lines[3]: '',
isset($dest_lines[4])? $dest_lines[4]: '',
isset($dest_lines[5])? $dest_lines[5]: '',
isset($dest_lines[6])? $dest_lines[6]: '',
$delivery_address->postcode,
mb_substr(mb_strtoupper($this->stripaccents($delivery_address->city)), 0, 42),
$sender_phone,
$sender_line1,
$sender_line3,
$sender_line4,
$sender_line2,
$sender_postal.' '.$sender_city,
$order->id,
mb_substr($delivery_address->other, 0, 32),
mb_substr($delivery_address->other, 32, 32),
trim($route['lpfx']),
),
$exapaq_formats['DOM']
);
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'exapaqws_parcel_route` VALUES (
"'.pSQL($exapass).'",
'.(int) $order->id.',
'.((float) $weight * 0.8).',
"'.pSQL($route['iso_code']).'",
"'.pSQL($route['lpfx']).'",
"'.pSQL($route['tri1']).'",
"'.pSQL($route['ligne1']).'",
"'.pSQL($route['tri2']).'",
"'.pSQL($route['ligne2']).'",
"'.pSQL($route['ac']).'",
"'.pSQL($route['acprint']).'",
"'.pSQL($route['tour']).'",
"'.pSQL($route['tourprint']).'",
"'.pSQL($route['pretri']).'",
"'.pSQL($route['cbtri']).'",
"'.pSQL($route['msg'] == 1? 'EXPORT A REETIQUETER': ($route['msg'] == 2? 'EXPORT A REETIQUETER AU TRI': '')).'"
)
');
return $format;
}
return FALSE;
}
public function logParcel($shipping_data, $products) {
global $cookie;
foreach($products as $k => $v) {
if($v > 0) {
Db::getInstance()->ExecuteS('
INSERT `'._DB_PREFIX_.'exapaqws` VALUES (
'.(int) $k.',
'.(int) $cookie->id_employee.',
'.(int) $v.',
"'.pSQL($shipping_data['exapass']).'",
NOW()
)
');
}
}
}
public function addOrderHistory($shipping_data, $order, $products_sent) {
global $cookie;
$exapaq_carrier_id = unserialize(Configuration::get('EXAPAQWS_CARRIERS'));
$exapaq_carrier_id = (int) array_pop($exapaq_carrier_id);
$carrier = new Carrier($exapaq_carrier_id? $exapaq_carrier_id: (int) Configuration::get('ICIRELAIS_ID_CARRIER'), (int) $cookie->id_lang);
$customer = new Customer((int) $order->id_customer);
$templateVars = array(
'{followup}' => str_replace('@', $shipping_data['exapass'], $carrier->url),
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{id_order}' => (int) $order->id,
'{product_list}' => !empty($products_sent)? '<strong>Contenu du colis :</strong>'.$products_sent: '',
'{product_list_txt}' => !empty($products_sent)? 'Contenu du colis :'.strip_tags($products_sent): '',
);
$history = new OrderHistory();
$history->id_order = (int) $order->id;
$fully_sent = TRUE;
$products_sent = array();
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'exapaqws` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] > 0) {
$fully_sent = FALSE;
break;
} else {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
$order_sales = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT `id_sale`
FROM `'._DB_PREFIX_.'privatesale`
WHERE `id_category` IN (
SELECT `id_category_default`
FROM `'._DB_PREFIX_.'product`
WHERE `id_product` IN (
SELECT `product_id`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order->id.'
'.(count($products_sent) > 0? ' AND `id_order_detail` NOT IN ('.implode(', ', $products_sent).')': '').'
)
)
') as $order_sale) {
$order_sales[] = (int) $order_sale['id_sale'];
}
if(Db::getInstance()->getRow('
SELECT `product_id`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order->id.'
'.(count($products_sent) > 0? ' AND `id_order_detail` NOT IN ('.implode(', ', $products_sent).')': '').'
AND `product_id` IN (
SELECT `id_product` FROM `'._DB_PREFIX_.'product_ps_cache` WHERE `id_sale` = 0
)
')) {
$order_sales[] = 999999;
}
if(count($order_sales) > 0) {
$cpt = array(1 => 0, 2 => 0);
foreach(Db::getInstance()->ExecuteS('
SELECT `id_shipping`, COUNT(`id_sale`) AS `sale_count`
FROM `'._DB_PREFIX_.'privatesale_shipping_sale`
WHERE `id_sale` IN ('.implode(', ', $order_sales).')
AND `id_sale` NOT IN (
SELECT `id_sale`
FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` = '.(int) $order->id.'
AND `id_sale` IN ('.implode(', ', $order_sales).')
)
GROUP BY `id_shipping`
') as $cpt_sale) {
$cpt[(int) $cpt_sale['id_shipping']] = (int) $cpt_sale['sale_count'];
}
if($cpt[1] == 0 && $cpt[2] == 0) {
$fully_sent = TRUE;
}
}
$history->changeIdOrderState(($fully_sent? Configuration::get('PS_OS_SHIPPING'): 17), (int) $order->id);
$history->id_employee = (int) $cookie->id_employee;
$history->addWithemail(TRUE, $templateVars);
global $_LANGMAIL;
$subject = 'Package in transit';
Mail::Send(
intval($order->id_lang),
'in_transit',
(
(is_array($_LANGMAIL) && key_exists($subject, $_LANGMAIL))
? $_LANGMAIL[$subject]
: $subject
),
$templateVars,
$customer->email,
$customer->firstname.' '.$customer->lastname
);
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,43 @@
<?php
include dirname(__FILE__).'/../../../../config/config.inc.php';
if(($date = Tools::getValue('date'))
&& (Tools::getValue('token') === Tools::getAdminToken('AdminLaPosteSummary'.(int) Tab::getIdFromClassName('AdminLaPosteSummary').(int) Tools::getValue('id_employee')))) {
$carts = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT o.`id_cart`
FROM `'._DB_PREFIX_.'lapostews` w, `'._DB_PREFIX_.'order_detail` d, `'._DB_PREFIX_.'orders` o
WHERE w.`id_order_detail` = d.`id_order_detail`
AND d.`id_order` = o.`id_order`
AND w.`date_add` > "'.pSQL(date('Y-m-d 00:00:00', strtotime($date))).'"
AND w.`date_add` <= "'.pSQL(date('Y-m-d 23:59:59', strtotime($date))).'"
') as $cart) {
$carts[] = (int) $cart['id_cart'];
}
$modes = array();
$dom = Db::getInstance()->getRow('
SELECT COUNT(o.*) AS `total`
FROM `'._DB_PREFIX_.'orders` o
WHERE o.`id_cart` IN ('.implode(', ', $carts).'
AND o.`id_cart` NOT IN (
SELECT i.`id_cart`
FROM `'._DB_PREFIX_.'socolissimo_delivery_info` i
)
');
if($dom['total'] > 0) {
$modes[] = 'dom';
}
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT `delivery_mode`
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` IN ('.implode(', ', $carts).')
') as $dm) {
$modes[] = strtolower($dm['delivery_mode']);
}
echo json_encode(array_unique($modes));
}

View File

@ -0,0 +1,39 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_PORT'] = 80;
include dirname(__FILE__).'/../../../../config/config.inc.php';
$f = fopen(dirname(__FILE__).'/PDR.csv', 'r');
fgetcsv($f);
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'lapostews_pr`
');
while($line = fgetcsv($f, 0, ';')) {
if($line[0] == 'PR') {
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'lapostews_pr`
VALUES (
"'.pSQL($line[1]).'",
"'.pSQL($line[2]).'",
"'.pSQL($line[3]).'",
"'.pSQL($line[4]).'",
"'.pSQL($line[5]).'",
"'.pSQL($line[6]).'",
"'.pSQL($line[7]).'",
"'.pSQL($line[8]).'",
"'.pSQL($line[9]).'",
"'.pSQL($line[10]).'",
"'.pSQL($line[12]).'",
"'.pSQL($line[14]).'",
"'.pSQL($line[15]).'"
)
');
}
}
fclose($f);

View File

@ -0,0 +1,19 @@
<?php
include dirname(__FILE__).'/../../../../config/config.inc.php';
if((Tools::getValue('token') === Tools::getAdminToken('AdminLaPosteSummary'.(int) Tab::getIdFromClassName('AdminLaPosteSummary').(int) Tools::getValue('id_employee')))
&& ($pdf_date = Tools::getValue('date')) && ($pdf_dm = Tools::getValue('dm')) && in_array($pdf_dm, array('dom', 'cit', 'acp', 'cdi', 'col', 'a2p', 'dos', 'rdv', 'bpr', 'cold'))) {
$pdf_date = (string) (int) $pdf_date;
$pdf_date = substr($pdf_date, 0, 4).'-'.substr($pdf_date, 4, 2).'-'.substr($pdf_date, 6);
if(is_file(dirname(__FILE__).'/summaries/'.$pdf_date.'_'.$pdf_dm.'.pdf')) {
header('Content-type: application/pdf');
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Content-disposition: inline; filename="'.$pdf_date.'_'.$pdf_dm.'.pdf"');
readfile(dirname(__FILE__).'/summaries/'.$pdf_date.'_'.$pdf_dm.'.pdf');
} else {
echo 'ERROR - File not found';
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,192 @@
<html>
<head>
<style type="text/css">{literal}
body {
margin: 0px;
padding: 0px;
font-family: sans-serif;
font-size: 11px;
line-height: 16px;
}
table {
border-collapse: collapse;
width: 100%;
}
td {
vertical-align: top;
}
thead th, .bar {
background: #cccccc;
text-align: left;
font-weight: normal;
}
thead th, tbody td {
padding: 2px 4px;
}
.right {
text-align: right;
}
.strong {
font-weight: bold;
}
.width1 {
width: 100px;
}
.width0 {
width: 20px;
}
.border td {
width: 250px;
border: 1px solid #000000;
padding: 10px;
}
{/literal}</style>
</head>
<body>
{literal}
<!--mpdf
<htmlpagefooter name="myfooter">
<div style="text-align: right;">
Page {PAGENO}/{nb}
</div>
</htmlpagefooter>
<sethtmlpagefooter name="myfooter" value="on" />
mpdf-->
{/literal}
<table>
<tr>
<td>SITE DE PRISE EN CHARGE : {$site_code}</td>
<td class="right strong">BORDEREAU DE REMISE Offre Entreprises So Colissimo</td>
</tr>
<tr>
<td colspan="2">LIBELLE SITE DE PRISE EN CHARGE : {$site}</td>
</tr>
</table>
<table>
<tr>
<td class="width1">N° CLIENT</td><td class="width0">:</td><td>{$contract}</td>
<td class="right">EDITE LE {$date}</td>
</tr>
<tr>
<td class="width1">LIBELLE CLIENT</td><td class="width0">:</td>
<td colspan="2">{foreach $sender_lines as $line}{$line}<br />{/foreach}
{$sender_postal} {$sender_city}<br /><br /><br /><br /></td>
</tr>
<tr>
<td class="width1">N° BORDEREAU</td><td class="width0">:</td><td colspan="2">{$summary_number} du {$date}</td>
</tr>
<tr>
<td class="strong" colspan="3"><br />{$title} - Compte de facturation : {$contract}</td>
</tr>
</table>
{assign var=i value=1}
<table>
<thead>
<tr>
<th>Ref exped</th><th>Adresse destinataire</th><th>N° colis</th><th>CPOST</th><th>CPAYS</th><th>Poids</th><th>N</th><th>CRBT</th><th>VA</th>
</th>
</thead>
<tfoot>
<tr><td class="bar" colspan="9"></td></tr>
<tr>
<td colspan="9">
<br />
NOMBRE DES COLIS DE LA PAGE : {if $count_orders <= 46}
{$count_orders}
{else}
46
{/if}
<br />
POIDS DES COLIS DE LA PAGE : {if $count_orders <= 46}
{$total_weight|number_format:2:',':''}
{else}
{(0.24*46)|number_format:2:',':''}
{/if} KG<br />
TOTAL CRBT DE LA PAGE : 0,00 EUR<br />
</td>
</tr>
</tfoot>
<tbody>
{foreach $orders as $order name=orders}
<tr>
<td>EXP{$order.id_order}</td>
<td>{$order.lastname|cat:' - '|cat:$order.address1|truncate:60:''}</td>
<td>{$order.shipping_number}</td>
<td>{$order.postcode}</td>
<td>FR</td>
<td>0,24</td>
<td>0</td>
<td>000.00</td>
<td>00</td>
</tr>
{if $smarty.foreach.orders.iteration % 46 == 0 && $smarty.foreach.orders.iteration != $smarty.foreach.orders.total}
{assign var=i value=$i+1}
</tbody>
</table>
<formfeed />
<table>
<thead>
<tr>
<th>Ref exped</th><th>Adresse destinataire</th><th>N° colis</th><th>CPOST</th><th>CPAYS</th><th>Poids</th><th>N</th><th>CRBT</th><th>VA</th>
</th>
</thead>
<tfoot>
<tr><td class="bar" colspan="9"></td></tr>
<tr>
<td colspan="9">
<br />
NOMBRE DES COLIS DE LA PAGE : {if $smarty.foreach.orders.iteration + 46 > $smarty.foreach.orders.total}
{$smarty.foreach.orders.total - $smarty.foreach.orders.iteration}
{else}
46
{/if}<br />
POIDS DES COLIS DE LA PAGE : {if $smarty.foreach.orders.iteration + 46 > $smarty.foreach.orders.total}
{(($smarty.foreach.orders.total - $smarty.foreach.orders.iteration)*0.24)|number_format:2:',':''}
{else}
{(46*0.24)|number_format:2:',':''}
{/if} KG<br />
TOTAL CRBT DE LA PAGE : 0,00 EUR<br />
</td>
</tr>
</tfoot>
<tbody>
{/if}
{/foreach}
</tbody>
</table>
<br /><br /><br />
<table>
<tr>
<td>
<br /><br />
NOMBRE TOTAL DE COLIS : {$count_orders}<br />
POIDS TOTAL DE COLIS : {$total_weight|number_format:2:',':''} KG<br />
TOTAL CRBT : 0,00 EUR<br />
<br />
Nombre de pages : {literal} <!--mpdf {nb} mpdf--> {/literal}
</td>
<td class="right">
<table class="border"><tr><td>
SIGNATURE DE L'AGENT (*)<br />
<br /><br /><br /><br />
DATE<br /><br />
</td></tr></table>
<br /><br /><br />
* Cette signature ne vaut pas validation des données indiquées par le client
</td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,566 @@
<?php
if(!defined('_PS_VERSION_')) {
exit;
}
class WS_ServiceCallContextVO {
public $dateDeposite; // dateTime
//~ public $dateValidation; // dateTime
public $returnType = 'CreatePDFFile'; // RequestTypeVO, CreatePDFFile / ReturnPDFInResponse
public $serviceType; // string
public $crbt = FALSE; // bool
public $removalBAL = FALSE; // bool
//~ public VATCode; // int
//~ public VATPercentage; // int
//~ public VATAmount; // int
//~ public transportationAmount; // int
//~ public totalAmount; // int, oblig pour Andorre
//public $portPaye = FALSE; // bool
//~ public FTD; // bool
//~ public FTDAmount; // int
//~ public returnOption; // bool
//~ public returnOptionAmount; // int
public function __construct() {
$this->serviceType = (Module::isInstalled('socolissimo')? 'SO': 'DOM');
$this->dateDeposite = date('Y-m-d\TH:i:s.000P');
}
}
class WS_ExpEnvVO {
public $alert = 'none'; // AlertTypeVO
public $addressVO; // AddressVO
}
class WS_AddressVO {
//~ public $companyName; // string
//~ public $Civility; // string
//~ public $Name; // string
//~ public $Surname; // string
//~ public $line0; // string
//~ public $line1; // string
public $line2 = ''; // string
//~ public $line3; // string
//~ public $phone; // string, not required for DOM or DOS only
//~ public $MobileNumber; // string
//~ public $DoorCode1; // string
//~ public $DoorCode2; // string
//~ public $Interphone; // string
//~ public $country; // string
public $countryCode; // string
public $city; // string
public $email; // string
public $postalCode; // string
}
class WS_DestEnvVO {
public $ref = '';
public $alert = 'none'; // AlertTypeVO
public $addressVO; // AddressVO
public $codeBarForreference = FALSE; // bool
public $deliveryError = FALSE; // bool
}
class WS_ServiceCallContextV2 extends WS_ServiceCallContextVO {
//~ public $commandNumber; // string
public $commercialName; // string
public function __construct() {
parent::__construct();
$this->commercialName = Configuration::get('LAPOSTEWS_COMMERCIALNAME', 'ONLINE SHOP');
}
}
class WS_Letter {
public $password; // string, not null
public $contractNumber; // int, not null
public $profil = 'SPECIFIQUE'; // string
public $service; // ServiceCallContextV2
public $parcel; // ParcelVO
public $dest; // DestEnvVO
public $exp; // ExpEnvVO
public function __construct() {
$this->contractNumber = (int) Configuration::get('LAPOSTEWS_API_CONTRACT');
$this->password = Configuration::get('LAPOSTEWS_API_PASSWORD');
}
}
class WS_GetLetterColissimoRequest {
public $letter; // Letter
public function __construct($letter=NULL) {
$this->letter = $letter;
}
}
class WS_Contents {
public $article = array(); // ArticleVO, 1..10
public $categorie = 3; // CategorieVO
}
class WS_ArticleVO {
public $description;
public $quantite;
public $poids;
public $valeur;
public $numTarifaire;
public $paysOrigine = 'FR';
}
class WS_ParcelVO {
public $insuranceRange = '00'; // string, not null
public $typeGamme; // string, not null
//~ public $parcelNumber; // string, not null
//~ public $returnTypeChoice; // int, not null
//~ public $insuranceValue; // int, not null
//~ public $recommendationLevel; // string, not null
//~ public $RecommendationAmount; // int
public $weight = 0.01; // float, not null, /!\ décimales si > 0 uniquement
public $horsGabarit = FALSE;
//~ public $HorsGabaritAmount; // int
public $DeliveryMode = 'DOM'; // DeliveryModeVO: DOM, RDV, BPR, ACP, CDI, A2P, MRL, CIT, DOS
//public $ReturnReceipt = FALSE; // bool
//public $Recommendation = FALSE; // bool
//~ public $Instructions; // string
//public $RegateCode = ''; // string, vide si domicile, sinon point de livraison
public $contents; // ContentsVO, not null, required if Andorre
}
class Parcel {
public $mode;
public $parcelVO;
public $getLetterColissimoRequest;
public $letter;
public $serviceCallContextV2;
public $order;
public function __construct() {
$this->mode = (int) Configuration::get('LAPOSTEWS_MODE'); // 0: test, 1: production
$this->serviceCallContextV2 = new WS_ServiceCallContextV2();
$this->parcelVO = new WS_ParcelVO();
$this->letter = new WS_Letter();
$this->letter->parcel = $this->parcelVO;
$this->letter->service = $this->serviceCallContextV2;
$this->letter->dest = new WS_DestEnvVO();
$this->letter->exp = new WS_ExpEnvVO();
$this->letter->contents = new WS_Contents();
}
public function addArticle($description, $qty, $weight, $value, $wco_nom) {
if(count($this->letter->contents->article) < 10) {
$article = new WS_ArticleVO();
if(mb_strlen($description) > 61) {
$article->description = mb_substr($customs_details[$k]['product_name'], 0, 61).'...';
} else {
$article->description = $description;
}
$article->quantite = (int) $qty;
$article->poids = str_replace('.00', '', (string) sprintf('%.02f', (float) $weight));
$article->valeur = str_replace('.00', '', (string) sprintf('%.02f', (float) $value));
$article->numTarifaire = $wco_nom;
$this->letter->contents->article[] = $article;
}
}
public function getShippingNumber($gamme) {
if($gamme == 'SO+A2P') {
$prefix = Configuration::get('LAPOSTEWS_RANGE_0_P');
Db::getInstance()->Execute('SET AUTOCOMMIT = 0');
Db::getInstance()->Execute('START TRANSACTION');
$res = Db::getInstance()->ExecuteS('
SELECT `value`
FROM `'._DB_PREFIX_.'logistics_shipping`
WHERE `carrier` = "laposte"
AND `delivery_mode` = "0"
FOR UPDATE
');
$max = (int) $res[0]['value'] + 1;
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'logistics_shipping`
SET `value` = "'.(int) $max.'"
WHERE `carrier` = "laposte"
AND `delivery_mode` = "0"
');
Db::getInstance()->Execute('COMMIT');
Db::getInstance()->Execute('SET AUTOCOMMIT = 1');
} elseif($gamme == 'SO+BPR') {
$prefix = Configuration::get('LAPOSTEWS_RANGE_1_P');
Db::getInstance()->Execute('SET AUTOCOMMIT = 0');
Db::getInstance()->Execute('START TRANSACTION');
$res = Db::getInstance()->ExecuteS('
SELECT `value`
FROM `'._DB_PREFIX_.'logistics_shipping`
WHERE `carrier` = "laposte"
AND `delivery_mode` = "1"
FOR UPDATE
');
$max = (int) $res[0]['value'] + 1;
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'logistics_shipping`
SET `value` = "'.(int) $max.'"
WHERE `carrier` = "laposte"
AND `delivery_mode` = "1"
');
Db::getInstance()->Execute('COMMIT');
Db::getInstance()->Execute('SET AUTOCOMMIT = 1');
} elseif($gamme == 'SO+DOS') {
$prefix = Configuration::get('LAPOSTEWS_RANGE_2_P');
Db::getInstance()->Execute('SET AUTOCOMMIT = 0');
Db::getInstance()->Execute('START TRANSACTION');
$res = Db::getInstance()->ExecuteS('
SELECT `value`
FROM `'._DB_PREFIX_.'logistics_shipping`
WHERE `carrier` = "laposte"
AND `delivery_mode` = "2"
FOR UPDATE
');
$max = (int) $res[0]['value'] + 1;
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'logistics_shipping`
SET `value` = "'.(int) $max.'"
WHERE `carrier` = "laposte"
AND `delivery_mode` = "2"
');
Db::getInstance()->Execute('COMMIT');
Db::getInstance()->Execute('SET AUTOCOMMIT = 1');
} elseif($gamme == 'SO+DOM') {
$prefix = Configuration::get('LAPOSTEWS_RANGE_3_P');
Db::getInstance()->Execute('SET AUTOCOMMIT = 0');
Db::getInstance()->Execute('START TRANSACTION');
$res = Db::getInstance()->ExecuteS('
SELECT `value`
FROM `'._DB_PREFIX_.'logistics_shipping`
WHERE `carrier` = "laposte"
AND `delivery_mode` = "3"
FOR UPDATE
');
$max = (int) $res[0]['value'] + 1;
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'logistics_shipping`
SET `value` = "'.(int) $max.'"
WHERE `carrier` = "laposte"
AND `delivery_mode` = "3"
');
Db::getInstance()->Execute('COMMIT');
Db::getInstance()->Execute('SET AUTOCOMMIT = 1');
} else {
$prefix = Configuration::get('LAPOSTEWS_RANGE_4_P');
Db::getInstance()->Execute('SET AUTOCOMMIT = 0');
Db::getInstance()->Execute('START TRANSACTION');
$res = Db::getInstance()->ExecuteS('
SELECT `value`
FROM `'._DB_PREFIX_.'logistics_shipping`
WHERE `carrier` = "laposte"
AND `delivery_mode` = "4"
FOR UPDATE
');
$max = (int) $res[0]['value'] + 1;
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'logistics_shipping`
SET `value` = "'.(int) $max.'"
WHERE `carrier` = "laposte"
AND `delivery_mode` = "4"
');
Db::getInstance()->Execute('COMMIT');
Db::getInstance()->Execute('SET AUTOCOMMIT = 1');
}
$max = sprintf('%08d', $max);
$key = ((int) substr($max, 0, 1) * 8 + (int) substr($max, 1, 1) * 6 + (int) substr($max, 2, 1) * 4 + (int) substr($max, 3, 1) * 2 + (int) substr($max, 4, 1) * 3 + (int) substr($max, 5, 1) * 5 + (int) substr($max, 6, 1) * 9 + (int) substr($max, 7, 1) * 7) % 11;
if($key == 0) {
$key = 5;
} elseif($key == 1) {
$key = 0;
} else {
$key = 11 - $key;
}
return $prefix.$max.$key.'FR';
}
public function attachOrder($id_order) {
global $cookie;
$this->order = new Order($id_order);
if(Validate::isLoadedObject($this->order)) {
$this->serviceCallContextV2->commandNumber = $this->order->id;
$dst_customer = new Customer($this->order->id_customer);
$dst_address = new Address($this->order->id_address_delivery);
$dst_country = new Country($dst_address->id_country);
$dst_address_ws = new WS_AddressVO();
if($dst_address->company != '') {
$dst_address_ws->companyName = mb_substr($dst_address->company, 0, 32);
}
$dst_address_ws->Name = (string) mb_substr(str_replace(array('', 'ª', 'ł', 'ň', 'ć', 'ņ', 'č',), array('\'', 'a', 'l', 'n', 'c', 'n', 'c',), $dst_address->firstname), 0, 32);
$dst_address_ws->Surname = (string) mb_substr(strtoupper(str_replace(array('ª', 'ł', 'ň', 'ć', 'ņ', 'č',), array('a', 'l', 'n', 'c', 'n', 'c',), $dst_address->lastname)), 0, 32);
$dst_address_ws->email = (string) $dst_customer->email;
if($dst_address->id_country == 193) {
$dst_address_ws->postalCode = str_replace('SI', '', (string) str_replace(array(' ', '-'), '', $dst_address->postcode));
} elseif($dst_address->id_country == 125) {
$dst_address_ws->postalCode = str_replace('LV', '', (string) str_replace(array(' ', '-'), '', $dst_address->postcode));
} else {
$dst_address_ws->postalCode = (string) str_replace(array(' ', '-'), '', $dst_address->postcode);
}
$dst_address_ws->city = (string) mb_substr(strtoupper($dst_address->city), 0, 32);
if(in_array($dst_country->iso_code, array('MO', 'GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
$dst_address_ws->countryCode = 'FR';
} else {
$dst_address_ws->countryCode = (string) $dst_country->iso_code;
}
$dst_address_ws->country = (string) mb_substr($dst_country->name[$cookie->id_lang], 0, 32);
if(Module::isInstalled('socolissimo')
&& ($so_data = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` = '.(int) $this->order->id_cart.'
AND `id_customer` = '.(int) $this->order->id_customer.'
'))
&& ($so_data['cecountry'] == 'FR' || $so_data['cecountry'] == 'AD' || $so_data['cecountry'] == 'MO')
) {
$this->parcelVO->typeGamme = 'SO';
$unicode_0 = json_decode('"\u0006"');
$unicode_1 = json_decode('"\u200b"');
$unicode_2 = json_decode('"\u00ad"');
$dst_address_ws->email = $so_data['ceemail'];
$dst_address_ws->Name = mb_substr(str_replace('ł', 'l', $so_data['cename']), 0, 32);
$dst_address_ws->Surname = mb_substr(str_replace('ł', 'l', $so_data['cefirstname']), 0, 32);
$address_lines = array();
for($i = 1; $i < 5; $i++) {
if(($line = (string) mb_substr($so_data['pradress'.$i], 0, 32)) != '') {
$address_lines[] = str_replace(
array('Á', '°', 'º', 'º', 'º', 'ª', "\t", "\n", "\r", ' ', '', '', $unicode_0, $unicode_1, $unicode_2,),
array('A', '', '', '', '', 'a', ' ', ' ', ' ', ' ', '-', '', '', '', '',),
trim($line)
);
}
}
if(count($address_lines) == 1) {
$dst_address_ws->line2 = str_replace(array('', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[0]);
} elseif(count($address_lines) == 2) {
$dst_address_ws->line2 = str_replace(array('', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[0]);
$dst_address_ws->line3 = str_replace(array('', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[1]);
} elseif(count($address_lines) == 3) {
$dst_address_ws->line0 = str_replace(array('', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[0]);
$dst_address_ws->line2 = str_replace(array('', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[1]);
$dst_address_ws->line3 = str_replace(array('', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[2]);
} else {
$dst_address_ws->line0 = str_replace(array('', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[0]);
$dst_address_ws->line1 = str_replace(array('', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[1]);
$dst_address_ws->line2 = str_replace(array('', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[2]);
$dst_address_ws->line3 = str_replace(array('', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[3]);
}
$dst_address_ws->postalCode = (string) mb_substr($so_data['przipcode'], 0, 32);
$dst_address_ws->city = (string) mb_substr($so_data['prtown'], 0, 32);
$dst_address_ws->MobileNumber = (string) mb_substr($so_data['cephonenumber'], 0, 32);
if(strlen($dst_address_ws->MobileNumber) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $dst_address_ws->MobileNumber)) {
$dst_address_ws->MobileNumber = '0'.mb_substr(mb_substr($dst_address_ws->MobileNumber, -10), 1);
}
}
if(mb_substr($dst_address_ws->MobileNumber, 0, 2) != '06' && mb_substr($dst_address_ws->MobileNumber, 0, 2) != '07') {
$dst_address_ws->MobileNumber = '0600000000';
}
if(($doorcode = (string) mb_substr($so_data['cedoorcode1'], 0, 32)) != '') {
$dst_address_ws->DoorCode1 = $doorcode;
}
if(($doorcode = (string) mb_substr($so_data['cedoorcode2'], 0, 32)) != '') {
$dst_address_ws->DoorCode2 = $doorcode;
}
$this->letter->parcel->Instructions = trim(str_replace(array('°', '|', ' ', '’', "\n", "\r"), ' ', (string) $so_data['cedeliveryinformation']));
$this->letter->parcel->DeliveryMode = (string) $so_data['delivery_mode'];
if(!in_array($this->letter->parcel->DeliveryMode, array('DOM', 'DOS', 'RDV'))) {
$this->letter->parcel->RegateCode = $so_data['prid']; //(string) ltrim($so_data['prid'], '0');
error_log($this->letter->parcel->RegateCode);
}
} else {
//$this->serviceCallContextV2->serviceType = 'DOM';
if($dst_country->iso_code == 'FR' /*|| $dst_country->iso_code == 'BE'*/) {
$this->parcelVO->typeGamme = 'SO';
} else {
$this->parcelVO->typeGamme = 'EI';
}
if($dst_country->iso_code != 'FR') {
$this->parcelVO->parcelNumber = $this->getShippingNumber($this->parcelVO->typeGamme.'+'.$this->parcelVO->DeliveryMode);
$this->parcelVO->returnTypeChoice = 3;
}
$dst_address_ws->line2 = str_replace(array('', '°', 'º', 'º', 'º', 'ª', 'ā', 'ė'), array('\'', ' ', '', '', '', 'a', 'a', 'e'), (string) $dst_address->address1);
$dst_address_ws->line3 = str_replace(array('', '°', 'º', 'º', 'º', 'ª', 'ā', 'ė'), array('\'', ' ', '', '', '', 'a', 'a', 'e'), (string) $dst_address->address2);
if(in_array($dst_country->iso_code, array('FR', 'AD', 'MO', 'GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
if($dst_address->phone != '' && preg_match('/^0[67][0-9]+$/', $dst_address->phone)) {
$dst_address_ws->phone = (string) $dst_address->phone;
} elseif($dst_address->phone_mobile != '' && preg_match('/^0[67][0-9]+$/', $dst_address->phone_mobile)) {
$dst_address_ws->phone = (string) $dst_address->phone_mobile;
}
if(strlen($dst_address_ws->phone) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $dst_address_ws->phone)) {
$dst_address_ws->phone = '0'.mb_substr(mb_substr($dst_address_ws->phone, -10), 1);
}
}
if(strlen($dst_address_ws->phone_mobile) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $dst_address_ws->phone_mobile)) {
$dst_address_ws->phone_mobile = '0'.mb_substr(mb_substr($dst_address_ws->phone_mobile, -10), 1);
}
}
} else {
/*$this->parcelVO->typeGamme = 'AI';
$this->letter->parcel->DeliveryMode = 'DOM';*/
if($dst_country->iso_code == 'BE') {
if($dst_address->phone != '') {
$dst_address_ws->phone = (string) $dst_address->phone;
} else {
$dst_address_ws->phone = (string) $dst_address->phone_mobile;
}
$dst_address_ws->MobileNumber = '';
} else {
if($dst_address->phone != '') {
$dst_address_ws->phone = (string) $dst_address->phone;
}
if($dst_address->phone_mobile != '') {
$dst_address_ws->MobileNumber = (string) $dst_address->phone_mobile;
}
}
}
}
$this->letter->dest->addressVO = $dst_address_ws;
$this->letter->dest->ref = $this->order->id;
$exp_country = new Country((int) Configuration::get('LAPOSTEWS_EXP_COUNTRY'));
$exp_address_ws = new WS_AddressVO();
$exp_address_ws->companyName = (string) mb_substr(Configuration::get('LAPOSTEWS_EXP_COMPANY', ''), 0, 32);
$exp_address_ws->Name = (string) mb_substr(Configuration::get('LAPOSTEWS_EXP_FIRSTNAME', ''), 0, 32);
$exp_address_ws->Surname = (string) mb_substr(strtoupper(Configuration::get('LAPOSTEWS_EXP_LASTNAME', '')), 0, 32);
$exp_address_ws->email = (string) Configuration::get('LAPOSTEWS_EXP_EMAIL', '');
$exp_address_ws->postalCode = (string) Configuration::get('LAPOSTEWS_EXP_POSTALCODE', '');
$exp_address_ws->city = (string) mb_substr(strtoupper(Configuration::get('LAPOSTEWS_EXP_CITY', '')), 0, 32);
$exp_address_ws->line2 = (string) mb_substr(strtoupper(Configuration::get('LAPOSTEWS_EXP_ADDR1', '')), 0, 32);
$exp_address_ws->line3 = (string) mb_substr(strtoupper(Configuration::get('LAPOSTEWS_EXP_ADDR2', '')), 0, 32);
if(in_array($exp_country->iso_code, array('MO', 'GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
$exp_address_ws->countryCode = 'FR';
} else {
$exp_address_ws->countryCode = (string) $exp_country->iso_code;
}
$exp_address_ws->country = (string) mb_substr($exp_country->name[$cookie->id_lang], 0, 32);
$exp_address_ws->phone = (string) Configuration::get('LAPOSTEWS_EXP_PHONE', '');
if(strlen($exp_address_ws->phone) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $exp_address_ws->phone)) {
$exp_address_ws->phone = '0'.mb_substr(mb_substr($exp_address_ws->phone, -10), 1);
}
}
$this->letter->exp->addressVO = $exp_address_ws;
}
}
public function setWeight($weight=0) {
$this->parcelVO->weight = rtrim((string) $weight, '0');
}
public function send() {
if(Validate::isLoadedObject($this->order)) {
global $cookie;
$c = new SoapClient(
'http://ws.colissimo.fr/soap.shippingclpV2/services/WSColiPosteLetterService?wsdl',
array(
'trace' => $this->mode,
'exceptions' => !$this->mode,
'cache_wsdl' => $this->mode? WSDL_CACHE_MEMORY: WSDL_CACHE_NONE,
)
);
$this->getLetterColissimoRequest = new WS_GetLetterColissimoRequest($this->letter);
try {
/*if($_SERVER['REMOTE_ADDR'] == '78.226.56.137') {
$x = $c->getLetterColissimo($this->getLetterColissimoRequest);
if($_SERVER['REMOTE_ADDR'] == '78.226.56.137') {
mail('perron@antadis.com', 'PSS TEST PANZOU', serialize($c->__getLastRequest())."\n".serialize($c->__getLastResponse())."\n".serialize($x)."\r\n\r\n".serialize($this->getLetterColissimoRequest));
}
return $x;
}*/
if($this->letter->dest->addressVO->countryCode == 'FR') {
// $x = $c->getLetterColissimo(array('in0' => $this->letter));
$x = $c->getLetterColissimo($this->getLetterColissimoRequest);
/*if($_SERVER['REMOTE_ADDR'] == '78.226.56.137') {
mail('perron@antadis.com', 'PSS TEST PANZOU', serialize($x)."\r\n\r\n".serialize($this->getLetterColissimoRequest));
}*/
} else {
//if($_SERVER['REMOTE_ADDR'] == '78.226.56.137') {
$this->getLetterColissimoRequest->letter->contractNumber = (int) Configuration::get('LAPOSTEWS_API_CONTRACT2');
$this->getLetterColissimoRequest->letter->password = Configuration::get('LAPOSTEWS_API_PASSWORD2');
$x = $c->genererEtiquetteBIC3($this->getLetterColissimoRequest);
//}
//var_dump($this->getLetterColissimoRequest);
//var_dump($x);
mail('perron@antadis.com', 'BBB TEST LOG', serialize($x)."\r\n\r\n".serialize($this->getLetterColissimoRequest));
}
return $x;
} catch(Exception $e) {
mail('perron@antadis.com', 'BBB TEST LOG', serialize($x)."\r\n\r\n".serialize($this->getLetterColissimoRequest)."\n".serialize($e));
return $e;
}
} else {
return FALSE;
}
}
}

View File

@ -0,0 +1,506 @@
<?php
if(!defined('_PS_VERSION_')) {
exit;
}
class SoapResponse {
const CONTENT_TYPE = 'Content-Type: application/xop+xml;';
const UUID = '/--uuid:/'; //This is the separator of each part of the response
const CONTENT = 'Content-';
public $attachments = array ();
public $soapResponse = array ();
public $uuid = NULL;
public function __construct($response)
{
if(strpos($response, self::CONTENT_TYPE ) !== FALSE) {
$this->parseResponse($response);
} else {
throw new Exception('This response is not '.self::CONTENT_TYPE);
}
}
private function parseResponse($response)
{
$content = array ();
$matches = array ();
preg_match_all(self::UUID, $response, $matches, PREG_OFFSET_CAPTURE);
for($i = 0; $i < count ($matches[0]) - 1; $i++) {
if ($i + 1 < count ( $matches [0] )) {
$content[$i] = substr($response, $matches[0][$i][1], $matches[0][$i + 1][1] - $matches[0][$i][1]);
} else {
$content[$i] = substr($response, $matches[0][$i][1], strlen($response));
}
}
foreach ( $content as $part ) {
if($this->uuid == NULL){
$uuidStart = 0;
$uuidEnd = 0;
$uuidStart = strpos($part, self::UUID, 0) + strlen(self::UUID);
$uuidEnd = strpos($part, "\r\n", $uuidStart);
$this->uuid = substr($part, $uuidStart, $uuidEnd-$uuidStart);
}
$header = $this->extractHeader($part);
if(count($header) > 0){
if(strpos($header['Content-Type'], 'type="text/xml"') !== FALSE) {
$this->soapResponse['header'] = $header;
$this->soapResponse['data'] = trim(substr($part, $header['offsetEnd']));
} else {
$attachment['header'] = $header;
$attachment['data'] = trim(substr($part, $header['offsetEnd']));
array_push($this->attachments, $attachment);
}
}
}
}
/**
* Exclude the header from the Web Service response
* @param string $part
* @return array $header
*/
private function extractHeader($part)
{
$header = array();
$headerLineStart = strpos($part, self::CONTENT, 0);
$endLine = 0;
while($headerLineStart !== FALSE){
$header['offsetStart'] = $headerLineStart;
$endLine = strpos($part, "\r\n", $headerLineStart);
$headerLine = explode(': ', substr($part, $headerLineStart, $endLine - $headerLineStart));
$header[$headerLine[0]] = $headerLine[1];
$headerLineStart = strpos($part, self::CONTENT, $endLine);
}
$header['offsetEnd'] = $endLine;
return $header;
}
}
class Parcel {
public function addArticle($description, $qty, $weight, $value, $wco_nom) {}
public function getShippingNumber() {}
public function attachOrder($id_order)
{
$this->order = new Order($id_order);
if(Validate::isLoadedObject($this->order)) {
$this->product_type = '';
$dst_customer = new Customer($this->order->id_customer);
$dst_address = new Address($this->order->id_address_delivery);
$dst_country = new Country($dst_address->id_country);
$langs = array(
1 => 'EN',
2 => 'FR',
3 => 'ES',
5 => 'IT',
6 => 'EN',
);
$this->dst_address = array(
'companyName' => '',
'lastName' => '',
'firstName' => '',
'line0' => '',
'line1' => '',
'line2' => '',
'line3' => '',
'countryCode' => '',
'city' => '',
'zipCode' => '',
'phoneNumber' => '',
'mobileNumber' => '',
'doorCode1' => '',
'doorCode2' => '',
'email' => '',
'intercom' => '',
'language' => $langs[(int) $this->order->id_lang],
);
$this->prid = '';
$this->instructions = '';
$unicode_ack = json_decode('"\u0006"');
$unicode_ack2 = json_decode('"\u00ad"');
if(Module::isInstalled('socolissimo')
&& ($so_data = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` = '.(int) $this->order->id_cart.'
AND `id_customer` = '.(int) $this->order->id_customer.'
'))
&& (
(strpos(Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'carrier`
WHERE `id_carrier` = '.(int) $this->order->id_carrier.'
'), 'La Poste') !== FALSE)
|| (strpos(Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'carrier`
WHERE `id_carrier` = '.(int) $this->order->id_carrier.'
'), 'Colissimo') !== FALSE)
)) {
$this->product_type = $so_data['delivery_mode'];
if($this->product_type == 'BOM') {
$this->product_type = 'DOM';
}
if($so_data['cecountry'] == 'ES' && $this->product_type == 'DOM') {
$this->product_type = 'DOS';
}
if(!in_array($so_data['cecountry'], array('ES', 'BE', 'AD', 'MC', 'FR', 'GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
$this->product_type = 'DOS';
}
if($so_data['cecountry'] == 'IT'){
$this->product_type = 'COLI';
}
$this->dst_address['email'] = $so_data['ceemail'];
if(empty($this->dst_address['email'])) {
$this->dst_address['email'] = $dst_customer->email;
}
if(!empty($so_data['cename'])) {
$this->dst_address['lastName'] = mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','İ'), array(' ', '', '', '', 'a', 'a','a','A','l','i'), $so_data['cename']), 0, 35);
} else {
$this->dst_address['lastName'] = mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','İ'), array(' ', '', '', '', 'a', 'a','a','A','l','i'), $so_data['prname']), 0, 35);
}
if(!empty($so_data['cefirstname'])) {
$this->dst_address['firstName'] = mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','','İ'), array(' ', '', '', '', 'a', 'a','a','A','l',' ','i'), $so_data['cefirstname']), 0, 29);
} else {
$this->dst_address['firstName'] = mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','','İ'), array(' ', '', '', '', 'a', 'a','a','A','l',' ','i'), $so_data['prfirstname']), 0, 29);
}
if(!empty($so_data['cecompanyname'])) {
$this->dst_address['companyName'] = mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','','İ'), array(' ', '', '', '', 'a', 'a','a','A','l',' ','i'), $so_data['cecompanyname']), 0, 35);
}
$address_lines = array();
for($i = 1; $i < 5; $i++) {
if(($line = (string) mb_substr($so_data['pradress'.$i], 0, 32)) != '') {
$address_lines[] = trim($line);
}
}
if(count($address_lines) == 1) {
$this->dst_address['line2'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[0]);
} elseif(count($address_lines) == 2) {
if(strtolower($so_data['cecountry']) == 'be') {
$this->dst_address['line0'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[0]);
$this->dst_address['line2'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[1]);
} else {
$this->dst_address['line2'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[0]);
$this->dst_address['line3'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[1]);
}
} elseif(count($address_lines) == 3) {
$this->dst_address['line0'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[0]);
$this->dst_address['line2'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[1]);
$this->dst_address['line3'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[2]);
} else {
$this->dst_address['line0'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[0]);
$this->dst_address['line1'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[1]);
$this->dst_address['line2'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[2]);
$this->dst_address['line3'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[3]);
}
$this->dst_address['countryCode'] = $so_data['cecountry'];
if(strtolower($so_data['cecountry']) == 'sl') {
$this->dst_address['zipCode'] = (string) str_ireplace(array('SI-', 'SL-'), '', mb_substr($so_data['przipcode'], 0, 5));
} elseif(strtolower($so_data['cecountry']) == 'pt') {
$this->dst_address['zipCode'] = (string) $so_data['przipcode'];
} else {
$this->dst_address['zipCode'] = (string) mb_substr($so_data['przipcode'], 0, 5);
}
$this->dst_address['city'] = (string) mb_substr($so_data['prtown'], 0, 35);
$this->dst_address['mobileNumber'] = (string) mb_substr(str_replace(array('.','°', '|', ' ', '’',"/"),'',$so_data['cephonenumber']), 0, 32);
if(strlen($this->dst_address['mobileNumber']) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $this->dst_address['mobileNumber'])) {
$this->dst_address['mobileNumber'] = '0'.mb_substr(mb_substr($this->dst_address['mobileNumber'], -10), 1);
}
if(strtolower($so_data['cecountry']) == 'be' && preg_match('/^(0032|32)[0-9]{9,10}$/', $this->dst_address['mobileNumber'])) {
$this->dst_address['mobileNumber'] = '+32'.mb_substr(mb_substr($this->dst_address['mobileNumber'], -10), 1);
}
} elseif(strtolower($so_data['cecountry']) == 'fr' && preg_match('/^[0-9]{9,10}$/', $this->dst_address['mobileNumber'])) {
if(strlen($this->dst_address['mobileNumber']) == 9) {
$this->dst_address['mobileNumber'] = '0'.$this->dst_address['mobileNumber'];
} elseif(strlen($this->dst_address['mobileNumber']) == 10) {
$this->dst_address['mobileNumber'] = '0'.mb_substr(mb_substr($this->dst_address['mobileNumber'], -10), 1);
}
} elseif(strtolower($so_data['cecountry']) == 'be' && preg_match('/^[0-9]{9,10}$/', $this->dst_address['mobileNumber'])) {
if(strlen($this->dst_address['mobileNumber']) == 9) {
$this->dst_address['mobileNumber'] = '+32'.$this->dst_address['mobileNumber'];
} elseif(strlen($this->dst_address['mobileNumber']) == 10) {
$this->dst_address['mobileNumber'] = '+32'.mb_substr(mb_substr($this->dst_address['mobileNumber'], -10), 1);
}
}
if(strtolower($so_data['cecountry']) == 'fr' && mb_substr($this->dst_address['mobileNumber'], 0, 2) != '06' && mb_substr($this->dst_address['mobileNumber'], 0, 2) != '07') {
$this->dst_address['mobileNumber'] = '0600000000';
}
if(($doorcode = (string) mb_substr($so_data['cedoorcode1'], 0, 8)) != '') {
$this->dst_address['doorCode1'] = (string) mb_substr($so_data['cedoorcode1'], 0, 8);
}
if(($doorcode = (string) mb_substr($so_data['cedoorcode2'], 8, 8)) != '') {
$this->dst_address['doorCode2'] = (string) mb_substr($so_data['cedoorcode1'], 8, 8);
}
$this->instructions = trim(str_replace(array('°', '|', ' ', '’', "\n", "\r"), ' ', (string) $so_data['cedeliveryinformation']));
$this->prid = $so_data['prid'];
} else {
$this->dst_address['companyName'] = (string) mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','','İ', $unicode_ack, $unicode_ack2), array(' ', '', '', '', 'a', 'a','a','A','l',' ','i',' ',' '), $dst_address->company), 0, 35);
$this->dst_address['lastName'] = (string) mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','','İ', $unicode_ack, $unicode_ack2), array(' ', '', '', '', 'a', 'a','a','A','l',' ','i',' ',' '), $dst_address->firstname), 0, 35);
$this->dst_address['firstName'] = (string) mb_substr(strtoupper(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','','İ', $unicode_ack, $unicode_ack2), array(' ', '', '', '', 'a', 'a','a','A','l',' ','i',' ',' '), $dst_address->lastname)), 0, 29);
$this->dst_address['email'] = (string) $dst_customer->email;
if($dst_address->id_country == 193) {
$this->dst_address['zipCode'] = mb_substr((string) str_ireplace(array('SI-', 'SL-'), '', $dst_address->postcode), 0, 5);
} else {
$this->dst_address['zipCode'] = mb_substr((string) str_replace(array(' ', '-'), '', $dst_address->postcode), 0, 5);
}
$this->dst_address['city'] = (string) mb_substr(strtoupper($dst_address->city), 0, 35);
if(in_array($dst_country->iso_code, array('GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
$this->dst_address['countryCode'] = 'FR';
} else {
$this->dst_address['countryCode'] = (string) $dst_country->iso_code;
}
$this->dst_address['line2'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), (string) $dst_address->address1);
$this->dst_address['line3'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), (string) $dst_address->address2);
$this->instructions = trim(str_replace(array('°', '|', ' ', '’', "\n", "\r"), ' ', (string) $dst_address->other));
if(in_array($dst_country->iso_code, array('FR', 'AD', 'MC', 'GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
$dst_address->phone = ($dst_address->phone != ''? (string) str_replace(array('.','°', '|', ' ', '’',"/"),'',$dst_address->phone) : '');
$dst_address->phone_mobile = ($dst_address->phone_mobile != ''? (string) str_replace(array('.','°', '|', ' ', '’',"/"),'',$dst_address->phone_mobile) : '');
if($dst_address->phone != '' && preg_match('/^0[67][0-9]+$/', $dst_address->phone)) {
$this->dst_address['phoneNumber'] = (string) $dst_address->phone;
} elseif($dst_address->phone_mobile != '' && preg_match('/^0[67][0-9]+$/', $dst_address->phone_mobile)) {
$this->dst_address['phoneNumber'] = (string) $dst_address->phone_mobile;
}
if(strlen($this->dst_address['phoneNumber']) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $this->dst_address['phoneNumber'])) {
$this->dst_address['phoneNumber'] = '0'.mb_substr(mb_substr($this->dst_address['phoneNumber'], -10), 1);
}
}
if(strlen($this->dst_address['mobileNumber']) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $this->dst_address['mobileNumber'])) {
$this->dst_address['mobileNumber'] = '0'.mb_substr(mb_substr($this->dst_address['mobileNumber'], -10), 1);
}
}
} else {
if($dst_country->iso_code == 'BE') {
if($dst_address->phone != '') {
$this->dst_address['phoneNumber'] = (string) $dst_address->phone;
} else {
$this->dst_address['phoneNumber'] = (string) $dst_address->phone_mobile;
}
$this->dst_address['mobileNumber'] = '';
} else {
if($dst_address->phone != '') {
$this->dst_address['phoneNumber'] = (string) $dst_address->phone;
}
if($dst_address->phone_mobile != '') {
$this->dst_address['mobileNumber'] = (string) $dst_address->phone_mobile;
}
}
}
if($dst_country->iso_code == 'FR' || $dst_country->iso_code == 'MC' || $dst_country->iso_code == 'BE') {
//$this->product_type = 'COLD'; // Amené a disparaitre
$this->product_type = 'DOM';
} else {
$this->product_type = 'COLI';
}
}
}
}
private function array_to_xml($array, $xml)
{
foreach($array as $key => $value) {
if(is_array($value)) {
if(!is_numeric($key)){
$subnode = $xml->addChild("$key");
$this->array_to_xml($value, $subnode);
}
else{
$subnode = $xml->addChild("item$key");
$this->array_to_xml($value, $subnode);
}
}
else {
$xml->addChild("$key",htmlspecialchars("$value"));
}
}
}
private function xml_to_array($xml, $array=array())
{
foreach((array) $xml as $index => $node) {
$array[$index] = (is_object($node))? $this->xml_to_array($node): $node;
}
return $array;
}
public function setWeight($weight=0)
{
$this->weight = rtrim((string) $weight, '0');
}
public function send()
{
if(Validate::isLoadedObject($this->order)) {
global $cookie;
$carrier_config = array(
'api' => array(
'wsu' => array(
'contract' => (int) Configuration::get('LAPOSTEWS_API_CONTRACT_WSU'),
'password' => Configuration::get('LAPOSTEWS_API_PASSWORD_WSU'),
)
),
'exp_commercial_name' => Configuration::get('LAPOSTEWS_COMMERCIALNAME'),
'exp_firstname' => Configuration::get('LAPOSTEWS_EXP_FIRSTNAME'),
'exp_lastname' => Configuration::get('LAPOSTEWS_EXP_LASTNAME'),
'exp_company' => Configuration::get('LAPOSTEWS_EXP_COMPANY'),
'exp_address1' => Configuration::get('LAPOSTEWS_EXP_ADDR1'),
'exp_address2' => Configuration::get('LAPOSTEWS_EXP_ADDR2'),
'exp_city' => Configuration::get('LAPOSTEWS_EXP_CITY'),
'exp_postcode' => Configuration::get('LAPOSTEWS_EXP_POSTALCODE'),
'exp_email' => Configuration::get('LAPOSTEWS_EXP_EMAIL'),
'exp_country' => Configuration::get('LAPOSTEWS_EXP_COUNTRY'),
'exp_phone' => Configuration::get('LAPOSTEWS_EXP_PHONE'),
);
$c = new SoapClient(
'https://ws.colissimo.fr/sls-ws/SlsServiceWS?wsdl',
array(
'trace' => 0,
'exceptions' => 1,
'cache_wsdl' => 0? WSDL_CACHE_MEMORY: WSDL_CACHE_NONE,
)
);
try {
$exp_country = new Country((int) $carrier_config['exp_country']);
if(in_array($exp_country->iso_code, array('GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
$countryCode = 'FR';
} else {
$countryCode = (string) $exp_country->iso_code;
}
$phone = $carrier_config['exp_phone'];
if(strlen($phone) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $phone)) {
$phone = '0'.mb_substr(mb_substr($phone, -10), 1);
}
}
$soap = new SimpleXMLElement('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" />');
$soap->addChild('soapenv:Header');
$children = $soap->addChild('soapenv:Body');
$children = $children->addChild('sls:generateLabel', NULL, 'http://sls.ws.coliposte.fr');
$children = $children->addChild('generateLabelRequest', NULL, '');
$this->array_to_xml(array(
'contractNumber' => $carrier_config['api']['wsu']['contract'],
'password' => $carrier_config['api']['wsu']['password'],
'outputFormat' => array(
'x' => 0,
'y' => 0,
'outputPrintingType' => 'DPL_10x15_203dpi', // DPL_10x15_300dpi / PDF_10x15_300dpi / PDF_A4_300dpi
),
'letter' => array(
'service' => array(
/*
COLD = Colissimo Access FR
COL = Colissimo Expert FR
COM = Colissimo Access FR
CDS = Colissimo Expert OM
COLI = Colissimo Expert Inter
DOM = SoCol Dom SS
DOS = SoCol Dom AS
BPR = Socol Bureau de poste FR
A2P = Socol Commerçant FR
CMT = Socol commercant FR
BDP = Socol Bureau de poste inter
*/
'productCode' => $this->product_type,
'depositDate' => date('Y-m-d'),
'transportationAmount' => (int) ($this->order->total_shipping * 100),
'orderNumber' => (string) $this->order->id,
'commercialName' => $carrier_config['exp_commercial_name'],
'returnTypeChoice' => 3, // 2 = return, 3 = do not return
),
'parcel' => array(
'weight' => 0.24,
'instructions' => $this->instructions,
'pickupLocationId' => $this->prid,
),
'customsDeclarations' => array(
),
'sender' => array(
'senderParcelRef' => 'REF'.$this->order->id,
'address' => array(
'companyName' => (string) mb_substr($carrier_config['exp_company'], 0, 35),
'line2' => (string) mb_substr(strtoupper($carrier_config['exp_address1']), 0, 35),
'line3' => (string) mb_substr(strtoupper($carrier_config['exp_address2']), 0, 35),
'countryCode' => $countryCode,
'city' => (string) mb_substr(strtoupper($carrier_config['exp_city']), 0, 35),
'zipCode' => (string) mb_substr($carrier_config['exp_postcode'], 0, 5),
'phoneNumber' => $phone,
'email' => mb_substr((string) $carrier_config['exp_email'], 0, 80),
'language' => 'FR',
),
),
'addressee' => array(
'address' => $this->dst_address,
),
),
), $children);
$authorized_ip = array(
'88.163.22.99',
'90.63.178.63',
);
if (in_array($_SERVER['REMOTE_ADDR'], $authorized_ip)) {
mail('marion@antadis.com', 'BBB LOG WSU xml', serialize($soap->asXML()));
}
$response = new SoapResponse($c->__doRequest($soap->asXML(), 'https://ws.colissimo.fr/sls-ws/SlsServiceWS', 'generateLabel', '2.0', 0));
if (in_array($_SERVER['REMOTE_ADDR'], $authorized_ip)) {
mail('marion@antadis.com', 'BBB LOG WSU reponse', serialize($response));
}
return array(
'data' => new SimpleXMLElement(
'<?xml version=\'1.0\' standalone=\'yes\'?>'.str_replace(
array(
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:generateLabelResponse xmlns:ns2="http://sls.ws.coliposte.fr">',
'</ns2:generateLabelResponse></soap:Body></soap:Envelope>',
),
'',
$response->soapResponse['data']
)
),
'label' => $response->attachments[0]['data'],
);
} catch(Exception $e) {
$authorized_ip = array(
'88.163.22.99',
'90.63.178.63',
);
if (in_array($_SERVER['REMOTE_ADDR'], $authorized_ip)) {
mail('marion@antadis.com', 'BBB LOG WSU Exception', serialize($e));
}
return $e;
}
}
}
}

View File

@ -0,0 +1,41 @@
<?php
include dirname(__FILE__).'/../../../../config/config.inc.php';
if(($date = Tools::getValue('date'))
&& (Tools::getValue('token') === Tools::getAdminToken('AdminMondialRelaySummary'.(int) Tab::getIdFromClassName('AdminMondialRelaySummary').(int) Tools::getValue('id_employee')))) {
$carts = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT o.`id_cart`
FROM `'._DB_PREFIX_.'mondialrelay_parcel` w, `'._DB_PREFIX_.'order_detail` d, `'._DB_PREFIX_.'orders` o
WHERE w.`id_order_detail` = d.`id_order_detail`
AND d.`id_order` = o.`id_order`
AND w.`date_add` > "'.pSQL(date('Y-m-d 00:00:00', strtotime($date))).'"
AND w.`date_add` <= "'.pSQL(date('Y-m-d 23:59:59', strtotime($date))).'"
') as $cart) {
$carts[] = (int) $cart['id_cart'];
}
$modes = array();
$dom = Db::getInstance()->getRow('
SELECT COUNT(o.*) AS `total`
FROM `'._DB_PREFIX_.'orders` o
WHERE o.`id_cart` IN ('.implode(', ', $carts).'
AND o.`id_cart` NOT IN (
SELECT i.`id_cart`
FROM `'._DB_PREFIX_.'mr_selected` i
)
');
if($dom['total'] > 0) {
$modes[] = 'dom';
}
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT `dlv_mode`
FROM `'._DB_PREFIX_.'mr_method`
') as $dm) {
$modes[] = strtolower($dm['dlv_mode']);
}
echo json_encode(array_unique($modes));
}

View File

@ -0,0 +1,45 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/../../../../config/config.inc.php';
## GET agences.txt FILE
$fname = 'agences.txt';
$filename = dirname(__FILE__) . '/' . $fname;
$file = fopen($filename, 'w+');
$remote_file = $fname;
$ftp = ftp_connect(Configuration::get('MONDIALRELAYWS_FTP_HOST'));
ftp_login($ftp, Configuration::get('MONDIALRELAYWS_FTP_LOGIN'), Configuration::get('MONDIALRELAYWS_FTP_PASSWORD'));
ftp_chdir($ftp, 'depuismrelay');
if (!ftp_fget($ftp, $file, $remote_file, FTP_BINARY))
die('An error occures while downloading remote file : ' . $fname);
$file = fopen($filename, 'r');
$content = fgets($file);
if (!$content)
die('File is empty : ' . $fname);
## Update DB
Db::getInstance()->ExecuteS('
TRUNCATE TABLE `'._DB_PREFIX_.'mondialrelay_agencies`
');
while($line = fgets($file)) {
if(substr($line, 1, 1) == '1') {
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'mondialrelay_agencies`
VALUES (
"'.pSQl(substr($line, 6, 4)).'",
"'.pSQl(substr($line, 10)).'"
)
');
}
}

View File

@ -0,0 +1,87 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/../../../../config/config.inc.php';
## GET relais.txt FILE
$fname = 'relais.txt';
$filename = dirname(__FILE__) . '/' . $fname;
$file = fopen($filename, 'w+');
$remote_file = $fname;
$ftp = ftp_connect(Configuration::get('MONDIALRELAYWS_FTP_HOST'));
ftp_login($ftp, Configuration::get('MONDIALRELAYWS_FTP_LOGIN'), Configuration::get('MONDIALRELAYWS_FTP_PASSWORD'));
ftp_chdir($ftp, 'depuismrelay');
if (!ftp_fget($ftp, $file, $remote_file, FTP_BINARY))
die('An error occures while downloading remote file : ' . $fname);
$file = fopen($filename, 'r');
$content = fgets($file);
if (!$content)
die('File is empty : ' . $fname);
## Update DB
Db::getInstance()->ExecuteS('
TRUNCATE TABLE `'._DB_PREFIX_.'mondialrelay_relais`
');
while($line = fgets($file)) {
if(substr($line, 1, 1) == '1') {
$datouv = explode('.', substr($line, 62, 10));
if(count($datouv) > 1) {
$datouv = $datouv[2].'-'.$datouv[1].'-'.$datouv[0];
} else {
$datouv = '0000-00-00';
}
$datfer = explode('.', substr($line, 72, 10));
if(count($datfer) > 1) {
$datfer = $datfer[2].'-'.$datfer[1].'-'.$datfer[0];
} else {
$datfer = '0000-00-00';
}
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'mondialrelay_relais`
VALUES (
"'.pSQl(substr($line, 4, 5)).'",
"'.pSQl(substr($line, 9, 1)).'",
"'.pSQl(substr($line, 10, 31)).'",
"'.pSQl(substr($line, 41, 5)).'",
"'.pSQl(substr($line, 46, 5)).'",
"'.pSQl(substr($line, 51, 5)).'",
"'.pSQl(substr($line, 56, 5)).'",
"'.pSQl(substr($line, 61, 1)).'",
"'.pSQl($datouv).'",
"'.pSQl($datfer).'",
"'.pSQl(substr($line, 202, 30)).'",
"'.pSQl(substr($line, 232, 31)).'",
"'.pSQl(substr($line, 325, 4)).'",
"'.pSQl(substr($line, 336, 31)).'",
"'.pSQl(substr($line, 367, 31)).'",
"'.pSQl(substr($line, 398, 31)).'",
"'.pSQl(substr($line, 429, 31)).'",
"'.pSQl(substr($line, 460, 5)).'",
"'.pSQl(substr($line, 465, 26)).'",
"'.pSQl(substr($line, 491, 5)).'",
"'.pSQl(substr($line, 613, 1)).'",
"'.pSQl(substr($line, 614, 1)).'",
"'.pSQl(substr($line, 615, 1)).'",
"'.pSQl(substr($line, 616, 1)).'",
"'.pSQl(substr($line, 617, 1)).'",
"'.pSQl(substr($line, 618, 1)).'",
"'.pSQl(substr($line, 619, 1)).'",
"'.pSQl(substr($line, 620, 2)).'",
"'.pSQl(substr($line, 622, 5)).'",
"'.pSQl(substr($line, 627, 20)).'",
"'.pSQl(substr($line, 652, 1)).'",
"'.pSQl(substr($line, 653, 6)).'",
"'.pSQl(substr($line, 659, 3)).'",
"'.pSQl(substr($line, 662, 6)).'"
)
');
}
}

View File

@ -0,0 +1,472 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/../../../../config/config.inc.php';
$call_prefix = array();
foreach(Db::getInstance()->executeS('
SELECT `id_country`, `call_prefix`
FROM `' . _DB_PREFIX_ . 'country`
') as $row){
$call_prefix[(int) $row['id_country']] = $row['call_prefix'];
}
// $str = 'aaAAäãØÃ#$()+@';
function str_format($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')
// );
return preg_replace(
'~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);~i',
'$1',
preg_replace('~&sup([\w]+);~',
'$1',
htmlentities($str, ENT_NOQUOTES, 'UTF-8')
)
);
}
function clean_str($str){
$str = str_replace(PHP_EOL, '', $str);
return preg_replace( "/\r|\n/","", $str);
}
function phone_format($phone, $id_country = 8){
global $call_prefix;
$prefix = '+' . (isset($call_prefix[$id_country]) ? $call_prefix[$id_country] : '33');
// normalize phone
$phone = str_replace(array(' ', '+'), '', $phone);
if (strlen($phone) > '10'){
if ($phone[0] != 0 && $phone[1] == 0)
$phone = substr($phone, 1);
$phone = substr($phone, 0, 10);
}
if (strlen($phone) == 9){
$phone = '0' . $phone;
}
// add spaces
// $_phone = '';
// for($i=0; $i<strlen($phone); $i++){
// $_phone .= $phone[$i];
// if (($i+1)%2==0)
// $_phone .= ' ';
// }
// $phone = $_phone;
// set format
$phone = $prefix . substr($phone, 1);
return $phone;
}
function mb_str_pad($input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT)
{
$diff = strlen( $input ) - mb_strlen( $input );
return str_pad( $input, $pad_length + $diff, $pad_string, $pad_type );
}
/**
* array(
* 0 => position,
* 1 => size,
* 2 => type,
* 3 => code,
* 4 => value
*/
function addRows($data_rows = array()){
if (!is_array($data_rows) || !count($data_rows))
return '';
$data_result = '';
foreach ($data_rows as $row) {
switch ($row[2]) {
case 'N':
if (isset($row[4]) && is_numeric($row[4]))
$val = sprintf('%0'.(int) $row[1].'d', $row[4]);
else
$val = mb_str_pad(mb_substr(str_format($row[4]), 0, (int) $row[1]), (int) $row[1]);
break;
case 'A':
case 'DT':
default:
$val = mb_str_pad(mb_substr(str_format($row[4]), 0, (int) $row[1]), (int) $row[1]);
break;
}
$data_result .= $val;
}
$data_result .= "\n";
return $data_result;
}
$last_sync = date('Y-m-d H:i:s', strtotime((Configuration::get('MONDIALRELAY_LASTSYNC') ? Configuration::get('MONDIALRELAY_LASTSYNC') : '0000-00-00 00:00:00')));
Configuration::updateValue('MONDIALRELAY_LASTSYNC', date('Y-m-d H:i:s'));
$sql = '
SELECT p.*, o.`id_lang`, o.`id_order`, o.`id_customer`, o.`id_address_delivery`, c.`email`
FROM `'._DB_PREFIX_.'mondialrelay_parcel` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
ON p.`id_order_detail` = d.`id_order_detail`
LEFT JOIN `'._DB_PREFIX_.'mondialrelay_dpc_sent` dpc
ON (p.`id_order_detail` = dpc.`id_order_detail` AND dpc.`shipping_number`=p.`shipping_number`)
LEFT JOIN `'._DB_PREFIX_.'orders` o
ON d.`id_order` = o.`id_order`
LEFT JOIN `'._DB_PREFIX_.'customer` c
ON c.`id_customer` = o.`id_customer`
WHERE p.`date_add` >= "'.pSQL($last_sync).'"
AND d.`id_order_detail` IS NOT NULL
AND o.`id_order` IS NOT NULL
AND dpc.`id_order_detail` IS NULL
GROUP BY p.`shipping_number`
';
$lines = Db::getInstance()->ExecuteS($sql);
if(count($lines)) {
$mr_account_details = unserialize(Configuration::get('MR_ACCOUNT_DETAIL'));
$crt_amount = 0.00; // contre remboursement en EUR
$exp_company = Configuration::get('MONDIALRELAY_EXP_COMPANY');
$exp_addr1 = Configuration::get('MONDIALRELAY_EXP_ADDR1');
$exp_addr2 = Configuration::get('MONDIALRELAY_EXP_ADDR2');
$exp_postcode = Configuration::get('MONDIALRELAY_EXP_POSTALCODE');
$exp_city = Configuration::get('MONDIALRELAY_EXP_CITY');
$exp_country = Db::getInstance()->getValue('
SELECT `iso_code`
FROM `'._DB_PREFIX_.'country`
WHERE `id_country` = '.(int) Configuration::get('MONDIALRELAY_EXP_COUNTRY').'
');
$exp_phone = Configuration::get('MONDIALRELAY_EXP_PHONE');
$exp_email = Configuration::get('MONDIALRELAY_EXP_EMAIL');
$collection_agency = Db::getInstance()->getValue('
SELECT `modexp`
FROM `'._DB_PREFIX_.'mondialrelay_tri`
WHERE `cppay` = "'.pSQL(Db::getInstance()->getValue('
SELECT `iso_code`
FROM `'._DB_PREFIX_.'country`
WHERE `id_country` = '.(int) $exp_country.'
')).'"
AND `destex` = "'.pSQL($exp_postcode).'"
');
$result = '';
$cpt = 0;
foreach($lines as $line) {
if (!in_array($line['mode'], array('24R', '24L', '24X', 'DRI','LD1','LDR','LDS','HOM')))
continue;
$cpt++;
// $mr_liv_mode = array(
// 'DISCOL' => (in_array($line['mode'], array('DOM', 'HOM', 'LD1', 'LDS', 'LCC'))? 'D': 'R'),
// 'SERCOL' => (in_array($line['mode'], array('DOM', 'HOM', 'LD1'))? '1': (in_array($line['mode'], array('LDS', 'LCC'))? '2': '3')),
// 'COLMOD' => (in_array($line['mode'], array('DOM', 'HOM', 'LD1'))? 'CDR': ($line['mode'] == 'LDS'? 'CDS': ($line['mode'] == 'LCC'? 'CCC': 'REL')))
// );
$mr_liv_mode = array(
'DISCOL' => 'R',
'SERCOL' => '2',
'COLMOD' => 'CCC'
);
switch ($line['mode']) {
case 'DOM':
case 'HOM':
case 'LD1':
case 'LDR':
$mr_liv_mode['DISCOL'] = '';
$mr_liv_mode['SERCOL'] = '2';
$mr_liv_mode['COLMOD'] = 'CCC';
// $mr_liv_mode['DISCOL'] = 'D';
// $mr_liv_mode['SERCOL'] = '1';
// $mr_liv_mode['COLMOD'] = 'CDR';
break;
case 'LDS':
$mr_liv_mode['DISCOL'] = '';
$mr_liv_mode['SERCOL'] = '2';
$mr_liv_mode['COLMOD'] = 'CCC';
// $mr_liv_mode['DISCOL'] = 'D';
// $mr_liv_mode['SERCOL'] = '2';
// $mr_liv_mode['COLMOD'] = 'CDS';
break;
case 'LCC':
$mr_liv_mode['DISCOL'] = 'D';
$mr_liv_mode['SERCOL'] = '2';
$mr_liv_mode['COLMOD'] = 'CCC';
case '24R':
case '24L':
case '24X':
case 'DRI':
$mr_liv_mode['DISCOL'] = '';
$mr_liv_mode['SERCOL'] = '2';
$mr_liv_mode['COLMOD'] = 'CCC';
default:
$mr_liv_mode['DISCOL'] = 'R';
$mr_liv_mode['SERCOL'] = '2';
$mr_liv_mode['COLMOD'] = 'CCC';
break;
}
$address = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int) $line['id_address_delivery'].'
');
// $code_marque = mb_substr($line['expedition_number'], 0, 2);
// $expe_number = mb_substr($line['expedition_number'], 2, 8);
$data_rows = array(
array(1, 1, 'A', 'CODFIC', 'A'),
array(2, 1, 'A', 'CODENR', '1'),
array(3, 1, 'A', 'SSCODE', '0'),
array(4, 2, 'A', 'MARQUE', 'F1'),
array(6, 8, 'A', 'NEXPE', $line['expedition_number']),
array(14, 2, 'N', 'NBCOLIS', '01'),
array(16, 1, 'A', 'DISTRI', 'D'),
array(17, 8, 'A', 'CDEST', !empty($line['idrelay'])? $line['idrelay']: $address['postcode']),
array(25, 4, 'N', 'TRANS', $line['modexp']),
array(29, 5, 'N', 'TOURNE', $line['direction']),
array(34, 1, 'N', 'TYPSER', ($line['mode'] == 'DOM' || $line['mode'] == 'HOM'? '0': ($line['mode'] == 'LD1'? '1': ($line['mode'] == 'LDS' || $line['mode'] == 'LCC'? '2': '3')))),
array(35, 3, 'A', 'LIVMOD', $line['mode']),
array(38, 10, 'DT', 'DATREM', date('d.m.Y')),
array(48, 4, 'A', 'SIGLE', ''),
array(52, 28, 'A', 'LVADR1', $address['lastname'].' '.$address['firstname']),
array(80, 30, 'A', 'LVADR2', $address['company']),
array(110, 2, 'A', 'Libre', ''),
array(112, 30, 'A', 'LVADR3', $address['address1']),
array(142, 2, 'A', 'Libre', ''),
array(144, 30, 'A', 'LVADR4', $address['address2']),
array(174, 2, 'A', 'Libre', ''),
array(176, 30, 'A', 'LVADR5', ''),
array(206, 2, 'A', 'Libre', ''),
array(208, 26, 'A', 'LVADR6', $address['city']),
array(234, 2, 'A', 'LVCPAY', $line['cppay']),
array(236, 5, 'A', 'LVCPOS', $address['postcode']),
array(241, 5, 'A', 'LVXPOS', ''),
array(246, 20, 'A', 'LVTEL1', str_replace(' ','',phone_format($address['phone']))),
array(266, 20, 'A', 'LVTEL2', str_replace(' ','',phone_format($address['phone_mobile']))),
array(286, 70, 'A', 'LVEMAI', $line['email']),
array(356, 31, 'A', 'INSLIV1', substr(clean_str($address['other']), 0, 30)),
array(387, 31, 'A', 'INSLIV2', substr(clean_str($address['other']), 0, 30)),
array(418, 10, 'A', 'libre', ''),
array(428, 7, 'N', 'POIDS', (float) $line['weight'] * $mr_account_details['MR_WEIGHT_COEFFICIENT']),
array(435, 7, 'N', 'VOLU', ''),
array(442, 3, 'N', 'LONG', ''),
array(445, 6, 'A', 'ORIG', 'BEBEBO'),
array(451, 7, 'N', 'VENTE', ''),
array(458, 3, 'A', 'DEVVTE', 'EUR'),
array(461, 7, 'N', 'CRT', (int) $crt_amount * 100),
array(468, 3, 'A', 'DEVCRT', 'EUR'),
array(471, 15, 'A', 'REFEXT', 'EXP'.$line['id_order']),
array(486, 9, 'A', 'REFCLI', $line['id_customer']),
array(495, 10, 'DT', 'DATFAC', date('d.m.Y')),
array(505, 10, 'DT', 'DATCDE', date('d.m.Y')),
array(515, 5, 'A', 'CALPHA', $address['lastname']),
array(520, 5, 'A', 'PRTMIS', '3BTK'),
array(525, 1, 'A', 'COLLEC', ''),
array(526, 1, 'A', 'TOPMDM', 'N'),
array(527, 2, 'A', 'TOPEMB', ''),
array(529, 2, 'N', 'QTLGAR', ''),
array(531, 10, 'DT', 'DATRDV', ''),
array(541, 2, 'A', 'CODCRNRDV', ''),
array(543, 2, 'A', 'DEBCRNLIVANN', ''),
array(545, 2, 'A', 'FINCRNLIVANN', ''),
array(547, 10, 'A', 'Libre', ''),
array(557, 1, 'A', 'TOPAVI', ''),
array(558, 7, 'N', 'TAXAFF', ''),
array(565, 7, 'N', 'TAXCRT', ''),
array(572, 2, 'A', 'Libre', ''),
array(574, 3, 'A', 'TOPKDO', ''),
array(577, 3, 'N', 'TOTDIM', ''),
array(580, 33, 'A', 'Libre', ''),
array(613, 7, 'A', 'TOP-POSIT', ''),
array(620, 1, 'A', 'DISCOL', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $mr_liv_mode['DISCOL'])),
array(621, 8, 'A', 'CCOLL', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : (!empty($line['idrelay'])? $line['idrelay']: $address['postcode']))),
array(629, 4, 'A', 'AGPEC', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $collection_agency)),
array(633, 5, 'A', 'TRNCOL', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $line['direction'])),
array(638, 1, 'A', 'SERCOL', ($mr_liv_mode['SERCOL'] ? $mr_liv_mode['SERCOL'] : 2)),
array(639, 3, 'A', 'COLMOD', ($mr_liv_mode['COLMOD'] ? $mr_liv_mode['COLMOD'] : 'CCC')),
array(642, 4, 'A', 'SIGLE', ''),
array(646, 28, 'A', 'EXADR1', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $exp_company)),
array(674, 30, 'A', 'EXADR2', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : mb_substr($exp_company, 28, 30))),
array(704, 2, 'A', 'Libre', ''),
array(706, 30, 'A', 'EXADR3', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $exp_addr1)),
array(736, 2, 'A', 'Libre', ''),
array(738, 30, 'A', 'EXADR4', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $exp_addr2)),
array(768, 2, 'A', 'Libre', ''),
array(770, 30, 'A', 'EXADR5', ''),
array(800, 2, 'A', 'Libre', ''),
array(802, 26, 'A', 'EXADR6', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $exp_city)),
array(828, 2, 'A', 'EXCPAY', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $exp_country)),
array(830, 5, 'A', 'EXCPOS', ($mr_liv_mode['COLMOD'] === 'CCC' ? '' : $exp_postcode)),
array(835, 5, 'A', 'EXXCPO', ''),
array(840, 20, 'A', 'EXNTEL', str_replace(' ','',phone_format($exp_phone, (int) $exp_country))),
array(860, 70, 'A', 'EXEMAI', $exp_email),
array(930, 2, 'A', 'LNGCOL', 'FR'),
array(932, 9, 'N', 'RECOL', '999999999'),
array(941, 1, 'A', 'TASSU', ''),
array(942, 2, 'A', 'LNGLIV', ($line['id_lang'] == 3? 'ES': ($line['id_lang'] == 2? 'FR': 'EN'))),
array(944, 58, 'A', 'Linre', '')
);
$result .= addRows($data_rows);
$i = 0;
foreach(Db::getInstance()->ExecuteS('
SELECT d.*, p.`quantity`
FROM `'._DB_PREFIX_.'mondialrelay_parcel` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
ON p.`id_order_detail` = d.`id_order_detail`
WHERE p.`shipping_number` = "'.pSQL($line['shipping_number']).'"
AND p.`date_add` = "'.pSQL($line['date_add']).'"
') as $art) {
$cpt++;
$i++;
$data_rows = array(
array(1, 1, 'A', 'CODFIC', 'A'),
array(2, 1, 'A', 'CODENR', '1'),
array(3, 1, 'A', 'SSCODE', '1'),
array(4, 2, 'A', 'MARQUE', 'F1'),
array(6, 8, 'A', 'NEXPE', $line['expedition_number']),
array(14, 2, 'N', 'SEQCAR', $i),
array(16, 1, 'N', 'CODART', '1'),
array(17, 1, 'A', 'FILLER', ''),
array(18, 5, 'N', 'QTART', (int) $art['quantity']),
array(23, 28, 'A', 'LIB', $art['product_name']),
array(51, 7, 'N', 'POIDS', (int) (Db::getInstance()->getValue('
SELECT `weight`
FROM `'._DB_PREFIX_.'product`
WHERE `id_product` = '.(int) $art['product_id'].'
') * $mr_account_details['MR_WEIGHT_COEFFICIENT'])),
array(58, 5, 'N', 'VOLUME', '0'),
array(63, 3, 'N', 'LONG', '0'),
array(66, 2, 'N', 'NBCOLI', '1'),
array(68, 5, 'N', 'Filler', ''),
array(73, 1, 'A', 'Filler', ''),
array(74, 1, 'A', 'Filler', ''),
array(75, 1, 'A', 'TOPSE1', ''),
array(76, 5, 'N', 'QTESE1', ''),
array(81, 1, 'A', 'TOPSE2', ''),
array(82, 5, 'N', 'QTESE2', ''),
array(87, 1, 'A', 'TOPSE3', ''),
array(88, 5, 'N', 'QTESE3', ''),
array(93, 1, 'A', 'TOPSE4', ''),
array(94, 5, 'N', 'QTESE4', ''),
array(99, 1, 'A', 'TOPSE5', ''),
array(100, 5, 'N', 'QTESE5', ''),
array(105, 1, 'A', 'TOPSE6', ''),
array(106, 5, 'N', 'QTESE6', ''),
array(111, 1, 'A', 'TOPSE7', ''),
array(112, 5, 'N', 'QTESE7', ''),
array(117, 1, 'A', 'TOPSE8', ''),
array(118, 5, 'N', 'QTESE8', ''),
array(123, 378, 'A', 'libre', '')
);
$result .= addRows($data_rows);
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'mondialrelay_dpc_sent` (`id_order_detail`, `expedition_number`, `shipping_number`, `date_add`)
VALUES (
'.(int)$art['id_order_detail'].',
"'.pSQL($line['expedition_number']).'",
"'.pSQL($line['shipping_number']).'",
NOW()
)
');
}
}
$data_rows = array(
array(1, 1, 'A', 'CODFIC', 'A'),
array(2, 1, 'A', 'CODENR', '0'),
array(3, 3, 'A', 'SOCEMET', 'MR '),
array(6, 3, 'A', 'SOCDEST', 'FRA'),
array(9, 5, 'N', 'SEQFIC', 1),
array(14, 7, 'N', 'NBENR', $cpt + 1),
array(21, 10, 'DT', 'DTTRAN', date('d.m.Y')),
array(31, 5, 'A', 'VERSION', '04.00'),
array(36, 965, 'A', 'libre', ''),
);
$data = addRows($data_rows);
$data .= mb_substr($result, 0, -1);
// $data = 'A0FRAMR 00001'
// .sprintf('%07d', $cpt + 1)
// .date('d.m.Y')
// .'04.00'
// .str_pad(' ', 965)
// ."\n"
// .mb_substr($result, 0, -1);
$fileName = 'dpc.D' . date('ymd') . 'H' . date('His') . '.txt';
// $fileName = 'dpc.test.txt';
$repo_dpc = dirname(__FILE__) . '/dpc/';
$repo_archive = dirname(__FILE__) . '/archives/dpc/';
$repo_paths = array(date('Y'), date('m'));
foreach ($repo_paths as $repo_path) {
$repo_archive .= $repo_path . '/';
if (!file_exists($repo_archive))
mkdir($repo_archive);
}
// file_put_contents($repo_dpc . $fileName, "\xEF\xBB\xBF".utf8_encode($w1252_data));
// file_put_contents($repo_archive . $fileName, "\xEF\xBB\xBF".utf8_encode($w1252_data));
// file_put_contents($repo_dpc . $fileName, mb_convert_encoding($data, "WINDOWS-1252", "UTF-8"));
// file_put_contents($repo_archive . $fileName, mb_convert_encoding($data, "WINDOWS-1252", "UTF-8"));
// file_put_contents($repo_dpc . $fileName, $data);
// file_put_contents($repo_archive . $fileName, $data);
$iconv = iconv('UTF-8', 'Windows-1252//TRANSLIT', $data);
if (!$iconv)
$iconv = $data;
file_put_contents($repo_dpc . $fileName, $iconv);
file_put_contents($repo_archive . $fileName, $iconv);
}
// echo 'A0FRAMR00001'.sprintf('%07d', $cpt + 1).date('d.m.Y').'04.00'."\n".mb_substr($result, 0, -1);
// SEND TO FTP
$mr_ftp_conf = Configuration::getMultiple(array(
'MONDIALRELAYWS_FTP_HOST',
'MONDIALRELAYWS_FTP_LOGIN',
'MONDIALRELAYWS_FTP_PASSWORD'
));
$id_ftp = ftp_connect($mr_ftp_conf['MONDIALRELAYWS_FTP_HOST']);
if (!ftp_login($id_ftp, $mr_ftp_conf['MONDIALRELAYWS_FTP_LOGIN'], $mr_ftp_conf['MONDIALRELAYWS_FTP_PASSWORD']))
die('erreur lors de l\'identification FTP'.chr(10).chr(10));
// //activation du mode passif
// // if (!ftp_pasv($id_ftp, true))
// // die('erreur lors de l\'activation du mode passif'.chr(10).chr(10));
$repo_dpc = dirname(__FILE__) . '/dpc/';
$mr_repo_in = 'versmrelay/';
//envoie du fichier
$list = scandir($repo_dpc);
foreach($list as $file)
{
if (!preg_match('/^dpc\..+\.txt$/', $file))
continue;
if ($file == '.' || $file == '..')
continue;
if (!ftp_put ($id_ftp, $mr_repo_in . $file, $repo_dpc . $file, FTP_BINARY))
print('erreur lors de l\'ouverture du fichier : ' . $file . chr(10));
else
unlink($repo_dpc . $file);
}
ftp_close($id_ftp);

View File

@ -0,0 +1,329 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/../../../../config/config.inc.php';
$regex = '/^trc\.(.*)\.txt$/';
## GET trc.Daammjj.Hhhmmss.txt FILE
$id_ftp = ftp_connect(Configuration::get('MONDIALRELAYWS_FTP_HOST'));
ftp_login($id_ftp, Configuration::get('MONDIALRELAYWS_FTP_LOGIN'), Configuration::get('MONDIALRELAYWS_FTP_PASSWORD'));
ftp_chdir($id_ftp, 'depuismrelay');
$list = ftp_nlist($id_ftp, '.');
foreach($list as $name_file)
{
$name_file;
if(!preg_match($regex, $name_file))
continue;
touch(dirname(__FILE__) . '/trace/' . $name_file);
chmod(dirname(__FILE__) . '/trace/' . $name_file, 0777);
$handle = fopen(dirname(__FILE__) . '/trace/' . $name_file, 'w+');
if (!ftp_fget($id_ftp, $handle, $name_file, FTP_BINARY)){
die('erreur lors de l\'ouverture du fichier : ' . $name_file . chr(10));
}
else{
ftp_delete($id_ftp, $name_file);
}
fclose($handle);
}
ftp_close($id_ftp);
## PROCESS FOR ALL "TRACE" FILES
$inFolder = dirname(__FILE__) . '/trace/';
$iterator = new DirectoryIterator($inFolder);
if(!is_object($iterator) || !count($iterator))
die('No file');
foreach ($iterator as $fileinfo) {
if (!$fileinfo->isFile() || $fileinfo->getFilename() == '..' || $fileinfo->getFilename() == '.')
continue;
if (!preg_match( $regex, $fileinfo->getFilename() ))
continue;
$file = fopen(dirname(__FILE__).'/trace/'.$fileinfo->getFilename(), 'r');
$trc_data = array();
$expeditions = array();
while($line = fgets($file)) {
if (substr($line, 1, 1) != '2')
continue;
$expedition_number = substr($line, 16, 8);
$situation = substr($line, 54, 3);
$info = substr($line, 57, 3);
$new_expedition_number = substr($line, 62, 15);
$date = explode('.', substr($line, 30, 10));
$date = $date[2].'-'.$date[1].'-'.$date[0].' '.substr($line, 50, 2).':'.substr($line, 52, 2).':00';
$trc_data[$expedition_number] = array(
'expedition_number' => $expedition_number,
'situation' => $situation,
'info' => $info,
'new_expedition_number' => $new_expedition_number,
'date' => $date
);
if ($situation == 'DPC')
$expeditions[] = $expedition_number;
}
if (!count($expeditions)) {
## ARCHIVE FILE
$repo_archive = dirname(__FILE__) . '/archives/trace/';
$repo_paths = array('others',date('Y'), date('m'));
foreach ($repo_paths as $repo_path) {
$repo_archive .= $repo_path . '/';
if (!file_exists($repo_archive))
mkdir($repo_archive);
}
rename(dirname(__FILE__).'/trace/'.$fileinfo->getFilename(), $repo_archive . $fileinfo->getFilename());
continue;
}
$expedition_orders = array();
$expedition_order_details = array();
$expedition_shipping = array();
$order_detail_qty = array();
foreach (Db::getInstance()->executeS('
SELECT d.`id_order`, s.`expedition_number`, s.`shipping_number`, d.`id_order_detail`, s.`quantity`
FROM `' . _DB_PREFIX_ . 'mondialrelay_parcel` s
LEFT JOIN `' . _DB_PREFIX_ . 'order_detail` d
ON d.`id_order_detail` = s.`id_order_detail`
LEFT JOIN `' . _DB_PREFIX_ . 'order_state_current` osc
ON osc.`id_order` = d.`id_order`
WHERE s.`expedition_number` IN (' . implode(', ', $expeditions) . ')
AND osc.`id_order_state` IN (2, 3, 12, 13, 17)
') as $row) {
$expedition_shipping[$row['expedition_number']] = $row['shipping_number'];
$expedition_orders[$row['expedition_number']] = (int) $row['id_order'];
if (!isset($expedition_order_details[$row['expedition_number']]))
$expedition_order_details[$row['expedition_number']] = array();
$expedition_order_details[$row['expedition_number']][] = (int) $row['id_order_detail'];
$order_detail_qty[(int) $row['id_order_detail']] = (int) $row['quantity'];
}
$mr_carriers = array();
foreach (Db::getInstance()->executeS('
SELECT `id_carrier`
FROM `' . _DB_PREFIX_ . 'mr_method`
ORDER BY `is_deleted` ASC') as $carrier) {
$mr_carriers[] = (int) $carrier['id_carrier'];
}
foreach ($expedition_orders as $expedition_number => $id_order) {
if (!isset($expedition_shipping[$expedition_number]) || !$expedition_shipping[$expedition_number])
continue;
$shipping_number = $expedition_shipping[$expedition_number];
if (!isset($expedition_order_details[$expedition_number]))
continue;
$order_details = $expedition_order_details[$expedition_number];
if (!isset($expedition_orders[$expedition_number]))
continue;
$order = new Order((int) $id_order);
if (!Validate::isLoadedObject($order))
continue;
$fully_sent = FALSE;
$products_sent = array();
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'lapostews` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'exapaqws` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'mondialrelay_parcel` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'philea_parcel` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
$_order_details = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order_detail`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order->id.'
') as $row) {
$_order_details[] = (int) $row['id_order_detail'];
}
$remaining = array();
foreach($_order_details as $d) {
if(!in_array($d, $products_sent)) {
$remaining[] = (int) $d;
}
}
if(count($remaining) == 0) {
$fully_sent = TRUE;
} else {
// $id_sales = array();
// foreach(Db::getInstance()->ExecuteS('
// SELECT DISTINCT c.`id_sale`
// FROM `'._DB_PREFIX_.'product_ps_cache` c
// LEFT JOIN `'._DB_PREFIX_.'order_detail` d
// ON c.`id_product` = d.`product_id`
// WHERE d.`id_order_detail` IN ('.implode(', ', $remaining).')
// ') as $row) {
// $id_sales[] = (int) $row['id_sale'];
// }
// $sent_sales = array();
// foreach(Db::getInstance()->ExecuteS('
// SELECT DISTINCT `id_sale`
// FROM `'._DB_PREFIX_.'shipping_history`
// WHERE `id_order` = '.(int) $order->id.'
// AND `id_sale` IN ('.implode(', ', $id_sales).')
// ') as $row) {
// $sent_sales[] = (int) $row['id_sale'];
// }
// $remaining = array();
// foreach($id_sales as $s) {
// if(empty($sent_sales) || !in_array($s, $sent_sales)) {
// $remaining[] = (int) $s;
// break;
// }
// }
// $fully_sent = (count($remaining) == 0);
}
$html_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(', ', $order_details).')
') as $p) {
if (isset($order_detail_qty[(int) $p['id_order_detail']]))
$html_products_sent .= '<br />'."\r\n".$order_detail_qty[(int) $p['id_order_detail']] . 'x' . ' ' . $p['product_name'];
}
$id_carrier = (int) $order->id_carrier;
if (!in_array($id_carrier, $mr_carriers))
$id_carrier = $mr_carriers[0];
$carrier = new Carrier($id_carrier, (int) $order->id_lang);
$customer = new Customer((int) $order->id_customer);
if((int) $order->id_lang == 3) {
$content_html = '<strong>Contenido del paquete:</strong>';
$content_txt = 'Contenido del paquete:';
} elseif((int) $order->id_lang == 5) {
$content_html = '<strong>Contenuto del package:</strong>';
$content_txt = 'Contenuto del package:';
} else {
$content_html = '<strong>Contenu du colis :</strong>';
$content_txt = 'Contenu du colis :';
}
if((int) $order->id_lang == 3) {
$url = 'http://www.puntopack.es/seguir-mi-envio/?numeroExpedition='.$shipping_number;
} else {
$url = 'http://www.mondialrelay.fr/suivi-de-colis/?numeroExpedition='.$shipping_number;
}
$templateVars = array(
'{followup}' => $url,
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{id_order}' => (int) $order->id,
'{product_list}' => !empty($html_products_sent)? $content_html.$html_products_sent: '',
'{product_list_txt}' => !empty($html_products_sent)? $content_txt.strip_tags($html_products_sent): '',
);
$history = new OrderHistory();
$history->id_order = (int) $order->id;
$history->changeIdOrderState(($fully_sent? Configuration::get('PS_OS_SHIPPING'): 17), (int) $order->id);
$history->id_employee = 0;
$history->addWithemail(TRUE, $templateVars);
global $_LANGMAIL;
$subject = 'Package in transit';
Mail::Send(
intval($order->id_lang),
'in_transit',
(
(is_array($_LANGMAIL) && key_exists($subject, $_LANGMAIL))
? $_LANGMAIL[$subject]
: $subject
),
$templateVars,
$customer->email,
$customer->firstname.' '.$customer->lastname
);
}
## ARCHIVE FILE
$repo_archive = dirname(__FILE__) . '/archives/trace/';
$repo_paths = array(date('Y'), date('m'));
foreach ($repo_paths as $repo_path) {
$repo_archive .= $repo_path . '/';
if (!file_exists($repo_archive))
mkdir($repo_archive);
}
rename(dirname(__FILE__).'/trace/'.$fileinfo->getFilename(), $repo_archive . $fileinfo->getFilename());
}

View File

@ -0,0 +1,62 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/../../../../config/config.inc.php';
## GET pltri.txt FILE
$fname = 'pltri.txt';
$filename = dirname(__FILE__) . '/' . $fname;
$file = fopen($filename, 'w+');
$remote_file = $fname;
$ftp = ftp_connect(Configuration::get('MONDIALRELAYWS_FTP_HOST'));
ftp_login($ftp, Configuration::get('MONDIALRELAYWS_FTP_LOGIN'), Configuration::get('MONDIALRELAYWS_FTP_PASSWORD'));
ftp_chdir($ftp, 'depuismrelay');
if (!ftp_fget($ftp, $file, $remote_file, FTP_BINARY))
die('An error occures while downloading remote file : ' . $fname);
$file = fopen($filename, 'r');
$content = fgets($file);
if (!$content)
die('File is empty : ' . $fname);
## Update DB
Db::getInstance()->ExecuteS('
TRUNCATE TABLE `'._DB_PREFIX_.'mondialrelay_tri`
');
while($line = fgets($file)) {
if(substr($line, 1, 1) == '1') {
$datdeb = explode('.', substr($line, 36, 10));
$datdeb = $datdeb[2].'-'.$datdeb[1].'-'.$datdeb[0];
$datfin = explode('.', substr($line, 46, 10));
$datfin = $datfin[2].'-'.$datfin[1].'-'.$datfin[0];
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'mondialrelay_tri`
VALUES (
"'.pSQl(substr($line, 2, 2)).'",
"'.pSQl(substr($line, 4, 8)).'",
"'.pSQl(substr($line, 12, 1)).'",
"'.pSQl(substr($line, 13, 3)).'",
"'.pSQl(substr($line, 16, 4)).'",
'.(int) substr($line, 20, 1).',
"'.pSQl(substr($line, 21, 5)).'",
"'.pSQl(substr($line, 26, 1)).'",
"'.pSQl(substr($line, 27, 3)).'",
"'.pSQl(substr($line, 30, 2)).'",
"'.pSQl(substr($line, 32, 4)).'",
"'.pSQl($datdeb).'",
"'.pSQl($datfin).'",
"'.pSQl(substr($line, 56, 2)).'",
"'.pSQl(substr($line, 58, 2)).'"
)
');
}
}

View File

@ -0,0 +1,19 @@
<?php
include dirname(__FILE__).'/../../../../config/config.inc.php';
if((Tools::getValue('token') === Tools::getAdminToken('AdminMondialRelaySummary'.(int) Tab::getIdFromClassName('AdminMondialRelaySummary').(int) Tools::getValue('id_employee')))
&& ($pdf_date = Tools::getValue('date')) && ($pdf_dm = Tools::getValue('dm')) && in_array($pdf_dm, array('24r', 'dri', 'ld1', 'lds', 'hom'))) {
$pdf_date = (string) (int) $pdf_date;
$pdf_date = substr($pdf_date, 0, 4).'-'.substr($pdf_date, 4, 2).'-'.substr($pdf_date, 6);
if(is_file(dirname(__FILE__).'/summaries/'.$pdf_date.'_'.$pdf_dm.'.pdf')) {
header('Content-type: application/pdf');
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Content-disposition: inline; filename="'.$pdf_date.'_'.$pdf_dm.'.pdf"');
readfile(dirname(__FILE__).'/summaries/'.$pdf_date.'_'.$pdf_dm.'.pdf');
} else {
echo 'ERROR - File not found';
}
}

View File

@ -0,0 +1,993 @@
<?php
if(!defined('_PS_VERSION_')) {
exit;
}
global $mondialrelay_formats;
$mondialrelay_formats = array(
'FR' => chr(2).'m'.'
1e1325011800082C{SHIPPING_NUMBER128}
131110011200180{SHIPPING_NUMBER}
1X1100009400050b0480015000010001
1X1100005500050b0480035000010001
1X1100004100050b0510009000010001
1X1100002940050b0510009000010001
1X1100003450585b0200011000010001
1X1100008370050l04800001
1X1100004500050l05100001
1X1100003370050l05100001
1X1100004050585l02000001
1X1100004100210l00010090
1X1100004100350l00010090
1X1100002940210l00010090
1X1100002940350l00010090
1X1100009400051P001000110870525
1X1100009400525P001000110870051
1911S2410500065P010P010{EXP_COMPANY}
1911S2310200065P008P008{EXP_ADDR1}
1911S2309900065P008P008{EXP_ADDR2}
1911S2309600065P008P008{EXP_POSTCODE} {EXP_CITY}
1911S2408550065P010P010Destinataire
1911S2407940065P010P010{DEST_ADDR1}
1911S2307640065P006P006{DEST_ADDR2}
1911S2307370065P006P006{DEST_ADDR3}
1911S2307100065P006P006{DEST_ADDR4}
1911S2306830065P006P006{DEST_ADDR5}
1911S2406440065P010P010{DEST_POSTCODE}
1911S2306440180P010P010{DEST_CITY}
1911S2306060065P010P010{DEST_PHONE}
1911S2305700065P010P010{DEST_OTHER}
1911S2410100570P025P014{SHIPPING_1} /
1911S2410180700P020P012{SHIPPING_2}
1911S2409200570P025P014AG {SHIPPING_3}
1911S2408400570P020P012N {SHIPPING_4} -
A5
1911S2408400710P020P012{SHIPPING_5}
A2
1911S2407600570P020P012T {SHIPPING_6}
1911S2406700570P025P014{SHIPPING_7}
1911S2406750850P020P0121/1
1911S2405700570P025P014{SHIPPING_8}
1911S2404650065P007P006N'.chr(248).' exp'.chr(130).'dition
1911S2404650220P007P006Date d\'envoi
1911S2404650360P007P006Agence de collecte
1911S2304220080P007P007{EXPEDITION_NUMBER}
1911S2304220220P007P007{DATE}
1911S2304220420P007P007{AGENCY_CODE}
1911S2404180595P009P009A Encaisser
1911S2403630661P010P0100 '.chr(255).'
1Y0000003240820MONDIALR
1911S2403500080P007P006Poids (kg)
1911S2403500225P007P006Volume (L)
1911S2403500410P007P006N'.chr(248).' Colis
1911S2303060085P007P007{WEIGHT}
1911S2303060265P007P007{VOLUME}
1911S2303060430P007P0071/1
1911S2302400050P007P007{INSTRUCTIONS}
'.chr(2).'n
',
'EN' => chr(2).'m'.'
1e1325011800052C{SHIPPING_NUMBER128}
131110011200180{SHIPPING_NUMBER}
1X1100009400050b0480015000010001
1X1100005500050b0480035000010001
1X1100004100050b0510009000010001
1X1100002940050b0510009000010001
1X1100003450585b0200011000010001
1X1100008370050l04800001
1X1100004500050l05100001
1X1100003370050l05100001
1X1100004050585l02000001
1X1100004100210l00010090
1X1100004100350l00010090
1X1100002940210l00010090
1X1100002940350l00010090
1X1100009400051P001000110870525
1X1100009400525P001000110870051
1911S2410500065P010P010{EXP_COMPANY}
1911S2310200065P008P008{EXP_ADDR1}
1911S2309900065P008P008{EXP_ADDR2}
1911S2309600065P008P008{EXP_POSTCODE} {EXP_CITY}
1911S2408550065P010P010Consignee
1911S2407940065P010P010{DEST_ADDR1}
1911S2307640065P006P006{DEST_ADDR2}
1911S2307370065P006P006{DEST_ADDR3}
1911S2307100065P006P006{DEST_ADDR4}
1911S2306830065P006P006{DEST_ADDR5}
1911S2406440065P010P010{DEST_POSTCODE}
1911S2306440180P010P010{DEST_CITY}
1911S2306060065P010P010{DEST_PHONE}
1911S2305700065P010P010{DEST_OTHER}
1911S2410100570P025P014{SHIPPING_1} /
1911S2410180700P020P012{SHIPPING_2}
1911S2409200570P025P014AG {SHIPPING_3}
1911S2408400570P020P012N {SHIPPING_4} -
A5
1911S2408400710P020P012{SHIPPING_5}
A2
1911S2407600570P020P012T {SHIPPING_6}
1911S2406700570P025P014{SHIPPING_7}
1911S2406750850P020P0121/1
1911S2405700570P025P014{SHIPPING_8}
1911S2404650065P007P006No. Shipment
1911S2404650220P007P006Sending Date
1911S2404650360P007P006Connection Agency
1911S2304220080P007P007{EXPEDITION_NUMBER}
1911S2304220220P007P007{DATE}
1911S2304220420P007P007{AGENCY_CODE}
1911S2404180595P009P009C.O.D.
1911S2403630661P010P0100 '.chr(255).'
1Y0000003240820MONDIALR
1911S2403500080P007P006Weight (kg)
1911S2403500225P007P006Volume (L)
1911S2403500410P007P006No. Parcel
1911S2303060085P007P007{WEIGHT}
1911S2303060265P007P007{VOLUME}
1911S2303060430P007P0071/1
1911S2302400050P007P007{INSTRUCTIONS}
'.chr(2).'n
',
'ES' => chr(2).'m'.'
1e1325011800052C{SHIPPING_NUMBER128}
131110011200180{SHIPPING_NUMBER}
1X1100009400050b0480015000010001
1X1100005500050b0480035000010001
1X1100004100050b0510009000010001
1X1100002940050b0510009000010001
1X1100003450585b0200011000010001
1X1100008370050l04800001
1X1100004500050l05100001
1X1100003370050l05100001
1X1100004050585l02000001
1X1100004100210l00010090
1X1100004100350l00010090
1X1100002940210l00010090
1X1100002940350l00010090
1X1100009400051P001000110870525
1X1100009400525P001000110870051
1911S2410500065P010P010{EXP_COMPANY}
1911S2310200065P008P008{EXP_ADDR1}
1911S2309900065P008P008{EXP_ADDR2}
1911S2309600065P008P008{EXP_POSTCODE} {EXP_CITY}
1911S2408550065P010P010Destinario
1911S2407940065P010P010{DEST_ADDR1}
1911S2307640065P006P006{DEST_ADDR2}
1911S2307370065P006P006{DEST_ADDR3}
1911S2307100065P006P006{DEST_ADDR4}
1911S2306830065P006P006{DEST_ADDR5}
1911S2406440065P010P010{DEST_POSTCODE}
1911S2306440180P010P010{DEST_CITY}
1911S2306060065P010P010{DEST_PHONE}
1911S2305700065P010P010{DEST_OTHER}
1911S2410100570P025P014{SHIPPING_1} /
1911S2410180700P020P012{SHIPPING_2}
1911S2409200570P025P014AG {SHIPPING_3}
1911S2408400570P020P012N {SHIPPING_4} -
A5
1911S2408400710P020P012{SHIPPING_5}
A2
1911S2407600570P020P012T {SHIPPING_6}
1911S2406700570P025P014{SHIPPING_7}
1911S2406750850P020P0121/1
1911S2405700570P025P014{SHIPPING_8}
1911S2404650065P007P006N'.chr(248).' d\'exp'.chr(130).'dicion
1911S2404650220P007P006Fetcha de envio
1911S2404650360P007P006Agencia de Cobros
1911S2304220080P007P007{EXPEDITION_NUMBER}
1911S2304220220P007P007{DATE}
1911S2304220420P007P007{AGENCY_CODE}
1911S2404180595P009P009A Cobrar
1911S2403630661P010P0100 '.chr(255).'
1Y0000003240820MONDIALR
1911S2403500080P007P006Peso (kg)
1911S2403500225P007P006Volumen (L)
1911S2403500410P007P006N'.chr(248).' Paquete
1911S2303060085P007P007{WEIGHT}
1911S2303060265P007P007{VOLUME}
1911S2303060430P007P0071/1
1911S2302400050P007P007{INSTRUCTIONS}
'.chr(2).'n
',
);
class MondialrelayCarrier {
public $displayName = 'Mondial Relay';
public function checkavailability() {
return TRUE;
}
public function __toString() {
return $this->displayName;
}
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_QUOTES, 'UTF-8')
);
}
public function renderLabel($order, $weight, $shipping_data) {
global $cookie, $mondialrelay_formats;
$mr_agencies = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'mondialrelay_agencies`');
$agencies = array();
foreach($mr_agencies as $row){
$agencies[$row['code']] = $row['name'];
}
$exp_company = Configuration::get('MONDIALRELAY_EXP_COMPANY');
$exp_address1 = Configuration::get('MONDIALRELAY_EXP_ADDR1');
$exp_address2 = Configuration::get('MONDIALRELAY_EXP_ADDR2');
$exp_postal = Configuration::get('MONDIALRELAY_EXP_POSTALCODE');
$exp_city = Configuration::get('MONDIALRELAY_EXP_CITY');
$exp_country = Configuration::get('MONDIALRELAY_EXP_COUNTRY');
$delivery_address = new Address((int) $order->id_address_delivery);
if(!Validate::isLoadedObject($delivery_address)) {
return FALSE;
}
$delivery_infos = Db::getInstance()->getRow('
SELECT s.*, m.`dlv_mode`
FROM `'._DB_PREFIX_.'mr_selected` s
LEFT JOIN `'._DB_PREFIX_.'mr_method` m ON s.`id_method` = m.`id_mr_method`
WHERE s.`id_order` = '.(int) $order->id.'
');
// Hack 5 numbers relay num
if (isset($delivery_infos['MR_Selected_Num']) && $delivery_infos['MR_Selected_Num'])
$delivery_infos['MR_Selected_Num'] = substr($delivery_infos['MR_Selected_Num'], -5);
if(!$delivery_infos || in_array($delivery_infos['dlv_mode'], array('LDS', 'LD1', 'HOM'))) {
$mode = $delivery_infos? $delivery_infos['dlv_mode']: 'LD1';
$shipping = array(
$delivery_address->firstname.' '.$delivery_address->lastname,
$delivery_address->company,
$delivery_address->address1,
$delivery_address->address2,
$delivery_address->postcode,
$delivery_address->city,
'',
empty($delivery_address->phone)? $delivery_address->phone_mobile: $delivery_address->phone,
trim(str_replace('|', ' ', $delivery_address->other)),
);
$dest_country = $delivery_address->id_country;
} else {
$mr_relais = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'mondialrelay_relais`
WHERE 1
AND `direction` = "'.pSQL($delivery_infos['MR_Selected_Num']).'"
AND `prpay` = "'.pSQL($delivery_infos['MR_Selected_Pays']).'"
');
if(!$mr_relais){
return false;
}
$mode = $delivery_infos['dlv_mode'];
if($mode == '24R') {
if($mr_relais['narel'] == 'F') {
$mode = '24X';
} elseif($mr_relais['narel'] == 'E') {
$mode = '24L';
} else {
$mode = '24R';
}
}
$shipping = array(
$delivery_address->firstname.' '.$delivery_address->lastname,
$mr_relais['colnom'],
$mr_relais['colbat'],
str_replace(' AVENUE D', ' AV. D', str_replace(' GENERAL LECLERC', ' GAL LECLERC', $mr_relais['colrue'])),
$mr_relais['coldit'],
$mr_relais['codpos'],
$mr_relais['libbp'],
empty($delivery_address->phone_mobile)? $delivery_address->phone: $delivery_address->phone_mobile,
'',
);
$dest_country = (int) Db::getInstance()->getValue('
SELECT `id_country`
FROM `'._DB_PREFIX_.'country`
WHERE `iso_code` = "'.pSQL($delivery_infos['MR_Selected_Pays']).'"
');
}
if(mb_strlen($shipping[2]) > 22 && $shipping[3] == '') {
$shipping[3] = mb_substr($shipping[2], 22, 22);
$shipping[2] = mb_substr($shipping[2], 0, 22);
}
$format = str_replace(
array(
'{SHIPPING_NUMBER128}',
'{SHIPPING_NUMBER}',
'{EXP_COMPANY}',
'{EXP_ADDR1}',
'{EXP_ADDR2}',
'{EXP_POSTCODE}',
'{EXP_CITY}',
'{DEST_ADDR1}',
'{DEST_ADDR2}',
'{DEST_ADDR3}',
'{DEST_ADDR4}',
'{DEST_ADDR5}',
'{DEST_POSTCODE}',
'{DEST_CITY}',
'{DEST_PHONE}',
'{DEST_OTHER}',
'{SHIPPING_1}',
'{SHIPPING_2}',
'{SHIPPING_3}',
'{SHIPPING_4}',
'{SHIPPING_5}',
'{SHIPPING_6}',
'{SHIPPING_7}',
'{SHIPPING_8}',
'{EXPEDITION_NUMBER}',
'{DATE}',
'{AGENCY_CODE}',
'{WEIGHT}',
'{VOLUME}',
'{INSTRUCTIONS}',
),
array(
$shipping_data['shipping_number'],
$shipping_data['shipping_number_fmt'],
$exp_company,
$exp_address1,
$exp_address2,
$exp_postal,
$exp_city,
$shipping[0],
$shipping[1],
$shipping[2],
$shipping[3],
$shipping[4],
$shipping[5],
$shipping[6],
$shipping[7],
$shipping[8],
$shipping_data['plantri']['cppay'],
$shipping_data['plantri']['nogroup'],
$shipping_data['plantri']['modexp'],
$shipping_data['plantri']['pretri'], // N ...
$shipping_data['plantri']['navette'],
$shipping_data['plantri']['direction'], // T ...
$shipping_data['mode'],
$agencies[$shipping_data['plantri']['modexp']],
$shipping_data['expedition_number'],
date('d/m/Y'),
Db::getInstance()->getValue('
SELECT `modexp`
FROM `'._DB_PREFIX_.'mondialrelay_tri`
WHERE `cppay` = "'.pSQL(Db::getInstance()->getValue('
SELECT `iso_code`
FROM `'._DB_PREFIX_.'country`
WHERE `id_country` = '.(int) $exp_country.'
')).'"
AND `destex` = "'.pSQL($exp_postal).'"
'),
number_format((float) $shipping_data['weight'], 2, ',', ''),
'NC',
'',
),
$mondialrelay_formats[$dest_country == 6? 'ES': (in_array($dest_country, array(3, 8, 12))? 'FR': 'EN')]
);
return $format;
}
public function getShippingNumber($id_order) {
Db::getInstance()->Execute('SET AUTOCOMMIT = 0');
Db::getInstance()->Execute('START TRANSACTION');
$res = Db::getInstance()->ExecuteS('
SELECT `value`
FROM `'._DB_PREFIX_.'logistics_shipping`
WHERE `carrier` = "MONDIALRELAY"
FOR UPDATE
');
$sequence = (int) $res[0]['value'] + 1;
// LOOP SHIPPING SEQUENCE
if ($sequence < Configuration::get('MONDIALRELAY_SHIPPINGLOW') || $sequence > Configuration::get('MONDIALRELAY_SHIPPINGHIGH'))
$sequence = Configuration::get('MONDIALRELAY_SHIPPINGLOW');
// CHECK UNICITY
$last_update = Db::getInstance()->getValue('SELECT DATE_ADD(`date_upd`, INTERVAL 1 YEAR) FROM `' . _DB_PREFIX_ . 'mondialrelay_expedition_numbers` WHERE `sequence` = ' . (int) $sequence);
if ($last_update && $last_update > date('Y-m-d H:i:s')){
$content = 'Le numéro d\'expédition ' . $sequence . ' a été affecté il y a moins d\'un an.' . "\n" . 'Impossible d\'affecter un nouveau numéro d\'expédition';
mail('marion@antadis.com', '[BBB MONDIAL RELAY] Numéro d\'expédition', $content, 'Content-Type: text/plain; charset="utf-8"'."\r\n".'From: commande@bebeboutik.com'."\r\n".'Reply-To: marion@antadis.com'."\r\n".'Return-Path: marion@antadis.com'."\r\n");
return false;
}
Db::getInstance()->execute('
INSERT INTO ' . _DB_PREFIX_ . 'mondialrelay_expedition_numbers (`sequence`, `date_upd`)
VALUES (' . (int) $sequence . ', "' . pSQL(date('Y-m-d H:i:s')) . '")
ON DUPLICATE KEY UPDATE date_upd="' . pSQL(date('Y-m-d H:i:s')) . '";
');
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'logistics_shipping`
SET `value` = "'.(int) $sequence.'"
WHERE `carrier` = "MONDIALRELAY"
');
Db::getInstance()->Execute('COMMIT');
Db::getInstance()->Execute('SET AUTOCOMMIT = 1');
return $sequence;
}
public function registerParcel($order, $products, $weight) {
global $cookie;
$delivery_infos = Db::getInstance()->getRow('
SELECT s.*, m.`dlv_mode`
FROM `'._DB_PREFIX_.'mr_selected` s
LEFT JOIN `'._DB_PREFIX_.'mr_method` m ON (s.`id_method` = m.`id_mr_method`)
WHERE s.`id_order` = '.(int) $order->id.'
');
// Hack 5 numbers relay num
if (isset($delivery_infos['MR_Selected_Num']) && $delivery_infos['MR_Selected_Num']) {
$delivery_infos['MR_Selected_Num'] = substr($delivery_infos['MR_Selected_Num'], -5);
}
if(!$delivery_infos || in_array($delivery_infos['dlv_mode'], array('LDS', 'LD1', 'HOM'))) {
$mode = $delivery_infos? $delivery_infos['dlv_mode']: 'LD1';
$address = Db::getInstance()->getRow('
SELECT a.`postcode`, UPPER(c.`iso_code`) AS `iso_code`
FROM `'._DB_PREFIX_.'address` a
LEFT JOIN `'._DB_PREFIX_.'country` c
ON a.`id_country` = c.`id_country`
WHERE a.`id_address` = '.(int) $order->id_address_delivery.'
');
$country = $address['iso_code'];
$postcode = $address['postcode'];
$mode_tri = $mode == 'LD1' ? 'LDR': $mode;
$plantri = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'mondialrelay_tri`
WHERE `destyp` = "CP"
AND `destex` = "'.pSQL($postcode).'"
AND `cppay` = "'.pSQL($country).'"
AND (
`livmod` = "'.pSQL($mode_tri).'"
OR `livmod` = "HOM"
) ORDER BY `livmod` DESC
');
if(!$plantri) {
$plantri = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'mondialrelay_tri`
WHERE `destyp` = "DT"
AND `destex` = "'.pSQL(substr($postcode, 0, 2)).'"
AND `cppay` = "'.pSQL($country).'"
AND (
`livmod` = "'.pSQL($mode_tri).'"
OR `livmod` = "HOM"
) ORDER BY `livmod` DESC
');
}
if($plantri) {
$mode = ($plantri['livmod'] == 'LDR'?'LD1':$plantri['livmod']);
}
} else {
$mr_relais = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'mondialrelay_relais`
WHERE 1
AND `direction` = "'.pSQL($delivery_infos['MR_Selected_Num']).'"
AND `prpay` = "'.pSQL($delivery_infos['MR_Selected_Pays']).'"
');
if(!$mr_relais){
return array('<p class="error">Point relais not found</p><br />', array());
}
$mode = $delivery_infos['dlv_mode'];
if($mode == '24R') {
if($mr_relais['narel'] == 'F') {
$mode = '24X';
} elseif($mr_relais['narel'] == 'E') {
$mode = '24L';
} else {
$mode = '24R';
}
}
$country = $delivery_infos['MR_Selected_Pays'];
$postcode = $delivery_infos['MR_Selected_CP'];
$plantri = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'mondialrelay_tri`
WHERE `destyp` = "RL"
AND `destex` = "'.pSQL($delivery_infos['MR_Selected_Num']).'"
AND `cppay` = "'.pSQL($country).'"
');
}
if(!$plantri) {
// TODO: error handling
return array('<p class="error">Tri not found</p><br />', array());
}
$sequence = $this->getShippingNumber((int) $order->id);
if (!$sequence){
return array('<p class="error">Unicité du numéro d\'expédition non respecté</p><br />', array());
}
$expedition_number = sprintf('%08d', $sequence);
$mr_info = Configuration::get('MR_ACCOUNT_DETAIL');
$mr_info = unserialize($mr_info);
// $shipping_number_1 = Configuration::get('MONDIALRELAY_ENSIGN_CODE').$expedition_number.'0101';
$shipping_number_1 = $mr_info['MR_CODE_MARQUE'].$expedition_number.'0101';
$control_number_1 = 11 - ((int) substr($shipping_number_1, 13, 1) * 2 + (int) substr($shipping_number_1, 12, 1) * 3 + (int) substr($shipping_number_1, 11, 1) * 4 + (int) substr($shipping_number_1, 10, 1) * 5 + (int) substr($shipping_number_1, 9, 1) * 6 + (int) substr($shipping_number_1, 8, 1) * 7 + (int) substr($shipping_number_1, 7, 1) * 2 + (int) substr($shipping_number_1, 6, 1) * 3 + (int) substr($shipping_number_1, 5, 1) * 4 + (int) substr($shipping_number_1, 4, 1) * 5 + (int) substr($shipping_number_1, 3, 1) * 6 + (int) substr($shipping_number_1, 2, 1) * 7 + (int) substr($shipping_number_1, 1, 1) * 2 + (int) substr($shipping_number_1, 0, 1) * 3) % 11;
if($control_number_1 == 10 || $control_number_1 == 11) {
$control_number_1 = 0;
}
$shipping_number_2 = $plantri['modexp'].$plantri['service'].$plantri['direction'];
$control_number_2 = 11 - ((int) substr($shipping_number_2, 9, 1) * 2 + (int) substr($shipping_number_2, 8, 1) * 3 + (int) substr($shipping_number_2, 7, 1) * 4 + (int) substr($shipping_number_2, 6, 1) * 5 + (int) substr($shipping_number_2, 5, 1) * 6 + (int) substr($shipping_number_2, 4, 1) * 7 + (int) substr($shipping_number_2, 3, 1) * 2 + (int) substr($shipping_number_2, 2, 1) * 3 + (int) substr($shipping_number_2, 1, 1) * 4 + (int) substr($shipping_number_2, 0, 1) * 5) % 11;
if($control_number_2 == 10 || $control_number_2 == 11) {
$control_number_2 = 0;
}
$shipping_number = $shipping_number_1.$control_number_1.$shipping_number_2.$control_number_2;
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'] != '90.63.178.63') {
$order->shipping_number = $shipping_number;
$order->update();
}
return array('', array(
'idrelay' => $delivery_infos? $delivery_infos['MR_Selected_Num']: '',
'shipping_number' => $shipping_number,
'shipping_number_fmt' => substr($shipping_number, 0, 2).' '.substr($shipping_number, 2, 8).' '.substr($shipping_number, 10, 4).' '.substr($shipping_number, 14, 1).' '.substr($shipping_number, 15, 4).' '.substr($shipping_number, 19, 1).' '.substr($shipping_number, 20, 5).' '.substr($shipping_number, 25, 1),
'shipping_number_c25i' => $this->isoreplace($this->c25I($shipping_number)),
'weight' => $weight,
'plantri' => $plantri,
'mode' => $mode,
'expedition_number' => $expedition_number,
));
}
public function _getRegisteredParcel($order, $id_order_detail , $products, $weight) {
global $cookie;
$delivery_infos = Db::getInstance()->getRow('
SELECT s.*, m.`dlv_mode`
FROM `'._DB_PREFIX_.'mr_selected` s
LEFT JOIN `'._DB_PREFIX_.'mr_method` m ON (s.`id_method` = m.`id_mr_method`)
WHERE s.`id_order` = '.(int) $order->id.'
');
// Hack 5 numbers relay num
if (isset($delivery_infos['MR_Selected_Num']) && $delivery_infos['MR_Selected_Num']) {
$delivery_infos['MR_Selected_Num'] = substr($delivery_infos['MR_Selected_Num'], -5);
}
if(!$delivery_infos || in_array($delivery_infos['dlv_mode'], array('LDS', 'LD1', 'HOM'))) {
$mode = $delivery_infos? $delivery_infos['dlv_mode']: 'LD1';
$address = Db::getInstance()->getRow('
SELECT a.`postcode`, UPPER(c.`iso_code`) AS `iso_code`
FROM `'._DB_PREFIX_.'address` a
LEFT JOIN `'._DB_PREFIX_.'country` c
ON a.`id_country` = c.`id_country`
WHERE a.`id_address` = '.(int) $order->id_address_delivery.'
');
$country = $address['iso_code'];
$postcode = $address['postcode'];
$mode_tri = $mode == 'LD1' ? 'LDR': $mode;
$plantri = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'mondialrelay_tri`
WHERE `destyp` = "CP"
AND `destex` = "'.pSQL($postcode).'"
AND `cppay` = "'.pSQL($country).'"
AND (
`livmod` = "'.pSQL($mode_tri).'"
OR `livmod` = "HOM"
) ORDER BY `livmod` DESC
');
if(!$plantri) {
$plantri = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'mondialrelay_tri`
WHERE `destyp` = "DT"
AND `destex` = "'.pSQL(substr($postcode, 0, 2)).'"
AND `cppay` = "'.pSQL($country).'"
AND (
`livmod` = "'.pSQL($mode_tri).'"
OR `livmod` = "HOM"
) ORDER BY `livmod` DESC
');
}
if($plantri) {
$mode = ($plantri['livmod'] == 'LDR'?'LD1':$plantri['livmod']);
}
} else {
$mr_relais = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'mondialrelay_relais`
WHERE 1
AND `direction` = "'.pSQL($delivery_infos['MR_Selected_Num']).'"
AND `prpay` = "'.pSQL($delivery_infos['MR_Selected_Pays']).'"
');
$mode = $delivery_infos['dlv_mode'];
if($mode == '24R') {
if($mr_relais['narel'] == 'F') {
$mode = '24X';
} elseif($mr_relais['narel'] == 'E') {
$mode = '24L';
} else {
$mode = '24R';
}
}
$country = $delivery_infos['MR_Selected_Pays'];
$postcode = $delivery_infos['MR_Selected_CP'];
$plantri = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'mondialrelay_tri`
WHERE `destyp` = "RL"
AND `destex` = "'.pSQL($delivery_infos['MR_Selected_Num']).'"
AND `cppay` = "'.pSQL($country).'"
');
}
if(!$plantri) {
// TODO: error handling
return;
}
$sequence = Db::getInstance()->getRow('
SELECT expedition_number
FROM `'._DB_PREFIX_.'mondialrelay_parcel`
WHERE `id_order_detail` = '.(int)$id_order_detail);
if (!$sequence){
return array('<p class="error">Unicité du numéro d\'expédition non respecté</p><br />', array());
}
$expedition_number = sprintf('%08d', $sequence['expedition_number']);
$mr_info = Configuration::get('MR_ACCOUNT_DETAIL');
$mr_info = unserialize($mr_info);
// $shipping_number_1 = Configuration::get('MONDIALRELAY_ENSIGN_CODE').$expedition_number.'0101';
$shipping_number_1 = $mr_info['MR_CODE_MARQUE'].$expedition_number.'0101';
$control_number_1 = 11 - ((int) substr($shipping_number_1, 13, 1) * 2 + (int) substr($shipping_number_1, 12, 1) * 3 + (int) substr($shipping_number_1, 11, 1) * 4 + (int) substr($shipping_number_1, 10, 1) * 5 + (int) substr($shipping_number_1, 9, 1) * 6 + (int) substr($shipping_number_1, 8, 1) * 7 + (int) substr($shipping_number_1, 7, 1) * 2 + (int) substr($shipping_number_1, 6, 1) * 3 + (int) substr($shipping_number_1, 5, 1) * 4 + (int) substr($shipping_number_1, 4, 1) * 5 + (int) substr($shipping_number_1, 3, 1) * 6 + (int) substr($shipping_number_1, 2, 1) * 7 + (int) substr($shipping_number_1, 1, 1) * 2 + (int) substr($shipping_number_1, 0, 1) * 3) % 11;
if($control_number_1 == 10 || $control_number_1 == 11) {
$control_number_1 = 0;
}
$shipping_number_2 = $plantri['modexp'].$plantri['service'].$plantri['direction'];
$control_number_2 = 11 - ((int) substr($shipping_number_2, 9, 1) * 2 + (int) substr($shipping_number_2, 8, 1) * 3 + (int) substr($shipping_number_2, 7, 1) * 4 + (int) substr($shipping_number_2, 6, 1) * 5 + (int) substr($shipping_number_2, 5, 1) * 6 + (int) substr($shipping_number_2, 4, 1) * 7 + (int) substr($shipping_number_2, 3, 1) * 2 + (int) substr($shipping_number_2, 2, 1) * 3 + (int) substr($shipping_number_2, 1, 1) * 4 + (int) substr($shipping_number_2, 0, 1) * 5) % 11;
if($control_number_2 == 10 || $control_number_2 == 11) {
$control_number_2 = 0;
}
$shipping_number = $shipping_number_1.$control_number_1.$shipping_number_2.$control_number_2;
return array('', array(
'idrelay' => $delivery_infos? $delivery_infos['MR_Selected_Num']: '',
'shipping_number' => $shipping_number,
'shipping_number_fmt' => substr($shipping_number, 0, 2).' '.substr($shipping_number, 2, 8).' '.substr($shipping_number, 10, 4).' '.substr($shipping_number, 14, 1).' '.substr($shipping_number, 15, 4).' '.substr($shipping_number, 19, 1).' '.substr($shipping_number, 20, 5).' '.substr($shipping_number, 25, 1),
'shipping_number_c25i' => $this->isoreplace($this->c25I($shipping_number)),
'weight' => $weight,
'plantri' => $plantri,
'mode' => $mode,
'expedition_number' => $expedition_number,
));
}
private function c25I($string, $checksum=FALSE) {
if(strlen($string) == 0 || strlen($string) % 2 != 0 || !is_numeric($string)) {
return '';
}
if($checksum) {
$i = strlen($string) - 1;
$checksum = 0;
for($i=strlen($string) - 1; $i >= 0; $i -= 2) {
$checksum += (int) substr($string, $i, 1);
}
$checksum = $checksum * 3;
for($i=strlen($string) - 2; $i >= 0; $i -= 2) {
$checksum += (int) substr($string, $i, 1);
}
$string = $string.((10 - ($checksum % 10)) % 10);
}
$result = '';
for($i=0, $l=strlen($string); $i < $l; $i += 2) {
$dummy = (int) substr($string, $i, 2);
$dummy += ($dummy < 94? 33: 101);
$result .= chr($dummy);
}
return '«'.$result.'»';
}
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(174), chr(175),
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), chr(210),
), $str);
}
public function logParcel($shipping_data, $products) {
global $cookie;
foreach($products as $id_order_detail => $qty) {
if($qty > 0) {
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'mondialrelay_parcel` VALUES (
'.(int) $id_order_detail.',
'.(int) $cookie->id_employee.',
'.(int) $qty.',
"'.pSQL($shipping_data['shipping_number']).'",
"'.pSQL($shipping_data['idrelay']).'",
"'.pSQL($shipping_data['plantri']['cppay']).'",
"'.pSQL($shipping_data['plantri']['nogroup']).'",
"'.pSQL($shipping_data['plantri']['modexp']).'",
"'.pSQL($shipping_data['plantri']['pretri']).'",
"'.pSQL($shipping_data['plantri']['navette']).'",
"'.pSQL($shipping_data['plantri']['direction']).'",
"'.pSQL($shipping_data['mode']).'",
"'.pSQL($shipping_data['expedition_number']).'",
'.(float) $shipping_data['weight'].',
NOW(),
"0000-00-00 00:00:00"
)
');
}
}
}
public function __addOrderHistory($shipping_data, $order, $products_sent) {
}
public function addOrderHistory($shipping_data, $order, $products_sent) {
global $cookie;
// $MONDIALRELAY_carrier_id = unserialize(Configuration::get('MONDIALRELAY_CARRIERS'));
// $MONDIALRELAY_carrier_id = (int) array_pop($exapaq_carrier_id);
$id_carrier = (int) $order->id_carrier;
$mr_carriers = array();
foreach (Db::getInstance()->executeS('
SELECT `id_carrier`
FROM `' . _DB_PREFIX_ . 'mr_method`
ORDER BY `is_deleted` ASC') as $carrier) {
$mr_carriers = (int) $carrier['id_carrier'];
}
if (!in_array($id_carrier, $mr_carriers))
$id_carrier = $mr_carriers[0];
$carrier = new Carrier($id_carrier, (int) $order->id_lang);
$customer = new Customer((int) $order->id_customer);
if((int) $order->id_lang == 3) {
$content_html = '<strong>Contenido del paquete:</strong>';
$content_txt = 'Contenido del paquete:';
} elseif((int) $order->id_lang == 5) {
$content_html = '<strong>Contenuto del package:</strong>';
$content_txt = 'Contenuto del package:';
} else {
$content_html = '<strong>Contenu du colis :</strong>';
$content_txt = 'Contenu du colis :';
}
$templateVars = array(
'{followup}' => "https://www.mondialrelay.fr/suivi-de-colis?numeroExpedition=".$shipping_data['shipping_number'],
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{id_order}' => (int) $order->id,
'{product_list}' => !empty($products_sent)? $content_html.$products_sent: '',
'{product_list_txt}' => !empty($products_sent)? $content_txt.strip_tags($products_sent): '',
);
$history = new OrderHistory();
$history->id_order = (int) $order->id;
$fully_sent = FALSE;
$products_sent = array();
$order_details = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order_detail`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order->id.'
') as $row) {
$order_details[] = (int) $row['id_order_detail'];
}
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'lapostews` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'exapaqws` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'mondialrelay_parcel` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'philea_parcel` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
$remaining = array();
foreach($order_details as $d) {
if(!in_array($d, $products_sent)) {
$remaining[] = (int) $d;
}
}
if(count($remaining) == 0) {
$fully_sent = TRUE;
} else {
$id_sales = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT c.`id_sale`
FROM `'._DB_PREFIX_.'product_ps_cache` c
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
ON c.`id_product` = d.`product_id`
WHERE d.`id_order_detail` IN ('.implode(', ', $remaining).')
') as $row) {
$id_sales[] = (int) $row['id_sale'];
}
$sent_sales = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT `id_sale`
FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` = '.(int) $order->id.'
AND `id_sale` IN ('.implode(', ', $id_sales).')
') as $row) {
$sent_sales[] = (int) $row['id_sale'];
}
$remaining = array();
foreach($id_sales as $s) {
if(!in_array($s, $sent_sales)) {
$remaining[] = (int) $s;
break;
}
}
$fully_sent = (count($remaining) == 0);
}
$history->changeIdOrderState(($fully_sent? Configuration::get('PS_OS_SHIPPING'): 17), (int) $order->id);
$history->id_employee = (int) $cookie->id_employee;
$history->addWithemail(TRUE, $templateVars);
global $_LANGMAIL;
$subject = 'Package in transit';
if((int) $order->id_lang == 3) {
$subject = 'Paquete en tránsito';
} else {
$subject = 'Package in transit';
}
Mail::Send(
intval($order->id_lang),
'in_transit',
(
(is_array($_LANGMAIL) && key_exists($subject, $_LANGMAIL))
? $_LANGMAIL[$subject]
: $subject
),
$templateVars,
$customer->email,
$customer->firstname.' '.$customer->lastname
);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,192 @@
<html>
<head>
<style type="text/css">{literal}
body {
margin: 0px;
padding: 0px;
font-family: sans-serif;
font-size: 11px;
line-height: 16px;
}
table {
border-collapse: collapse;
width: 100%;
}
td {
vertical-align: top;
}
thead th, .bar {
background: #cccccc;
text-align: left;
font-weight: normal;
}
thead th, tbody td {
padding: 2px 4px;
}
.right {
text-align: right;
}
.strong {
font-weight: bold;
}
.width1 {
width: 100px;
}
.width0 {
width: 20px;
}
.border td {
width: 250px;
border: 1px solid #000000;
padding: 10px;
}
{/literal}</style>
</head>
<body>
{literal}
<!--mpdf
<htmlpagefooter name="myfooter">
<div style="text-align: right;">
Page {PAGENO}/{nb}
</div>
</htmlpagefooter>
<sethtmlpagefooter name="myfooter" value="on" />
mpdf-->
{/literal}
<table>
<tr>
<td>SITE DE PRISE EN CHARGE : {$site_code}</td>
<td class="right strong">BORDEREAU DE REMISE Offre Entreprises So Colissimo</td>
</tr>
<tr>
<td colspan="2">LIBELLE SITE DE PRISE EN CHARGE : {$site}</td>
</tr>
</table>
<table>
<tr>
<td class="width1">N° CLIENT</td><td class="width0">:</td><td>{$contract}</td>
<td class="right">EDITE LE {$date}</td>
</tr>
<tr>
<td class="width1">LIBELLE CLIENT</td><td class="width0">:</td>
<td colspan="2">{foreach $sender_lines as $line}{$line}<br />{/foreach}
{$sender_postal} {$sender_city}<br /><br /><br /><br /></td>
</tr>
<tr>
<td class="width1">N° BORDEREAU</td><td class="width0">:</td><td colspan="2">{$summary_number} du {$date}</td>
</tr>
<tr>
<td class="strong" colspan="3"><br />{$title} - Compte de facturation : {$contract}</td>
</tr>
</table>
{assign var=i value=1}
<table>
<thead>
<tr>
<th>Ref exped</th><th>Adresse destinataire</th><th>N° colis</th><th>CPOST</th><th>CPAYS</th><th>Poids</th><th>N</th><th>CRBT</th><th>VA</th>
</th>
</thead>
<tfoot>
<tr><td class="bar" colspan="9"></td></tr>
<tr>
<td colspan="9">
<br />
NOMBRE DES COLIS DE LA PAGE : {if $count_orders <= 46}
{$count_orders}
{else}
46
{/if}
<br />
POIDS DES COLIS DE LA PAGE : {if $count_orders <= 46}
{$total_weight|number_format:2:',':''}
{else}
{(0.24*46)|number_format:2:',':''}
{/if} KG<br />
TOTAL CRBT DE LA PAGE : 0,00 EUR<br />
</td>
</tr>
</tfoot>
<tbody>
{foreach $orders as $order name=orders}
<tr>
<td>EXP{$order.id_order}</td>
<td>{$order.lastname|cat:' - '|cat:$order.address1|truncate:60:''}</td>
<td>{$order.shipping_number}</td>
<td>{$order.postcode}</td>
<td>FR</td>
<td>0,24</td>
<td>0</td>
<td>000.00</td>
<td>00</td>
</tr>
{if $smarty.foreach.orders.iteration % 46 == 0 && $smarty.foreach.orders.iteration != $smarty.foreach.orders.total}
{assign var=i value=$i+1}
</tbody>
</table>
<formfeed />
<table>
<thead>
<tr>
<th>Ref exped</th><th>Adresse destinataire</th><th>N° colis</th><th>CPOST</th><th>CPAYS</th><th>Poids</th><th>N</th><th>CRBT</th><th>VA</th>
</th>
</thead>
<tfoot>
<tr><td class="bar" colspan="9"></td></tr>
<tr>
<td colspan="9">
<br />
NOMBRE DES COLIS DE LA PAGE : {if $smarty.foreach.orders.iteration + 46 > $smarty.foreach.orders.total}
{$smarty.foreach.orders.total - $smarty.foreach.orders.iteration}
{else}
46
{/if}<br />
POIDS DES COLIS DE LA PAGE : {if $smarty.foreach.orders.iteration + 46 > $smarty.foreach.orders.total}
{(($smarty.foreach.orders.total - $smarty.foreach.orders.iteration)*0.24)|number_format:2:',':''}
{else}
{(46*0.24)|number_format:2:',':''}
{/if} KG<br />
TOTAL CRBT DE LA PAGE : 0,00 EUR<br />
</td>
</tr>
</tfoot>
<tbody>
{/if}
{/foreach}
</tbody>
</table>
<br /><br /><br />
<table>
<tr>
<td>
<br /><br />
NOMBRE TOTAL DE COLIS : {$count_orders}<br />
POIDS TOTAL DE COLIS : {$total_weight|number_format:2:',':''} KG<br />
TOTAL CRBT : 0,00 EUR<br />
<br />
Nombre de pages : {literal} <!--mpdf {nb} mpdf--> {/literal}
</td>
<td class="right">
<table class="border"><tr><td>
SIGNATURE DE L'AGENT (*)<br />
<br /><br /><br /><br />
DATE<br /><br />
</td></tr></table>
<br /><br /><br />
* Cette signature ne vaut pas validation des données indiquées par le client
</td>
</tr>
</table>
</body>
</html>

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,47 @@
/* French initialisation for the jQuery UI date picker plugin. */
/* Written by Keith Wood (kbwood{at}iinet.com.au),
Stéphane Nahmani (sholby@sholby.net),
Stéphane Raimbault <stephane.raimbault@gmail.com> */
jQuery(function($){
$.datepicker.regional['fr'] = {
closeText: 'Fermer',
prevText: 'Précédent',
nextText: 'Suivant',
currentText: 'Aujourd\'hui',
monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin',
'Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
monthNamesShort: ['Janv.','Févr.','Mars','Avril','Mai','Juin',
'Juil.','Août','Sept.','Oct.','Nov.','Déc.'],
dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
dayNamesShort: ['Dim.','Lun.','Mar.','Mer.','Jeu.','Ven.','Sam.'],
dayNamesMin: ['D','L','M','M','J','V','S'],
weekHeader: 'Sem.',
dateFormat: 'dd/mm/yy',
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ''};
$.datepicker.setDefaults($.datepicker.regional['fr']);
});
/* French translation for the jQuery Timepicker Addon */
/* Written by Thomas Lété */
(function($) {
$.timepicker.regional['fr'] = {
timeOnlyTitle: 'Choisir une heure',
timeText: 'Heure',
hourText: 'Heures',
minuteText: 'Minutes',
secondText: 'Secondes',
millisecText: 'Millisecondes',
timezoneText: 'Fuseau horaire',
currentText: 'Maintenant',
closeText: 'Terminé',
timeFormat: 'hh:mm',
amNames: ['AM', 'A'],
pmNames: ['PM', 'P'],
ampm: false
};
$.timepicker.setDefaults($.timepicker.regional['fr']);
})(jQuery);

View File

@ -0,0 +1,100 @@
/*
* jQuery Hotkeys Plugin
* Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Based upon the plugin by Tzury Bar Yochay:
* http://github.com/tzuryby/hotkeys
*
* Original idea by:
* Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/
*/
(function(jQuery){
jQuery.hotkeys = {
version: "0.8",
specialKeys: {
8: "backspace", 9: "tab", 13: "return", 16: "shift", 17: "ctrl", 18: "alt", 19: "pause",
20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home",
37: "left", 38: "up", 39: "right", 40: "down", 45: "insert", 46: "del",
96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6", 103: "7",
104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110: ".", 111 : "/",
112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5", 117: "f6", 118: "f7", 119: "f8",
120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 191: "/", 224: "meta"
},
shiftNums: {
"`": "~", "1": "!", "2": "@", "3": "#", "4": "$", "5": "%", "6": "^", "7": "&",
"8": "*", "9": "(", "0": ")", "-": "_", "=": "+", ";": ": ", "'": "\"", ",": "<",
".": ">", "/": "?", "\\": "|"
}
};
function keyHandler( handleObj ) {
// Only care when a possible input has been specified
if ( typeof handleObj.data !== "string" ) {
return;
}
var origHandler = handleObj.handler,
keys = handleObj.data.toLowerCase().split(" ");
handleObj.handler = function( event ) {
// Don't fire in text-accepting inputs that we didn't directly bind to
if ( this !== event.target && (/textarea|select/i.test( event.target.nodeName ) ||
event.target.type === "text") ) {
return;
}
// Keypress represents characters, not special keys
var special = event.type !== "keypress" && jQuery.hotkeys.specialKeys[ event.which ],
character = String.fromCharCode( event.which ).toLowerCase(),
key, modif = "", possible = {};
// check combinations (alt|ctrl|shift+anything)
if ( event.altKey && special !== "alt" ) {
modif += "alt+";
}
if ( event.ctrlKey && special !== "ctrl" ) {
modif += "ctrl+";
}
// TODO: Need to make sure this works consistently across platforms
if ( event.metaKey && !event.ctrlKey && special !== "meta" ) {
modif += "meta+";
}
if ( event.shiftKey && special !== "shift" ) {
modif += "shift+";
}
if ( special ) {
possible[ modif + special ] = true;
} else {
possible[ modif + character ] = true;
possible[ modif + jQuery.hotkeys.shiftNums[ character ] ] = true;
// "$" can be triggered as "Shift+4" or "Shift+$" or just "$"
if ( modif === "shift+" ) {
possible[ jQuery.hotkeys.shiftNums[ character ] ] = true;
}
}
for ( var i = 0, l = keys.length; i < l; i++ ) {
if ( possible[ keys[i] ] ) {
return origHandler.apply( this, arguments );
}
}
};
}
jQuery.each([ "keydown", "keyup", "keypress" ], function() {
jQuery.event.special[ this ] = { add: keyHandler };
});
})( jQuery );

View File

@ -0,0 +1,15 @@
/*
* jQuery MultiSelect UI Widget Filtering Plugin 1.4
* Copyright (c) 2011 Eric Hynds
*
* http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/
*
* Depends:
* - jQuery UI MultiSelect widget
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
(function(a){var f=/[\-\[\]{}()*+?.,\\\^$|#\s]/g;a.widget("ech.multiselectfilter",{options:{label:"Filter:",width:null,placeholder:"Enter keywords",autoReset:!1},_create:function(){var e;var b=this,c=this.options,d=this.instance=a(this.element).data("multiselect");this.header=d.menu.find(".ui-multiselect-header").addClass("ui-multiselect-hasfilter");e=this.wrapper=a('<div class="ui-multiselect-filter">'+(c.label.length?c.label:"")+'<input placeholder="'+c.placeholder+'" type="search"'+(/\d/.test(c.width)? 'style="width:'+c.width+'px"':"")+" /></div>").prependTo(this.header),c=e;this.inputs=d.menu.find('input[type="checkbox"], input[type="radio"]');this.input=c.find("input").bind({keydown:function(a){13===a.which&&a.preventDefault()},keyup:a.proxy(b._handler,b),click:a.proxy(b._handler,b)});this.updateCache();d._toggleChecked=function(c,d){var e=d&&d.length?d:this.labels.find("input"),i=this,e=e.not(b.instance._isOpen?":disabled, :hidden":":disabled").each(this._toggleState("checked",c));this.update(); var j=e.map(function(){return this.value}).get();this.element.find("option").filter(function(){!this.disabled&&-1<a.inArray(this.value,j)&&i._toggleState("selected",c).call(this)})};d=a(document).bind("multiselectrefresh",function(){b.updateCache();b._handler()});this.options.autoReset&&d.bind("multiselectclose",a.proxy(this._reset,this))},_handler:function(b){var c=a.trim(this.input[0].value.toLowerCase()),d=this.rows,g=this.inputs,h=this.cache;if(c){d.hide();var e=RegExp(c.replace(f,"\\$&"),"gi"); this._trigger("filter",b,a.map(h,function(a,b){return-1!==a.search(e)?(d.eq(b).show(),g.get(b)):null}))}else d.show();this.instance.menu.find(".ui-multiselect-optgroup-label").each(function(){var b=a(this),c=b.nextUntil(".ui-multiselect-optgroup-label").filter(function(){return"none"!==a.css(this,"display")}).length;b[c?"show":"hide"]()})},_reset:function(){this.input.val("").trigger("keyup")},updateCache:function(){this.rows=this.instance.menu.find(".ui-multiselect-checkboxes li:not(.ui-multiselect-optgroup-label)");this.cache=this.element.children().map(function(){var b=a(this);"optgroup"===this.tagName.toLowerCase()&&(b=b.children());return b.map(function(){return this.innerHTML.toLowerCase()}).get()}).get()},widget:function(){return this.wrapper},destroy:function(){a.Widget.prototype.destroy.call(this);this.input.val("").trigger("keyup");this.wrapper.remove()}})})(jQuery);

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,27 @@
/*
* SimpleModal 1.4.4 - jQuery Plugin
* http://simplemodal.com/
* Copyright (c) 2013 Eric Martin
* Licensed under MIT and GPL
* Date: Sun, Jan 20 2013 15:58:56 -0800
*/
(function(b){"function"===typeof define&&define.amd?define(["jquery"],b):b(jQuery)})(function(b){var j=[],n=b(document),k=navigator.userAgent.toLowerCase(),l=b(window),g=[],o=null,p=/msie/.test(k)&&!/opera/.test(k),q=/opera/.test(k),m,r;m=p&&/msie 6./.test(k)&&"object"!==typeof window.XMLHttpRequest;r=p&&/msie 7.0/.test(k);b.modal=function(a,h){return b.modal.impl.init(a,h)};b.modal.close=function(){b.modal.impl.close()};b.modal.focus=function(a){b.modal.impl.focus(a)};b.modal.setContainerDimensions=
function(){b.modal.impl.setContainerDimensions()};b.modal.setPosition=function(){b.modal.impl.setPosition()};b.modal.update=function(a,h){b.modal.impl.update(a,h)};b.fn.modal=function(a){return b.modal.impl.init(this,a)};b.modal.defaults={appendTo:"body",focus:!0,opacity:50,overlayId:"simplemodal-overlay",overlayCss:{},containerId:"simplemodal-container",containerCss:{},dataId:"simplemodal-data",dataCss:{},minHeight:null,minWidth:null,maxHeight:null,maxWidth:null,autoResize:!1,autoPosition:!0,zIndex:1E3,
close:!0,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:"simplemodal-close",escClose:!0,overlayClose:!1,fixed:!0,position:null,persist:!1,modal:!0,onOpen:null,onShow:null,onClose:null};b.modal.impl={d:{},init:function(a,h){if(this.d.data)return!1;o=p&&!b.support.boxModel;this.o=b.extend({},b.modal.defaults,h);this.zIndex=this.o.zIndex;this.occb=!1;if("object"===typeof a){if(a=a instanceof b?a:b(a),this.d.placeholder=!1,0<a.parent().parent().size()&&(a.before(b("<span></span>").attr("id",
"simplemodal-placeholder").css({display:"none"})),this.d.placeholder=!0,this.display=a.css("display"),!this.o.persist))this.d.orig=a.clone(!0)}else if("string"===typeof a||"number"===typeof a)a=b("<div></div>").html(a);else return alert("SimpleModal Error: Unsupported data type: "+typeof a),this;this.create(a);this.open();b.isFunction(this.o.onShow)&&this.o.onShow.apply(this,[this.d]);return this},create:function(a){this.getDimensions();if(this.o.modal&&m)this.d.iframe=b('<iframe src="javascript:false;"></iframe>').css(b.extend(this.o.iframeCss,
{display:"none",opacity:0,position:"fixed",height:g[0],width:g[1],zIndex:this.o.zIndex,top:0,left:0})).appendTo(this.o.appendTo);this.d.overlay=b("<div></div>").attr("id",this.o.overlayId).addClass("simplemodal-overlay").css(b.extend(this.o.overlayCss,{display:"none",opacity:this.o.opacity/100,height:this.o.modal?j[0]:0,width:this.o.modal?j[1]:0,position:"fixed",left:0,top:0,zIndex:this.o.zIndex+1})).appendTo(this.o.appendTo);this.d.container=b("<div></div>").attr("id",this.o.containerId).addClass("simplemodal-container").css(b.extend({position:this.o.fixed?
"fixed":"absolute"},this.o.containerCss,{display:"none",zIndex:this.o.zIndex+2})).append(this.o.close&&this.o.closeHTML?b(this.o.closeHTML).addClass(this.o.closeClass):"").appendTo(this.o.appendTo);this.d.wrap=b("<div></div>").attr("tabIndex",-1).addClass("simplemodal-wrap").css({height:"100%",outline:0,width:"100%"}).appendTo(this.d.container);this.d.data=a.attr("id",a.attr("id")||this.o.dataId).addClass("simplemodal-data").css(b.extend(this.o.dataCss,{display:"none"})).appendTo("body");this.setContainerDimensions();
this.d.data.appendTo(this.d.wrap);(m||o)&&this.fixIE()},bindEvents:function(){var a=this;b("."+a.o.closeClass).bind("click.simplemodal",function(b){b.preventDefault();a.close()});a.o.modal&&a.o.close&&a.o.overlayClose&&a.d.overlay.bind("click.simplemodal",function(b){b.preventDefault();a.close()});n.bind("keydown.simplemodal",function(b){a.o.modal&&9===b.keyCode?a.watchTab(b):a.o.close&&a.o.escClose&&27===b.keyCode&&(b.preventDefault(),a.close())});l.bind("resize.simplemodal orientationchange.simplemodal",
function(){a.getDimensions();a.o.autoResize?a.setContainerDimensions():a.o.autoPosition&&a.setPosition();m||o?a.fixIE():a.o.modal&&(a.d.iframe&&a.d.iframe.css({height:g[0],width:g[1]}),a.d.overlay.css({height:j[0],width:j[1]}))})},unbindEvents:function(){b("."+this.o.closeClass).unbind("click.simplemodal");n.unbind("keydown.simplemodal");l.unbind(".simplemodal");this.d.overlay.unbind("click.simplemodal")},fixIE:function(){var a=this.o.position;b.each([this.d.iframe||null,!this.o.modal?null:this.d.overlay,
"fixed"===this.d.container.css("position")?this.d.container:null],function(b,e){if(e){var f=e[0].style;f.position="absolute";if(2>b)f.removeExpression("height"),f.removeExpression("width"),f.setExpression("height",'document.body.scrollHeight > document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight + "px"'),f.setExpression("width",'document.body.scrollWidth > document.body.clientWidth ? document.body.scrollWidth : document.body.clientWidth + "px"');else{var c,d;a&&a.constructor===
Array?(c=a[0]?"number"===typeof a[0]?a[0].toString():a[0].replace(/px/,""):e.css("top").replace(/px/,""),c=-1===c.indexOf("%")?c+' + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"':parseInt(c.replace(/%/,""))+' * ((document.documentElement.clientHeight || document.body.clientHeight) / 100) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"',a[1]&&(d="number"===typeof a[1]?
a[1].toString():a[1].replace(/px/,""),d=-1===d.indexOf("%")?d+' + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"':parseInt(d.replace(/%/,""))+' * ((document.documentElement.clientWidth || document.body.clientWidth) / 100) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"')):(c='(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"',
d='(document.documentElement.clientWidth || document.body.clientWidth) / 2 - (this.offsetWidth / 2) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"');f.removeExpression("top");f.removeExpression("left");f.setExpression("top",c);f.setExpression("left",d)}}})},focus:function(a){var h=this,a=a&&-1!==b.inArray(a,["first","last"])?a:"first",e=b(":input:enabled:visible:"+a,h.d.wrap);setTimeout(function(){0<e.length?e.focus():h.d.wrap.focus()},
10)},getDimensions:function(){var a="undefined"===typeof window.innerHeight?l.height():window.innerHeight;j=[n.height(),n.width()];g=[a,l.width()]},getVal:function(a,b){return a?"number"===typeof a?a:"auto"===a?0:0<a.indexOf("%")?parseInt(a.replace(/%/,""))/100*("h"===b?g[0]:g[1]):parseInt(a.replace(/px/,"")):null},update:function(a,b){if(!this.d.data)return!1;this.d.origHeight=this.getVal(a,"h");this.d.origWidth=this.getVal(b,"w");this.d.data.hide();a&&this.d.container.css("height",a);b&&this.d.container.css("width",
b);this.setContainerDimensions();this.d.data.show();this.o.focus&&this.focus();this.unbindEvents();this.bindEvents()},setContainerDimensions:function(){var a=m||r,b=this.d.origHeight?this.d.origHeight:q?this.d.container.height():this.getVal(a?this.d.container[0].currentStyle.height:this.d.container.css("height"),"h"),a=this.d.origWidth?this.d.origWidth:q?this.d.container.width():this.getVal(a?this.d.container[0].currentStyle.width:this.d.container.css("width"),"w"),e=this.d.data.outerHeight(!0),f=
this.d.data.outerWidth(!0);this.d.origHeight=this.d.origHeight||b;this.d.origWidth=this.d.origWidth||a;var c=this.o.maxHeight?this.getVal(this.o.maxHeight,"h"):null,d=this.o.maxWidth?this.getVal(this.o.maxWidth,"w"):null,c=c&&c<g[0]?c:g[0],d=d&&d<g[1]?d:g[1],i=this.o.minHeight?this.getVal(this.o.minHeight,"h"):"auto",b=b?this.o.autoResize&&b>c?c:b<i?i:b:e?e>c?c:this.o.minHeight&&"auto"!==i&&e<i?i:e:i,c=this.o.minWidth?this.getVal(this.o.minWidth,"w"):"auto",a=a?this.o.autoResize&&a>d?d:a<c?c:a:f?
f>d?d:this.o.minWidth&&"auto"!==c&&f<c?c:f:c;this.d.container.css({height:b,width:a});this.d.wrap.css({overflow:e>b||f>a?"auto":"visible"});this.o.autoPosition&&this.setPosition()},setPosition:function(){var a,b;a=g[0]/2-this.d.container.outerHeight(!0)/2;b=g[1]/2-this.d.container.outerWidth(!0)/2;var e="fixed"!==this.d.container.css("position")?l.scrollTop():0;this.o.position&&"[object Array]"===Object.prototype.toString.call(this.o.position)?(a=e+(this.o.position[0]||a),b=this.o.position[1]||b):
a=e+a;this.d.container.css({left:b,top:a})},watchTab:function(a){if(0<b(a.target).parents(".simplemodal-container").length){if(this.inputs=b(":input:enabled:visible:first, :input:enabled:visible:last",this.d.data[0]),!a.shiftKey&&a.target===this.inputs[this.inputs.length-1]||a.shiftKey&&a.target===this.inputs[0]||0===this.inputs.length)a.preventDefault(),this.focus(a.shiftKey?"last":"first")}else a.preventDefault(),this.focus()},open:function(){this.d.iframe&&this.d.iframe.show();b.isFunction(this.o.onOpen)?
this.o.onOpen.apply(this,[this.d]):(this.d.overlay.show(),this.d.container.show(),this.d.data.show());this.o.focus&&this.focus();this.bindEvents()},close:function(){if(!this.d.data)return!1;this.unbindEvents();if(b.isFunction(this.o.onClose)&&!this.occb)this.occb=!0,this.o.onClose.apply(this,[this.d]);else{if(this.d.placeholder){var a=b("#simplemodal-placeholder");this.o.persist?a.replaceWith(this.d.data.removeClass("simplemodal-data").css("display",this.display)):(this.d.data.hide().remove(),a.replaceWith(this.d.orig))}else this.d.data.hide().remove();
this.d.container.hide().remove();this.d.overlay.hide();this.d.iframe&&this.d.iframe.hide().remove();this.d.overlay.remove();this.d={}}}}});

View File

@ -0,0 +1,436 @@
var f1_pressed = false;
var QueryString = function () {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
// If first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = pair[1];
// If second entry with this name
} else if (typeof query_string[pair[0]] === "string") {
var arr = [ query_string[pair[0]], pair[1] ];
query_string[pair[0]] = arr;
// If third or later entry with this name
} else {
query_string[pair[0]].push(pair[1]);
}
}
return query_string;
} ();
function checkPrinting() {
if(lockPrint) {
return false;
}
var productsok = true;
$("#main table.std tbody tr.grey, #main table.std tbody tr.blocked, #main table.std tbody tr.fed_ship").each(function(id, el) {
if(parseInt($(el).find(".shipped").find("input").val()) != 0) {
productsok = false;
}
});
if(!productsok) {
prompt("Les produits sélectionnés ne font pas partie des ventes actives. Confirmer l\'envoi ?", function() { $("#button4").attr("onclick", "").trigger("click"); });
} else {
var allok = true;
$("#main table.std tbody tr:not(.grey):not(.blocked):not(.fed_ship)").each(function(id, el) {
if(parseInt($(el).find(".toship").text()) > parseInt($(el).find(".shipped").find("input").val())) {
allok = false;
}
});
if(!allok) {
prompt("Les quantités scannées sont inférieures aux quantités à envoyer. Confirmer l\'envoi ?", function() { $("#button4").attr("onclick", "").trigger("click"); });
} else {
$("#button4").attr("onclick", "").trigger("click");
}
}
}
function toggleMode(el) {
$(el).parent().children("a").toggleClass("active");
$("body").toggleClass("mode_light");
if($("body").hasClass("mode_light")) {
$(el).parent().children("a").children("i").removeClass('anticon-enlarge2');
$(el).parent().children("a").children("i").addClass('anticon-shrink2');
$(el).parent().children("a").attr('href','#light');
if($("#button_form").attr("action").indexOf("&mode=&") == -1) {
$("#button_form").attr("action", $("#button_form").attr("action").replace("&mode=normal", "&mode=light"));
} else {
$("#button_form").attr("action", $("#button_form").attr("action").replace("&mode=", "") + "&mode=light");
}
} else {
$(el).parent().children("a").children("i").removeClass('anticon-shrink2');
$(el).parent().children("a").children("i").addClass('anticon-enlarge2');
$(el).parent().children("a").attr('href','#normal');
if($("#button_form").attr("action").indexOf("&mode=&") == -1) {
$("#button_form").attr("action", $("#button_form").attr("action").replace("&mode=light", "&mode=normal"));
} else {
$("#button_form").attr("action", $("#button_form").attr("action").replace("&mode=", "") + "&mode=normal");
}
}
}
function checkParcelCarrier(el) {
/*var carriers = $(el).parent().parent().attr("data-carrier");
var id_carriers = [];
if(carriers != "") {
id_carriers = carriers.split(",");
}
var notfound = 0;
var carrier = $("#parcel_carrier").val() == 'laposte'? carriers_laposte: carriers_exapaq;
$(id_carriers).each(function(id, el) {
if(carrier.indexOf(el) == -1) {
notfound++;
}
});
if(notfound == id_carriers.length) {
confirm("Attention, ce produit ne peut pas être expédié avec le transporteur sélectionné");
}*/
}
function qtyUp(el, max) {
var input = $(el).parent().parent().children("input");
var current_weight = parseFloat($("#weight").val());
if(input.val() + 1 <= max) {
$("#weight").val(ps_round(current_weight + parseFloat($(el).parent().parent().parent().attr("data-weight")), 2));
}
input.val(Math.min(parseInt(input.val()) + 1, max));
if(parseInt(input.val()) > 0) {
$(input).trigger("change");
}
changeCarrier();
tryPrintLabel();
}
function qtyDown(el) {
var input = $(el).parent().parent().children("input");
var current_weight = parseFloat($("#weight").val());
if(input.val() - 1 >= 0) {
$("#weight").val(ps_round(Math.max(current_weight - parseFloat($(el).parent().parent().parent().attr("data-weight")), 0), 2));
}
input.val(Math.max(parseInt(input.val()) - 1, 0));
if(parseInt(input.val()) > 0) {
$(input).trigger("change");
}
changeCarrier();
}
function checkQuantityPack(el, id_item, id_order_detail, quantity, max){
var add_quantity = true;
var quantity_ok = {};
var pack_quantity = parseInt($('input[name="shipped['+id_order_detail+']"]').val());
$('.pack_'+id_order_detail+' input.input_quantity').each(function(){
id_item = $(this).data('item');
quantity = $(this).val();
item_pack_quantity = $('input[name="shipped['+id_order_detail+']"]').parent().parent().attr('data-pack_'+id_item);
result = quantity / (item_pack_quantity*(pack_quantity+1));
if(parseFloat(result)!=1){
quantity_ok[id_item] = false;
} else {
quantity_ok[id_item] = true;
}
});
$.each( quantity_ok, function( key, value ) {
if(value == false){
add_quantity = false;
}
});
if(add_quantity == true){
adding = parseInt($('input[name="shipped['+id_order_detail+']"]').val())+1;
$('input[name="shipped['+id_order_detail+']"]').val(adding);
$('input[name="shipped['+id_order_detail+']"]').trigger("change");
changeCarrier();
tryPrintLabel();
}
}
function confirm(message, callback) {
$('#confirm .message').html(message);
$('#confirm').modal('toggle');
}
function prompt(message, callback) {
$('#prompt .message').html(message);
$('#prompt').modal('toggle');
$("#prompt").on("show.bs.modal", function (event) {
var button = $(event.relatedTarget);
var modal = $(this);
$("#prompt .yes", dialog.data[0]).click(function () {
// call the callback
if ($.isFunction(callback)) {
callback.apply();
}
// close the dialog
$('#prompt').modal('toggle');
});
});
}
function changeCarrier() {
if(isRelay == 1) {
if($("#parcel_carrier").val() != "laposte") {
confirm("Impression bloquée : point de livraison hors domicile non compatible avec ce transporteur");
$("#button4").css("opacity", .2);
lockPrint = true;
return;
}
} else if(isRelay == 2) {
if($("#parcel_carrier").val() != "exapaq") {
confirm("Impression bloquée : point de livraison hors domicile non compatible avec ce transporteur");
$("#button4").css("opacity", .2);
lockPrint = true;
return;
}
}
$("#button4").css("opacity", 1);
lockPrint = false;
}
function tryPrintLabel() {
var toship_sum = 0;
$("#button_form table tbody tr:not(.grey):not(.pack_item) .toship strong").each(function(id, el) {
toship_sum += parseInt($(el).text());
});
if(toship_sum > 0) {
var execprint = true;
$("#button_form table tbody tr:not(.grey):not(.pack_item)").each(function(id, el) {
if(parseInt($(el).find(".shipped input").val()) < parseInt($(el).find(".toship strong").text())) {
execprint = false;
}
});
if(execprint) {
$("#button4").trigger("click");
}
}
}
var ean_timeout = null;
function checkEAN() {
clearTimeout(ean_timeout);
ean_timeout = setTimeout(function() {
var eanval = $("#eaninput").val();
if(eanval != "") {
var eanval_item = $("#button_form tbody tr").filter(function() {
if($(this).attr("rel") != eanval) {
return $(this).attr("rel") == '0'+eanval;
}
return $(this).attr("rel") == eanval;
});
if(eanval_item.length > 0) {
$(eanval_item).each(function(id, el) {
var current_val = parseInt($(el).find(".shipped input").val());
var max_val = parseInt($(el).find(".toship strong").text());
if(current_val < max_val) {
qtyUp($(el).find(".shipped a")[0], max_val);
} else {
var eanval_item_pack = $("#button_form tbody tr").filter(function() {
if($(this).attr("rel") != eanval+'_pack') {
return $(this).attr("rel") == '0'+eanval+'_pack';
}
return $(this).attr("rel") == eanval+'_pack';
});
if(eanval_item_pack.length > 0) {
$(eanval_item_pack).each(function(id_pack, el_pack) {
var current_val = parseInt($(el_pack).find(".shipped input").val());
var max_val = parseInt($(el_pack).find(".toship strong").text());
if(current_val < max_val) {
qtyUp($(el_pack).find(".shipped a")[0], max_val);
} else {
confirm("Quantité à envoyer déjà atteinte pour ce produit");
}
});
} else {
confirm("Quantité à envoyer déjà atteinte pour ce produit");
}
}
});
} else {
var eanval_item_pack = $("#button_form tbody tr").filter(function() {
if($(this).attr("rel") != eanval+'_pack') {
return $(this).attr("rel") == '0'+eanval+'_pack';
}
return $(this).attr("rel") == eanval+'_pack';
});
if(eanval_item_pack.length > 0) {
$(eanval_item_pack).each(function(id_pack, el_pack) {
var current_val = parseInt($(el_pack).find(".shipped input").val());
var max_val = parseInt($(el_pack).find(".toship strong").text());
if(current_val < max_val) {
qtyUp($(el_pack).find(".shipped a")[0], max_val);
} else {
confirm("Quantité à envoyer déjà atteinte pour ce produit");
}
});
} else {
confirm("Aucun produit avec cet EAN13 ne figure dans cette commande");
}
}
$("#eaninput").val("");
}
}, 200);
}
function filterKeys(event) {
if(event.keyCode == 13) {
event.stopPropagation();
return false;
} else if(event.keyCode == 112) {
event.stopPropagation();
if(!f1_pressed) {
f1_pressed = true;
$("#button4").trigger("click");
}
return false;
}
}
$(document).ready(function() {
if(window.location.hash == "#light" || QueryString.mode == "light") {
$("body").toggleClass("mode_light");
}
$("#barcodeinput").trigger("focus");
$("#barcodeinput").focus(function() {
$(this).attr("placeholder", "En attente du code-barres");
});
$("#barcodeinput").blur(function() {
$(this).attr("placeholder", "Cliquez ici et scannez un code-barres");
});
$(document).bind("keydown", "f1", function (evt) {
if(!f1_pressed) {
f1_pressed = true;
$("#button4").trigger("click");
}
return false;
});
$(document).bind("keydown", "f2", function (evt) {
$("#button3").trigger("click");
return false;
});
$(document).bind("keydown", "f3", function (evt) {
$("#button2").trigger("click");
return false;
});
$(document).bind("keydown", "f4", function (evt) {
$("#button1").trigger("click");
return false;
});
$(document).bind("keydown", "f11", function (evt) {
toggleMode($("#main fieldset legend.right a.active"));
return false;
});
$(document).bind("keydown", "f12", function (evt) {
$("#eaninput").focus();
$(document).scrollTop($("#eaninput").position().top - 70);
return false;
});
$("#barcodeinput, #manualinput, #eaninput").bind("keydown", "f1", function (evt) {
if(!f1_pressed) {
f1_pressed = true;
$("#button4").trigger("click");
}
return false;
});
$("#barcodeinput, #manualinput, #eaninput").bind("keydown", "f2", function (evt) {
$("#button3").trigger("click");
return false;
});
$("#barcodeinput, #manualinput, #eaninput").bind("keydown", "f3", function (evt) {
$("#button2").trigger("click");
return false;
});
$("#barcodeinput, #manualinput, #eaninput").bind("keydown", "f4", function (evt) {
$("#button1").trigger("click");
return false;
});
$("#barcodeinput, #manualinput, #eaninput").bind("keydown", "f11", function (evt) {
toggleMode($("#main fieldset legend.right a.active"));
return false;
});
$("#barcodeinput, #manualinput, #eaninput").bind("keydown", "f12", function (evt) {
$("#eaninput").focus();
$(document).scrollTop($("#eaninput").position().top - 70);
return false;
});
$("#barcodeinput").keyup(function(event) {
if(!(event.keyCode == 112 || event.keyCode == 113 || event.keyCode == 114 || event.keyCode == 115 || event.keyCode == 123)) {
$("#manualinput").val("");
if(event.keyCode == 32) {
loadOrder(null, true);
}
}
});
$("#manualinput").keyup(function(event) {
if(!(event.keyCode == 112 || event.keyCode == 113 || event.keyCode == 114 || event.keyCode == 115 || event.keyCode == 123)) {
if (event.keyCode == 13) {
$("#barcodeinput").val("");
loadOrder(null, true);
}
}
});
QueryString.id_order? loadOrder(parseInt(QueryString.id_order), false): true;
$("#filter_id_sale").multiselect({
selectedList: 7,
selectedText: function(numChecked, numTotal, checkedItems){
var seltext = "";
$(checkedItems).each(function(id, el) {
seltext += ", " + $(el).parent().text();
});
return (numChecked > 1? "Ventes sélectionnées : ": "Vente sélectionnée : ") + seltext.slice(2);
},
checkAllText: "Tout sélectionner",
uncheckAllText: "Tout désélectionner",
noneSelectedText: "Sélectionnez une ou plusieurs ventes",
minWidth: 850
}).multiselectfilter({
label: "Filtrer :",
autoReset: false,
placeholder: "Entrez un nom ou un ID de vente"
});
QueryString.id_order? $("#barcodeinput").focus(): true;
});

View File

@ -0,0 +1,14 @@
<?php
include dirname(__FILE__).'/../../config/config.inc.php';
include dirname(__FILE__).'/../../init.php';
if(Tools::getValue('token') === Tools::getAdminToken('AdminAntLogistic'.(int) Tab::getIdFromClassName('AdminAntLogistic').(int) Tools::getValue('id_employee'))) {
if($sales = Tools::getValue('filter_id_sale')) {
setcookie('logistics_sales', implode('-', $sales), 0, __PS_BASE_URI__);
} else {
setcookie('logistics_sales', '', 0, __PS_BASE_URI__);
}
Tools::redirectAdmin('/adm/index.php?tab=AdminAntLogistic&token='.Tools::getValue('token'));
}